Repository URL to install this package:
|
Version:
0.0.9 ▾
|
import { errorContainer, toastMessage } from '@skava/packages/core/notifications';
import { isErrorLikeResponse } from '@skava/is-error-like-response';
import { ObservableContainer } from '@skava/packages/libraries/observable-container';
import { mapCookiesOnResponse, toStatus } from './deps';
import { loginBinding, registerUserBindings, registerAccountBinding, registerGuestBinding, updateProfileBinding, updateSecurityBinding, getSecurityQuestionBinding, updatePasswordBinding, resetBySmsBindings, makeLoginCall, resetPasswordThroughEmailBindings, validateByEmailBindings, userActivationBindings, resetPasswordThroughSecurityQuestionsBindings, getTwitterAuthTokenBindings, } from './bindings';
// @todo export elsewhere
export * from './bindings';
class SessionApis extends ObservableContainer {
constructor() {
super(...arguments);
/**
* @NOTE Temporary while debugginng @michael
* @todo @FIXME @michael -- nothing is as permenant as temporary code
* -- do it properly
*/
this.registerGuestUser = async () => {
const response = await registerGuestBinding();
mapCookiesOnResponse(response);
return response;
};
this.registerUser = async (data, securityParams) => {
const response = await registerUserBindings(data, securityParams);
mapCookiesOnResponse(response);
return response;
};
this.adminRegisterAccount = async (data) => {
const response = await registerAccountBinding(data);
return response;
};
this.updateProfile = async (data) => {
const response = await updateProfileBinding(data);
const toastText = isErrorLikeResponse(response)
? toastMessage.updateProfileFailure
: toastMessage.updateProfileSuccess;
errorContainer.setMessage(toastText);
const { updateProfile } = response.data;
return updateProfile;
};
this.updateSecurity = async (data, isNewUser = false) => {
const response = await updateSecurityBinding(data);
const toastText = isErrorLikeResponse(response)
? toastMessage.updateQuestionFailure
: toastMessage.updateQuestionSuccess;
if (!isNewUser) {
errorContainer.setMessage(toastText);
}
const { updateSecurity } = response.data;
return updateSecurity;
};
this.getSecurityQuestions = async (data) => {
const response = await getSecurityQuestionBinding(data);
return response;
};
this.updatePassword = async (data) => {
const response = await updatePasswordBinding(data);
const updatePasswordResponse = response.data.updatePassword;
if (isErrorLikeResponse(response)) {
errorContainer.setMessage(toastMessage.updatePasswordFailure);
}
else {
const responseStatus = toStatus(updatePasswordResponse);
errorContainer.setMessage(responseStatus);
}
// need to handle if the call had an error
// need to return error if we had error, otherwise return undefined?
return updatePasswordResponse;
};
this.resetPasswordThroughSms = async (data) => {
const response = await resetBySmsBindings(data);
return response;
};
//
this.logIn = async (params) => {
return await loginBinding(params);
};
// @todo cookies
this.loginWithGoogle = (authToken) => {
return makeLoginCall({
provider: 'google',
authToken,
});
};
// @todo cookies
this.loginWithTwitter = (authToken) => {
return makeLoginCall({
provider: 'twitter',
authToken,
});
};
// @todo cookies
this.loginWithFacebook = (authToken) => {
return makeLoginCall({
provider: 'facebook',
authToken,
});
};
this.createList = async () => {
// const response = await this.client.mutate({
// mutation: CreateLists,
// })
// return response && response.data && response.data.createList
};
this.createSaveForLater = async () => {
console.warn('[SessionApis] createSaveForLater missing, moved to saveForLater in lists');
// const response = await this.client.mutate<CreateSaveForLaterResponseType>({
// mutation: CreateSavedForLater,
// variables: {},
// })
// return response.data!.createSaveForLater
// return createSaveForLaterBinding()
};
this.fetchList = async () => {
// const response = await this.client.query({
// query: ListsQuery,
// })
// return response.data.getLists
};
// @todo - missing gql?
this.fetchListItems = async (listId) => {
// const response = await this.client.query({
// // query: ListItemsQuery,
// query: FavoritesQuery,
// variables: {
// favoriteId: listId,
// // listId,
// },
// })
// return response.data.favorites
};
}
resetPasswordThroughEmail(data) {
return resetPasswordThroughEmailBindings(data);
}
validateByEmail(data) {
return validateByEmailBindings(data);
}
userActivation(data) {
return userActivationBindings(data);
}
resetPasswordThroughSecurityQuestions(data) {
return resetPasswordThroughSecurityQuestionsBindings(data);
}
getTwitterAuthToken() {
return getTwitterAuthTokenBindings();
}
}
SessionApis.debugName = 'SessionApis';
const sessionApis = new SessionApis();
export { sessionApis, SessionApis };
//# sourceMappingURL=container.apis.js.map