react-native-lightspeedsdk
Version:
A react-native interface for using the LightspeedSDK
113 lines (92 loc) • 3.92 kB
JavaScript
'use strict';
import {NativeEventEmitter} from 'react-native';
import UserProfile from './models/UserProfile';
import BasicUserInfo from './models/BasicUserInfo';
const NativeRegistrationCoordinator = require('react-native').NativeModules.LSRegistrationCoordinator;
const RegistrationEventEmitter = new NativeEventEmitter(NativeRegistrationCoordinator);
export type SocialLoginProviderType = 'facebook';
module.exports = {
addLogoutListener(listener: Function){
return RegistrationEventEmitter.addListener(NativeRegistrationCoordinator.UserLogoutNotification, listener);
},
removeLogoutListener(listener: Function) {
RegistrationEventEmitter.removeListener(NativeRegistrationCoordinator.UserLogoutNotification, listener);
},
/**
* Retrieves the supported and later supported countries and languages
*/
getCountryLanguages() : PromiseCountryLanguages> {
return NativeRegistrationCoordinator.getCountryLanguages();
},
/**
* Checks if the provided email is already registered
*/
isEmailRegistered(email: string): PromiseBasicUserInfo> {
return NativeRegistrationCoordinator.isEmailRegistered(email);
},
/**
* Getter for the current User Profile of the logged in User.
*/
getLoggedInUser(): PromiseUserProfile> {
return new Promise((resolve, reject) => {
NativeRegistrationCoordinator.loggedInUser((tokenMap, error) => {
if (tokenMap) {
let profile = new UserProfile(tokenMap);
resolve(profile);
} else {
resolve(null);
}
});
});
},
// reason object e.g.: {code: 6001, reason: "Rejected Country/Language"}
sessionClearedReason(): Promise<Object> {
return new Promise((resolve, reject) => {
NativeRegistrationCoordinator.sessionClearedReason((reason) => {
resolve(reason);
});
});
},
/**
* Registers the user using Mobile services
*/
register(email: string, password:string, firstName:string, lastName:string, zipCode:string, gender:int, birthDate: string, languageCode: string, countryCode: string): PromiseUserProfile> {
return NativeRegistrationCoordinator.register(email, password, firstName, lastName, zipCode, gender, birthDate, languageCode, countryCode);
},
/**
* Log the user in using Mobiles services
*/
login(email: string, password:string): PromiseUserProfile> {
return NativeRegistrationCoordinator.login(email, password);
},
/**
* Log the user in using the social provider credentials via Mobile Services
*/
socialLogin(gigyaId: string, provider: SocialLoginProviderType, providerUId: string, accessToken: string, email: string, firstName: string, lastName: string, isSiteUID: bool, languageCode: string, countryCode: string): PromiseUserProfile> {
return NativeRegistrationCoordinator.loginWithSocialProvider(gigyaId, provider, providerUId, accessToken, email, firstName, lastName, isSiteUID, languageCode, countryCode);
},
/**
* Reset the password of the provided email address
*/
resetPassword(email: string): PromiseObject>{
return NativeRegistrationCoordinator.resetPassword(email);
},
/**
* Log the user out using Mobile Services
*/
logout() {
NativeRegistrationCoordinator.logout();
},
/**
* Link the user Social Provider account via Mobile Services
*/
socialLink(gigyaId: string, provider: SocialLoginProviderType, providerUId: string, accessToken: string) : PromiseSingleAchievement>{
return NativeRegistrationCoordinator.socialLink(gigyaId, provider, providerUId, accessToken);
},
/**
* Unlink the user Social Provider account via Mobile Services
*/
socialUnlink(provider: SocialLoginProviderType) : PromiseObject>{
return NativeRegistrationCoordinator.socialUnlink(provider);
}
};