Repository URL to install this package:
|
Version:
1.1.13 ▾
|
/* eslint-disable max-lines */
// import querystring from 'query-string'
// import { campaignId, appid, locale, storeId, STORE_KEY } from '../../bootstrapper/api/config'
import { toPassword } from '../../deps/fromPasswordToHashed'
export const registerParams = {
// campaignId,
// locale,
// appid,
// storeId,
username: 'createuser',
// userinfo: JSON.stringify({
// verificationDetails: { userName: 'xxx', password: 'Xxx@123' },
// addresses: [
// {
// type: 'userIdentities',
// value: 'skava',
// customParams: { type: ['0'], channel: ['mobile'] },
// },
// { type: 'billingAddress' },
// { type: 'shippingAddress' },
// {
// type: 'securityQuestions',
// verificationDetails: {
// challengeQuestion: 'who are you?',
// challengeAnswer: 'xxx',
// },
// },
// {
// type: 'securityQuestions',
// verificationDetails: {
// challengeQuestion: 'where are you from?',
// challengeAnswer: 'xxx',
// },
// },
// ],
// email: 'xxx@yyy.com',
// phone: '999 - 999 - 9999',
// dob: '01-01-1970',
// gender: 'X',
// firstName: 'xxx',
// lastName: 'yyy',
// city: 'xxx',
// state: 'xx',
// country: 'xx',
// postalCode: '99999',
// customParams: {
// resetMethod: ['1'],
// status: ['1'],
// contactPreferences: ['string'],
// additionalPreferences: ['string'],
// promotions: ['string'],
// preferences: ['string'],
// },
// }),
// customparams: JSON.stringify({
// messageCampaignId: '',
// validationMethod: '1',
// sendWelcomeEmail: 'false',
// cv: 'FDHSDF',
// cid: '32423',
// promocode: '1',
// promocampaign: '1',
// skipValidations: '1',
// skipPassword: '1',
// locale: 'en_US',
// channel: 'web',
// }),
}
export const registerGuestParams = {
// campaignId,
// locale,
// storeId,
// appid,
username: 'createorgetuser',
userinfo: JSON.stringify({
customParams: {
createIfNecessary: ['true'],
useFP: ['false'],
},
}),
}
export const loginParams = {
// campaignId,
// locale,
// storeId,
// appid,
// userinfo: JSON.stringify({
// userName: 'xxx@yyy.com',
// password: 'Xxx@123',
// }),
// customparams: JSON.stringify({
// type: '0',
// value: 'skava',
// messageCampaignId: '',
// promocode: '',
// promocampaign: '',
// locale: '',
// channel: '',
// }),
}
export const logoutParams = {
// campaignId,
// storeId,
// appid,
}
export const addAddressParams = {
// campaignId,
// storeId,
// appid,
// address: JSON.stringify({
// addresses: [
// {
// type: 'shippingAddress',
// firstName: 'ccc',
// lastName: 'yyy',
// phone: '999 - 999 - 9999',
// addressLine1: '1%20Front%20Street',
// addressLine2: '',
// city: 'San Francisco',
// country: 'US',
// state: 'CA',
// postalCode: '94111',
// customParams: {
// validated: ['true'],
// override: ['false'],
// default: ['false'],
// },
// },
// ],
// }),
// customparams: JSON.stringify({
// locale: 'en_US',
// messageCampaignId: '364',
// }),
}
export const removeAddressParams = {
// appid,
// campaignId,
// storeId,
// address: JSON.stringify({
// addresses: [
// {
// type: 'shippingAddressToDelete',
// firstName: 'xxx',
// lastName: 'yyy',
// phone: '999 - 999 - 9999',
// addressLine1: '1%20Front%20Street',
// addressLine2: '',
// city: 'San Francisco',
// country: 'US',
// state: 'CA',
// postalCode: '94111',
// id: 'fcf8cf28-7f44-4ae0-a392-53a8ccd09867',
// customParams: {
// validated: ['true'],
// override: ['false'],
// default: ['false'],
// },
// },
// ],
// }),
customparams: JSON.stringify({
locale: 'en_US',
messageCampaignId: '365',
}),
}
export const updateAddressParams = {
// appid,
// campaignId,
// storeId,
// address: JSON.stringify({
// addresses: [
// {
// type: 'shippingAddress',
// firstName: 'xxx',
// lastName: 'yyy',
// phone: '999 - 999 - 9999',
// addressLine1: '1%20Front%20Street',
// addressLine2: '',
// city: 'San Francisco',
// country: 'US',
// state: 'CA',
// postalCode: '94111',
// id: 'fcf8cf28-7f44-4ae0-a392-53a8ccd09867',
// customParams: {
// validated: ['true'],
// override: ['false'],
// default: ['false'],
// },
// },
// ],
// }),
// customparams: JSON.stringify({
// locale: 'en_US',
// messageCampaignId: '',
// }),
}
export const changeDefaultAddressParams = {
// appid,
// campaignId,
// storeId,
// address: JSON.stringify({
// addresses: [
// {
// type: 'shippingAddress',
// firstName: 'xxx',
// lastName: 'yyy',
// phone: '999 - 999 - 9999',
// addressLine1: '1%20Front%20Street',
// addressLine2: '',
// city: 'San Francisco',
// country: 'US',
// state: 'CA',
// postalCode: '94111',
// id: 'fcf8cf28-7f44-4ae0-a392-53a8ccd09867',
// customParams: {
// validated: ['true'],
// override: ['false'],
// default: ['true'],
// },
// },
// ],
// }),
// customparams: JSON.stringify({
// locale: 'en_US',
// messageCampaignId: '',
// }),
}
export const addCardParams = {
// appid,
// campaignId,
// storeId,
}
export const deleteCardParams = {
// appid,
// campaignId,
// storeId,
}
export const changeDefaultCardParams = {
// appid,
// campaignId,
// storeId,
}
export const getProfileParams = {
// campaignId,
// locale,
// storeId,
// appid,
}
// interface UpdateProfileParams {
// firstName: string;
// lastName: string;
// userId: string;
// }
export const defaultUpdateProfileParams = {
firstName: 'yyy',
lastName: 'xxx',
userId: 'xxx@yyy.com',
}
export function toUpdateProfileParams(namedParams = defaultUpdateProfileParams) {
const { firstName, lastName, userId } = namedParams
const params = {
// campaignId,
// locale,
// appid,
// storeId,
userinfo: JSON.stringify({
firstName,
lastName,
}),
customparams: JSON.stringify({
type: '0',
value: 'skava',
userId,
}),
}
return params
}
export const updateProfileParams = toUpdateProfileParams({})
export async function toUpdatePasswordParams(namedParams) {
const oldPassword = await toPassword(namedParams.oldPassword)
const newPassword = await toPassword(namedParams.newPassword)
const params = {
// campaignId,
// locale,
// storeId,
// appid,
userinfo: {
verificationDetails: { oldPassword, password: newPassword },
},
customparams: {
locale: 'en_US',
messageCampaignId: '',
},
}
return params
}
export const updatePasswordParams = toUpdatePasswordParams({})
export function toUpdateSecurityParams(namedParams) {
const { userName, challengeQuestion, challengeAnswer } = namedParams
const params = {
// campaignId,
// locale,
// appid,
// storeId,
userinfo: {
verificationDetails: { userName: userName },
addresses: [
{
type: 'securityQuestions',
verificationDetails: {
challengeQuestion: challengeQuestion,
challengeAnswer: challengeAnswer,
},
},
],
},
customparams: { locale: 'en_US' },
}
return params
}
export const addSecurityQuestionParams = toUpdateSecurityParams({})
// export interface resetPasswordEmailParams {
// email: string;
// messageCampaignId: string;
// }
// export const defaultResetPasswordEmailParams = {
// email: 'favtest@skava.com',
// messageCampaignId: '379',
// }
export const toResetPasswordByEmailParams = namedParams => {
const { email, messageCampaignId } = namedParams
const params = {
// campaignId,
// storeId,
// appid,
userinfo: {
addresses: [
{
type: 'userIdentities',
value: 'skava',
id: email,
customParams: { type: ['0'] },
},
],
},
customparams: {
// messageCampaignId: '379',
// locale: 'en_US',
// resetMethod: '1',
// !!!!!! BAD BAD BAD BAD BAD BAD BAD BAD !!!!!! USE ENV
messageCampaignId: process.env.ACCOUNT_RESET_PASSWORD_CAMPAIGN_MESSAGE_ID || '',
locale: 'en_US',
resetMethod: '2',
channel: 'WEB',
},
}
return params
}
// default !?
export const resetPasswordByEmailParams = toResetPasswordByEmailParams({})
export const validatePasswordByEmailParams = namedParams => {
// campaignId,
// locale,
// storeId,
// appid,
const { password, resetParam } = namedParams
const params = {
userinfo: {
verificationDetails: { password: password },
addresses: [{ type: 'userIdentities', value: 'skava', customParams: { type: ['0'] } }],
customParams: { resetMethod: ['1'] },
},
customparams: {
resetParam: resetParam,
locale: 'en_US',
channel: 'web',
messageCampaignId: '',
mailerId: '301',
},
}
return params
}
export const validateResetPasswordByEmailParams = validatePasswordByEmailParams({})
export const toResetPasswordBySMSParams = email => {
const params = {
// campaignId,
// storeId,
// appid,
userinfo: {
addresses: [
{
type: 'userIdentities',
value: 'skava',
id: email,
customParams: { type: ['0'] },
},
],
},
customparams: {
// !!! BAD BAD BAD BAD BAD BAD FIXME !!!
messageCampaignId: '372',
locale: 'en_US',
resetMethod: '1',
channel: 'WEB',
},
}
return params
}
export const resetPasswordBySMSParams = toResetPasswordBySMSParams({})
export const validateResetPasswordBySMSParams = {
// campaignId,
// locale,
// storeId,
// appid,
userinfo: JSON.stringify({
verificationDetails: { password: 'Skava@123' },
addresses: [
{
type: 'userIdentities',
value: 'skava',
customParams: { type: ['0'] },
id: 'gnanaprabhu@skava.com',
},
],
}),
customparams: JSON.stringify({
otp: '12345',
locale: 'en_US',
channel: 'WEB',
messageCampaignId: '376',
mailerId: '376',
}),
}
export const twittertokenParams = {
// campaignId,
// appid: 'skreact',
username: 'twitter',
}
// export interface SecurityParams {
// emailId: string;
// }
export const defaultSecurityParams = {
emailId: 'favtest@skava.com',
}
export function toSecurityParams(namedParams = defaultSecurityParams) {
const { emailId } = namedParams
const params = {
// campaignId,
// locale,
// storeId,
// appid,
userinfo: {
addresses: [
{
type: 'userIdentities',
id: emailId,
value: 'skava',
customParams: { type: ['0'], channel: ['WEB'] },
},
],
},
}
return params
}
export const getSecurityQuestionsParams = toSecurityParams()
export const resetPasswordSecurityParams = async namedParams => {
const { emailId, challengeQuestion1, challengeAnswer1, password } = namedParams
const hashedPassword = await toPassword(password)
const params = {
// campaignId,
// locale,
// storeId,
// appid,
userinfo: {
addresses: [
{
type: 'userIdentities',
value: 'skava',
id: emailId,
customParams: { type: ['0'] },
},
{
type: 'securityQuestions',
verificationDetails: {
challengeQuestion: challengeQuestion1,
challengeAnswer: challengeAnswer1,
},
},
],
verificationDetails: { password: hashedPassword },
},
customparams: {
messageCampaignId: '',
resetMethod: '3',
channel: 'WEB',
},
}
return params
}
export const resetPasswordBySecurityQuestionsParams = resetPasswordSecurityParams({})
// export interface AddPaymentCardParams {
// messageCampaignId: string;
// }
export const defaultAddPaymentCardParams = {
messageCampaignId: '521',
}
export function getAddPaymentCardParams(params = defaultAddPaymentCardParams, email) {
const {
cardType,
messageCampaignId,
cardNumber,
expirationmonth,
expirationyear,
expiryDate,
firstName,
lastName,
makeDefaultCard,
securityCode,
} = params
const details = {
payment: {
creditCard: [
{
type: cardType,
number: cardNumber,
expirationMonth: expirationmonth,
expirationYear: expirationyear,
expiryDate,
name: firstName,
customParams: {
cardBrand: cardType,
validated: 'false',
default: makeDefaultCard,
},
},
],
address: [
{
type: 'billingAddress',
addressLine1: '1 Front Street',
city: 'San Francisco',
state: 'CA',
postalCode: '94111',
country: 'US',
email,
firstName,
lastName,
makeDefaultCard,
securityCode,
phone: '213 - 123 - 1231',
customParams: {
validated: ['true'],
override: ['false'],
default: ['false'],
},
},
],
},
customparams: {
locale: 'en_US',
channel: 'web',
linkBAddrToCard: 'true',
messageCampaignId,
},
...addCardParams,
}
return details
}
export function getDeletePaymentCardParams(params) {
const deletePaymentDetails = {
carddetail: {
cards: [
{
id: params.creditId,
},
],
},
customparams: {
type: '0',
value: 'skava',
userId: params.email,
messageCampaignId: '',
},
...deleteCardParams,
}
return deletePaymentDetails
}
// export interface DefaultCardParams {
// payment: string;
// messageCampaignId: string;
// }
export const changeDefaultPaymentCardParams = {
payment: '',
messageCampaignId: '366',
}
export function getChangeDefaultCardParams(changeCardParams = changeDefaultPaymentCardParams) {
const { payment, messageCampaignId } = changeCardParams
const changeDefaultPaymentDetails = {
payment,
customparams: {
locale: 'en_US',
channel: 'web',
linkBAddrToCard: 'true',
// messageCampaignId,
},
...changeDefaultCardParams,
}
return changeDefaultPaymentDetails
}
export function getProfileCustomParams(enablePaymentRetrival) {
return {
customparams: {
enablePaymentRetrival: [enablePaymentRetrival],
},
}
}
// --- export default exports
/**
* @see toUpdatePasswordParams
* @todo !!! THIS NEEDS FIXING - SHOULD NOT BE A STRING
*/
export async function toRegisterParams(params) {
const defaultUserIdentity = [
{
type: 'userIdentities',
value: 'skava',
customParams: {
type: ['0'],
},
},
]
const defaultUserCustomParams = {
resetMethod: ['4'],
status: ['1'],
contactPreferences: [''],
additionalPreferences: [''],
promotions: [''],
preferences: [''],
}
const defaultCustomParams = {
/**
* @todo @fixme - messageid is wrong
*/
messageCampaignId: process.env.ACCOUNT_CREATE_CAMPAIGN_MESSAGE_ID || '',
//default message Campaign Id should be empty String
// messageCampaignId: '88',
validationMethod: '4',
sendWelcomeEmail: 'true',
skipValidations: '1',
locale: process.env.LOCALE || 'en_US',
}
const { userName, password, telephone, firstName, lastName } = params
// Note returning {}
const hashedPassword = await toPassword(password)
const mergedParams = {
userinfo: {
verificationDetails: {
userName,
password: hashedPassword,
},
email: userName,
phone: telephone,
firstName,
lastName,
addresses: defaultUserIdentity,
customParams: {
...defaultUserCustomParams,
},
},
customparams: {
...defaultCustomParams,
},
}
return mergedParams
}
const fromSocialToLoginType = (type: string) => {
switch (type) {
case 'google':
return 3
case 'twitter':
return 4
case 'facebook':
return 2
case 'skava':
return '0'
default:
return '0'
}
}
function checkIsSocialLogin(provider): boolean {
return provider !== 'skava'
}
export async function toLoginParams(params) {
const { userName, password, provider = 'skava', authToken } = params
const hashedPassword = await toPassword(password)
const type = fromSocialToLoginType(params.provider)
const defaultCustomParams = {
type,
value: provider,
/**
* @todo @fixme - messageid is wrong
*/
// messageCampaignId: process.env.ACCOUNT_CREATE_CAMPAIGN_MESSAGE_ID || '88',
messageCampaignId: '',
promocode: '',
promocampaign: '',
locale: 'en_US',
channel: '',
}
const verificationDetails = {
userName,
password: hashedPassword,
}
if (checkIsSocialLogin(provider)) {
return {
customparams: {
...defaultCustomParams,
authToken,
},
}
}
return {
userinfo: {
...verificationDetails,
// verificationDetails,
},
customparams: {
...defaultCustomParams,
},
}
}