New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@vkontakte/vk-bridge-mock

Package Overview
Dependencies
Maintainers
4
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vkontakte/vk-bridge-mock

VK Bridge Mock for development in browser

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-16.67%
Maintainers
4
Weekly downloads
 
Created
Source

VK Bridge Mock NPM Travis

This library mocks VK Bridge methods.

Usage

Use in your code instead of using vk-bridge by following way:

import bridge from '@vkontakte/vk-bridge-mock';

// App init
bridge.send('VKWebAppInit');

bridge.send('VKWebAppGetUserInfo', {}).then(data => {
  // Do something
});

Or event-based way:

import bridge from '@vkontakte/vk-bridge-mock';

// App init
bridge.send('VKWebAppInit');

bridge.subscribe(e => {
  if (e.detail.type === 'VKWebAppGetUserInfoResult') {
    // Do something
  }
});

bridge.send('VKWebAppGetUserInfo', {});

Please note that some methods may only receive (for example, VKWebAppUpdateConfig, VKWebAppViewHide, VKWebAppViewRestore, etc.). To obtain data from them you need to use the event-based way and callReceiveOnlyMethod()

import bridge, { callReceiveOnlyMethod } from '@vkontakte/vk-bridge-mock';

// App init
bridge.send('VKWebAppInit');

bridge.subscribe(e => {
  if (e.detail.type === 'VKWebAppUpdateConfig') {
    // Do something
  }
});

// Use this function when you need to get data
callReceiveOnlyMethod('VKWebAppUpdateConfig');

For use without code bundler, include the file dist/browser.min.js and use as follows

<script src="https://unpkg.com/@vkontakte/vk-bridge-mock/dist/browser.min.js"></script>

<script>
  // Sends event to client
  vkBridgeMock.send('VKWebAppInit');

  vkBridgeMock.subscribe(e => {
    if (e.detail.type === 'VKWebAppUpdateConfig') {
      // Do something
    }
  });

  // Use this function when you need to get data
  vkBridgeCallReceiveOnlyMethod('VKWebAppUpdateConfig');
</script>

More documentation regarding VK Bridge is here.

Using with VK Mini Apps API

You can also use this library in conjunction with VK Mini Apps API:

import { VKMiniAppAPI } from '@vkontakte/vk-mini-apps-api';
import bridgeMock from '@vkontakte/vk-bridge-mock';

// Creating API instance
const api = new VKMiniAppAPI(bridgeMock);

// Using methods
api.getUserInfo().then(userInfo => {
  // Do something with mock data of user info
});

Keywords

FAQs

Package last updated on 22 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc