How to use zalgo-promise - 10 common examples

To help you get started, we’ve selected a few zalgo-promise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paypal / paypal-sdk-client / src / logger.js View on Github external
[FPTI_KEY.SELLER_ID]:              mID && mID[0],
            [FPTI_KEY.SESSION_UID]:            getSessionID(),
            [FPTI_KEY.REFERER]:                window.location.host,
            [FPTI_KEY.LOCALE]:                 `${ lang }_${ country }`,
            [FPTI_KEY.INTEGRATION_IDENTIFIER]: getClientID(),
            [FPTI_KEY.PARTNER_ATTRIBUTION_ID]: getPartnerAttributionID(),
            [FPTI_KEY.SDK_NAME]:               FPTI_SDK_NAME.PAYMENTS_SDK,
            [FPTI_KEY.SDK_VERSION]:            getVersion(),
            [FPTI_KEY.USER_AGENT]:             window.navigator && window.navigator.userAgent,
            [FPTI_KEY.USER_ACTION]:            getCommit() ? FPTI_USER_ACTION.COMMIT : FPTI_USER_ACTION.CONTINUE,
            [FPTI_KEY.CONTEXT_CORRID]:         getCorrelationID(),
            [FPTI_KEY.SDK_INTEGRATION_SOURCE]: getSDKIntegrationSource()
        };
    });

    ZalgoPromise.onPossiblyUnhandledException(err => {

        logger.track({
            [FPTI_KEY.ERROR_CODE]: 'payments_sdk_error',
            [FPTI_KEY.ERROR_DESC]: stringifyErrorMessage(err)
        });

        logger.error('unhandled_error', {
            err: stringifyError(err)
        });

        // eslint-disable-next-line promise/no-promise-in-callback
        logger.flush().catch(noop);
    });

    waitForWindowReady().then(() => {
        const loadTime = getResourceLoadTime(getSDKScript().src);
github paypal / paypal-sdk-client / dist / module / logger.js View on Github external
logger.addPayloadBuilder(function () {
        return {
            referer: window.location.host,
            uid: getSessionID(),
            env: getEnv()
        };
    });

    logger.addTrackingBuilder(function () {
        var _ref;

        return _ref = {}, _ref[FPTI_KEY.FEED] = FPTI_FEED.PAYMENTS_SDK, _ref[FPTI_KEY.DATA_SOURCE] = FPTI_DATA_SOURCE.PAYMENTS_SDK, _ref[FPTI_KEY.CLIENT_ID] = getClientID(), _ref[FPTI_KEY.SELLER_ID] = getMerchantID(), _ref[FPTI_KEY.SESSION_UID] = getSessionID(), _ref[FPTI_KEY.REFERER] = window.location.host, _ref[FPTI_KEY.LOCALE] = getLang() + '_' + getCountry(), _ref[FPTI_KEY.BUYER_COUNTRY] = getCountry(), _ref[FPTI_KEY.INTEGRATION_IDENTIFIER] = getClientID(), _ref[FPTI_KEY.PARTNER_ATTRIBUTION_ID] = getPartnerAttributionID(), _ref[FPTI_KEY.SDK_NAME] = FPTI_SDK_NAME.PAYMENTS_SDK, _ref[FPTI_KEY.SDK_VERSION] = getVersion(), _ref[FPTI_KEY.USER_AGENT] = window.navigator && window.navigator.userAgent, _ref[FPTI_KEY.USER_ACTION] = getCommit() ? FPTI_USER_ACTION.COMMIT : FPTI_USER_ACTION.CONTINUE, _ref[FPTI_KEY.CONTEXT_CORRID] = getCorrelationID(), _ref;
    });

    ZalgoPromise.onPossiblyUnhandledException(function (err) {
        var _logger$track;

        logger.track((_logger$track = {}, _logger$track[FPTI_KEY.ERROR_CODE] = 'checkoutjs_error', _logger$track[FPTI_KEY.ERROR_DESC] = stringifyErrorMessage(err), _logger$track));

        logger.error('unhandled_error', {
            stack: stringifyError(err),
            errtype: {}.toString.call(err)
        });

        // eslint-disable-next-line promise/no-promise-in-callback
        logger.flush()['catch'](noop);
    });
}
github paypal / paypal-checkout-components / src / checkout / template / containerTemplate.jsx View on Github external
e.preventDefault();
        e.stopPropagation();

        if (isIos()) {
            // eslint-disable-next-line no-alert
            window.alert('Please switch tabs to reactivate the PayPal window');
        } else {
            focus();
        }
    }

    const { style = {} } = props;

    const content = containerContent[lang];

    const onDisplay = new ZalgoPromise(resolve => {
        event.on(EVENT.DISPLAY, resolve);
    });

    const onClose = new ZalgoPromise(resolve => {
        event.on(EVENT.CLOSE, resolve);
    });

    const setupAnimations = (name) => {
        return (el) => {
            onDisplay.then(() => animate(el, `show-${ name }`, noop));
            onClose.then(() => animate(el, `hide-${ name }`, noop));
        };
    };

    let outlet;
