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/graphql / dist / endpoints / user / stream / transform / transform.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const exotic_1 = require("exotic");
// import { autofixSafe } from 'exotic-core'
const composition_1 = require("@skava/modules/___dist/composition");
// const transformAddressInfo = data => {
//   const { string } = getTyped(data)
//   return {
//     addressid: string('addressid'),
//   }
// }
const transformGenericInfo = addressinfoDetails => {
    const { array, string, boolean, obj } = composition_1.getTyped(addressinfoDetails);
    const transformed = {
        additionaldetails: array('additionaldetails'),
        addressid: string('addressid'),
        addressline1: string('addressline1'),
        addressline2: string('addressline2'),
        addresstype: string('addresstype'),
        city: string('city'),
        country: string('country'),
        email: string('email'),
        // @todo fullname
        firstname: string('firstname'),
        lastname: string('lastname'),
        // @todo - this also doesn't work on card.....
        // isDefaultItem: boolean('isdefaultaddress') || boolean('isdefault'),
        isdefaultaddress: boolean('isdefaultaddress') || boolean('isdefault'),
        phonedetails: array('phonedetails'),
        // isn't state an obj? (note in this place, it's string for address state!)
        state: string('state'),
        // @note this is a string!
        zipcode: string('zipcode'),
    };
    // return autofixSafe(transformed)
    return transformed;
};
const toDefaultAddress = address => {
    if (exotic_1.isTrue(exotic_1.toBoolean(address.isdefaultaddress))) {
        return address;
    }
    else {
        return '';
    }
};
exports.toDefaultAddress = toDefaultAddress;
const toCard = card => {
    return card;
};
const toDefaultCard = card => {
    if (exotic_1.isTrue(exotic_1.toBoolean(card.isdefault))) {
        return card;
    }
    else {
        return '';
    }
};
exports.toDefaultCard = toDefaultCard;
// const transformCard = cards => {
//   const { array, string, obj } = getTyped(cards)
//   return {
//     cards: array(cards).map(toCard),
//     defaultCard: array(cards).filter(toDefaultCard).map(toCard),
//   }
// }
const toSecurityQuestion = userinfo => {
    const { array, string, obj } = composition_1.getTyped(userinfo);
    if (exotic_1.isSafe(userinfo.securityquestion)) {
        return {
            securityquestion: userinfo.securityquestion,
            securityanswer: userinfo.securityanswer,
        };
    }
    return {};
};
exports.toSecurityQuestion = toSecurityQuestion;
const toAddressinfo = addressinfo => {
    const generic = transformGenericInfo(addressinfo);
    return generic;
};
exports.toAddressinfo = toAddressinfo;
const transformUser = response => {
    const { any, array, obj, float, string } = composition_1.getTyped(response);
    // const userSerialized = oneStorage.get('user-serial-info')
    // const preferencesSerialized = oneStorage.set('preferences-serial-info')
    // const profile-info = { 'userSerialized': userSerialized, 'preferencesSerialized': preferencesSerialized }
    const user = {
        type: any('type'),
        // lol -.-
        responseMessage: string('Get Profile Success'),
        // cardList
        cards: array('properties.creditcardinfo.cards').map(toCard),
        // probably we want like .address.shippingList & .payment.cardList
        // this one can be computed
        // addressList
        // addressinfo: array('properties.userinfo.0.addressinfo').map(toAddressinfo),
        // don't think we need this?
        // this is a confusing conflict for user because bad naming of "province"
        state: obj('properties.state'),
        // what  else is in userinfo o.o ?
        userinfo: obj('properties.userinfo.0'),
        // number
        responseCode: string('0'),
        // @todo should be computed
        // defaultCard: array('properties.creditcardinfo.cards').filter(toDefaultCard),
        security: array('properties.userinfo').map(toSecurityQuestion),
        cookies: array('cookies'),
    };
    // const autofixed = autofixSafe(user)
    // return autofixed
    return user;
};
exports.transformUser = transformUser;
const transformPaymentStatus = response => {
    if (!response.properties.state.status) {
        // response status is not received when call fails
        // hence adding static status responseMessage for failure
        response.properties.state.status =
            'failure - something went wrong in payment';
    }
    return response;
};
exports.transformPaymentStatus = transformPaymentStatus;
exports.default = transformUser;
//# sourceMappingURL=transform.js.map