How to use post-robot - 10 common examples

To help you get started, we’ve selected a few post-robot 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 krakenjs / zoid / test / child.js View on Github external
/* @flow */

import { on } from 'post-robot/src';

import './component';

on('eval', ({ data: { code } }) => {
    eval(code); // eslint-disable-line no-eval, security/detect-eval-with-expression
});

if (window.xprops.run) {
    // eslint-disable-next-line no-unused-vars
    let zoid = require('../src');
    // eslint-disable-next-line no-unused-vars
    let { onWindowOpen } = require('./common');
    eval(`(function() { ${ window.xprops.run } }).call(this);`); // eslint-disable-line no-eval, security/detect-eval-with-expression
}
github Bearer / bearer-js / packages / js / src / lib / bearer.ts View on Github external
static get authorizedListener() {
    if (!window[LISTENER_KEY]) {
      // TODO: get rid of post robot, too heavy for our needs
      window[LISTENER_KEY] = new EventEmitter()
      postRobot.on('BEARER_AUTHORIZED', ({ data }) => {
        window[LISTENER_KEY].emit(authorizeEvent(data.scenarioId || data.integrationId), data)
      })
      postRobot.on('BEARER_REJECTED', ({ data }) => {
        window[LISTENER_KEY].emit(rejectEvent(data.scenarioId || data.integrationId), data)
      })
    }
    return window[LISTENER_KEY]
  }
github paypal / paypal-checkout-components / src / api / rest.js View on Github external
return body.id;
        }

        throw new Error(`Order Api response error:\n\n${ JSON.stringify(body, null, 4) }`);
    });
}

const PROXY_REST = `proxy_rest`;
const parentWin = getAncestor();

on(PROXY_REST, { domain: getPayPalDomain() }, ({ data }) => {
    proxyRest = data;
});

if (parentWin && isPayPalDomain() && !isSameDomain(parentWin)) {
    send(parentWin, PROXY_REST, { createAccessToken, createOrder })
        .catch(() => {
            // pass
        });
}
github paypal / paypal-checkout-components / src / api / rest.js View on Github external
}).then(({ body }) : string => {

        logOrderResponse(body.id);

        if (body && body.id) {
            return body.id;
        }

        throw new Error(`Order Api response error:\n\n${ JSON.stringify(body, null, 4) }`);
    });
}

const PROXY_REST = `proxy_rest`;
const parentWin = getAncestor();

on(PROXY_REST, { domain: getPayPalDomain() }, ({ data }) => {
    proxyRest = data;
});

if (parentWin && isPayPalDomain() && !isSameDomain(parentWin)) {
    send(parentWin, PROXY_REST, { createAccessToken, createOrder })
        .catch(() => {
            // pass
        });
}
github paypal / paypal-checkout-components / src / compat / fallback.js View on Github external
import { isPayPalDomain, noop, getScriptVersion, extendUrl } from '../lib';
import { config } from '../config';

function match(str : string, pattern : RegExp) : ?string {
    let regmatch : ?Array<string> = str.match(pattern);
    if (regmatch) {
        return regmatch[1];
    }
}

let onAuthorize : ?Function;

// Post-Bridge

if (isPayPalDomain()) {
    on('onLegacyPaymentAuthorize', { window: window.parent }, ({ data } : { data : { method : Function } }) => {
        onAuthorize = data.method;
    });
}

// Button / Merchant

export function onLegacyPaymentAuthorize(method : Function) : ZalgoPromise<void> {
    onAuthorize = method;

    return ZalgoPromise.try(() => {
        if (bridge && !isPayPalDomain()) {
            return bridge.openBridge(extendUrl(config.postBridgeUrl, { version: getScriptVersion() }), config.postBridgeDomain).then((postBridge : CrossDomainWindowType) => {
                return send(postBridge, 'onLegacyPaymentAuthorize', { method }, { domain: config.paypalDomain })
                    .then(noop);
            });
        }
github EdgeApp / edge-login-ui / packages / edge-login-ui-web / src / client / client-state.js View on Github external
} = opts
  const { onError = onErrorNop } = callbacks

  let state: ClientState
  const message: ConnectionMessage = {
    apiKey,
    appId,
    hideKeys,
    vendorName,
    vendorImageUrl,
    clientDispatch: message => clientDispatch(state, message)
  }

  // Set up the frame:
  const frame = makeFrame(assetsPath)
  return postRobot
    .send(frame, 'connect', message, { timeout: frameTimeout })
    .then((reply: PostRobotEvent<ConnectionReply>) => {
      const frameDispatch: any = reply.data.frameDispatch
      state = {
        accounts: {},
        appId,
        createCurrencyWallet: reply.data.createCurrencyWallet,
        createWallet: reply.data.createWallet,
        signEthereumTransaction: reply.data.signEthereumTransaction,
        frame,
        frameDispatch,
        localUsers: reply.data.localUsers,
        onClose: void 0,
        onError,
        onLogin: void 0
      }
github paypal / paypal-checkout-components / globals.js View on Github external
/* eslint import/no-commonjs: off, flowtype/require-valid-file-annotation: off, flowtype/require-return-type: off */

const postRobotGlobals = require('post-robot/globals');
const zoidGlobals = require('zoid/globals');

module.exports = {
    
    __ZOID__: {
        ...zoidGlobals.__ZOID__,
        __DEFAULT_CONTAINER__: true,
        __DEFAULT_PRERENDER__: true,
        __FRAMEWORK_SUPPORT__: true
    },
    
    __POST_ROBOT__: {
        ...postRobotGlobals.__POST_ROBOT__,
        __IE_POPUP_SUPPORT__: false
    },

    __PAYPAL_CHECKOUT__: {
        __REMEMBERED_FUNDING__: [],
        __URI__:                {
            __CHECKOUT__:    '/checkoutnow',
            __BUTTONS__:     '/smart/buttons',
            __MENU__:        '/smart/menu',
            __MODAL__:        '/smart/modal',
            __CARD_FIELDS__: '/smart/card-fields',
            __NATIVE__:      '/smart/checkout/native'
        }
    }
};
github krakenjs / zoid / globals.js View on Github external
/* @flow */
/* eslint import/no-commonjs: off */

const postRobotGlobals = require('post-robot/globals');

const pkg = require('./package.json');

const formatVersion = (version) => {
    return version.replace(/[^\d]+/g, '_');
};

module.exports = {
    __POST_ROBOT__: {
        ...postRobotGlobals.__POST_ROBOT__,
        __AUTO_SETUP__: false
    },
    __ZOID__: {
        __VERSION__:           formatVersion(pkg.version),
        __GLOBAL_KEY__:        `__zoid_${ formatVersion(pkg.version) }__`,
        __POPUP_SUPPORT__:     true,
        __FRAMEWORK_SUPPORT__: false,
        __DEFAULT_CONTAINER__: true,
        __DEFAULT_PRERENDER__: true
    }
};