github paypal / paypal-checkout-components / src / legacy / interface.js View on Github external
function awaitPaymentTokenAndUrl() : { url : ZalgoPromise, paymentToken : ZalgoPromise } {

    let paymentTokenAndUrl = new ZalgoPromise((resolve) => {

        checkout.initXO = () => {
            warn(`gettoken_initxo`);
        };

        // startFlow is our 'success' case - we get a token, and we can pass it back to the caller

        checkout.startFlow = once((item) => {
            debug(`gettoken_startflow`, { item });

            let { url, paymentToken } = matchUrlAndPaymentToken(item);

            checkUrlAgainstEnv(url);

            return resolve({ url, paymentToken });
        });
github krakenjs / post-robot / src / drivers / receive / types.js View on Github external
try {
                // $FlowFixMe
                sendMessage(source, origin, {
                    type,
                    ack,
                    hash:   message.hash,
                    name:   message.name,
                    ...response
                }, { on, send });
            } catch (err) {
                throw new Error(`Send response message failed for ${ logName } in ${ getDomain() }\n\n${ stringifyError(err) }`);
            }
        }

        return ZalgoPromise.all([

            sendResponse(MESSAGE_TYPE.ACK),

            ZalgoPromise.try(() => {

                if (!options) {
                    throw new Error(`No handler found for post message: ${ message.name } from ${ origin } in ${ window.location.protocol }//${ window.location.host }${ window.location.pathname }`);
                }

                if (!matchDomain(options.domain, origin)) {
                    throw new Error(`Request origin ${ origin } does not match domain ${ options.domain.toString() }`);
                }

                const data = message.data;

                return options.handler({ source, origin, data });
github paypal / paypal-smart-payment-buttons / src / button / button.js View on Github external
const setupPrerenderTask = initPromise.then(() => {
        return ZalgoPromise.hash({ prerenderDetails: getPrerenderDetails(), initPromise }).then(({ prerenderDetails }) => {
            if (!prerenderDetails) {
                return;
            }

            const { win, fundingSource, card } = prerenderDetails;
            const button = document.querySelector(`[${ DATA_ATTRIBUTES.FUNDING_SOURCE }=${ fundingSource }]`);

            if (!button) {
                throw new Error(`Can not find button element`);
            }

            const payment = { win, button, fundingSource, card };
            const payPromise = initiatePayment({ payment });

            // $FlowFixMe
            button.payPromise = payPromise;
github paypal / paypal-card-components / src / component.js View on Github external
}).catch((err) => {
        if (!(err.details && err.details.find && err.details.find(detail => detail.issue === 'CONTINGENCY'))) {
          return ZalgoPromise.reject(err);
        }

        const url = `${ err.links.find(link => link.rel === '3ds-contingency-resolution').href  }`;
        return contingencyFlow.start(url);
      }).then((payload) => {
        // does contingency flow give a payload?
github paypal / paypal-card-components / src / component.js View on Github external
configuration.correlationId = correlationId;
    // $FlowFixMe
    configuration.paypalApi = getPayPalAPIDomain();

    const orderIdFunction = () => {
      return ZalgoPromise.resolve().then(() => {
        return options.createOrder();
      });
    };

    let button;

    if (buttonSelector && options.onApprove) {
      button = document.querySelector(buttonSelector);
      if (!button) {
        return ZalgoPromise.reject(new Error(`Could not find selector \`${ buttonSelector }\` on the page`));
      }
    }

    const hostedFieldsCreateOptions = JSON.parse(JSON.stringify(options));

    return btClient.create({
      authorization: clientToken,
      paymentsSdk:   true,
      configuration
    }).then((btClientInstance) => {
      hostedFieldsCreateOptions.paymentsSdk = true;
      hostedFieldsCreateOptions.client = btClientInstance;
      return hostedFields.create(hostedFieldsCreateOptions);
    }).then((hostedFieldsInstance) => {
      hostedFieldsInstance.submit = createSubmitHandler(hostedFieldsInstance, orderIdFunction);
github paypal / paypal-checkout-components / src / setup.js View on Github external
/* @flow */

import { logger, FPTI_KEY } from 'paypal-braintree-web-client/src';
import { ZalgoPromise } from 'zalgo-promise/src';
import { stringifyError, stringifyErrorMessage, once } from 'belter/src';

import { CURRENT_ENV } from './globals';
import { checkForCommonErrors, isEligible, setupLogger } from './lib';

ZalgoPromise.onPossiblyUnhandledException(err => {

    logger.error('unhandled_error', {
        stack:   stringifyError(err),
        errtype: ({}).toString.call(err)
    });

    logger.track({
        [ FPTI_KEY.ERROR_CODE ]: 'checkoutjs_error',
        [ FPTI_KEY.ERROR_DESC ]: stringifyErrorMessage(err)
    });

    logger.flush();
});

export let setup = once(() => {
github paypal / paypal-smart-payment-buttons / src / lib / logger.js View on Github external
[FPTI_KEY.SESSION_UID]:            sessionID,
            [FPTI_KEY.REFERER]:                window.location.host,
            [FPTI_KEY.MERCHANT_DOMAIN]:        merchantDomain,
            [FPTI_KEY.LOCALE]:                 `${ lang }_${ country }`,
            [FPTI_KEY.INTEGRATION_IDENTIFIER]: clientID,
            [FPTI_KEY.PARTNER_ATTRIBUTION_ID]: partnerAttributionID,
            [FPTI_KEY.SDK_NAME]:               FPTI_SDK_NAME.PAYMENTS_SDK,
            [FPTI_KEY.SDK_VERSION]:            version,
            [FPTI_KEY.USER_AGENT]:             window.navigator && window.navigator.userAgent,
            [FPTI_KEY.USER_ACTION]:            commit ? FPTI_USER_ACTION.COMMIT : FPTI_USER_ACTION.CONTINUE,
            [FPTI_KEY.CONTEXT_CORRID]:         correlationID,
            [FPTI_KEY.BUTTON_VERSION]:         __SMART_BUTTONS__.__MINOR_VERSION__
        };
    });

    ZalgoPromise.onPossiblyUnhandledException(err => {

        logger.track({
            [FPTI_KEY.ERROR_CODE]: 'payments_sdk_error',
            [FPTI_KEY.ERROR_DESC]: stringifyErrorMessage(err)
        });

        logger.error('unhandled_error', {
            err: stringifyError(err)
        });

        // eslint-disable-next-line promise/no-promise-in-callback
        logger.flush().catch(noop);
    });
}