Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/packages / core / auth / user / bindings.js
Size: Mime:
/**
 * @todo @require @skava/graphql-bindings
 */
import { client } from 'src/bootstrap/client/apolloClient';
import { getTyped } from 'composition';
/**
 * @deprecated don't use mapCookiesOnResponse
 */
import { DeleteUserAccount } from './queries';
import { mapCookiesOnResponse } from '@skava/packages/core/auth/session/deps';
import { UserLiteProfileQuery, GetAddressQuery, RemoveAddressFromProfile, DefaultShippingAddress, AddAddressToProfile, UpdateShippingAddress, GetPaymentsQuery, AccountInfoQuery, } from './queries';
import { AddCard, DeleteCard, ChangeDefaultCard, UpdateCard } from './queries';
/** @name addShippingAddressToProfileBinding */
export async function addShippingAddress(address) {
    const { addressParams, isDefault } = address;
    const response = await client.mutate({
        mutation: AddAddressToProfile,
        variables: {
            address: {
                ...addressParams,
                isDefault,
            },
        },
    });
    return response;
}
export { addShippingAddress as addShippingAddressToProfileBinding };
/**
 * @name updateShippingAddressInProfileBinding
 * @todo get the address id elsewhere
 */
export async function updateShippingAddress(address) {
    const { addressParams, addressId, isDefault } = address;
    const response = await client.mutate({
        mutation: UpdateShippingAddress,
        variables: {
            address: {
                ...addressParams,
                id: addressId,
                isDefault,
            },
        },
    });
    return response;
}
export { updateShippingAddress as updateShippingAddressInProfileBinding };
/** @name makeDefaultShippingAddressInProfileBinding */
export async function makeDefaultShippingAddress(address) {
    const response = await client.mutate({
        mutation: DefaultShippingAddress,
        variables: {
            address,
        },
    });
    return response;
}
export { makeDefaultShippingAddress as makeDefaultShippingAddressInProfileBinding };
/** @name removeShippingAddressFromProfileBinding */
export async function removeShippingAddress(addressId) {
    const response = await client.mutate({
        mutation: RemoveAddressFromProfile,
        variables: {
            id: addressId,
        },
    });
    return response;
}
export { removeShippingAddress as removeShippingAddressBinding };
/** @name fetchAddressBinding */
export async function fetchAddress() {
    const response = await client.query({
        query: GetAddressQuery,
        variables: {},
        fetchPolicy: 'no-cache',
    });
    return response;
}
export { fetchAddress as fetchAddressBinding };
/** @name fetchAccountInfoBinding */
export async function fetchAccountInfo() {
    const response = await client.query({
        query: AccountInfoQuery,
        variables: {},
        fetchPolicy: 'no-cache',
    });
    return response;
}
export { fetchAccountInfo as fetchAccountInfoBinding };
// {
//   'type': '',
//   'status': '',
//   'cards': [
//     {
//       cardId: '245',
//       identifier: '245',
//       addressinfo: [
//         {
//           addressId: '',
//           firstName: 'ssadas',
//           lastName: 'dasd',
//           addressLine1: '5999 eh street',
//           addressLine2: '',
//           city: 'Courtenay',
//           state: 'BC',
//           country: 'US',
//           zipCode: 'v9j1t6',
//           email: 'james@skava.com',
//           telephone: '6253761523',
//           __typename: 'UserAddressInfo'
//         }
//       ],
//       cardNumber: '411111XXXXXX1111',
//       cardType: 'VISA',
//       expirationmonth: '12',
//       expirationyear: '2023',
//       isDefault: 'true',
//       lastFourDigits: '1111',
//       nameOnCard: ' dasd',
//       firstName: '',
//       lastName: 'dasd',
//       type: '',
//       __typename: 'CreditCardDetails'
//     }
//   ],
//   '__typename': 'GetCardsResponse'
// }
export async function getPaymentsBinding() {
    const response = await client.query({
        query: GetPaymentsQuery,
        variables: {},
        fetchPolicy: 'no-cache',
    });
    const userPaymentsResponse = response.data.getUserPayments;
    return { response, userPaymentsResponse };
}
export async function fetchUserLiteProfileBinding() {
    const response = await client.query({
        query: UserLiteProfileQuery,
        variables: {},
        fetchPolicy: 'no-cache',
    });
    const { profileLite } = response.data;
    console.log('[mike]', profileLite);
    mapCookiesOnResponse(profileLite);
    return profileLite;
}
// UserApiResponseType
export async function addCardBinding(variables) {
    const response = await client.mutate({
        mutation: AddCard,
        fetchPolicy: 'no-cache',
        variables,
    });
    const addCardResponse = getTyped(response).obj('response.data.addCard');
    return { response, addCardResponse };
}
export async function changeDefaultCardBinding(variables) {
    const response = await client.mutate({
        mutation: ChangeDefaultCard,
        variables,
        fetchPolicy: 'no-cache',
    });
    const changeDefaultCardResponse = getTyped(response).obj('response.data.changeDefaultCard');
    return { response, changeDefaultCardResponse };
}
export async function updateCardPaymentBinding(variables) {
    const response = await client.mutate({
        mutation: UpdateCard,
        variables,
        fetchPolicy: 'no-cache',
    });
    const updateCardResponse = getTyped(response).obj('response.data.updateCard');
    return { response, updateCardResponse };
}
export async function deleteCardBinding(cardId) {
    const response = await client.mutate({
        mutation: DeleteCard,
        variables: {
            id: cardId,
        },
        fetchPolicy: 'no-cache',
    });
    const deleteCardResponse = getTyped(response).obj('response.data.updateCard');
    return { response, deleteCardResponse };
}
export async function deleteUserAccountBindings() {
    const response = await client.mutate({
        mutation: DeleteUserAccount,
        variables: {},
    });
    return response;
}
//# sourceMappingURL=bindings.js.map