npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@appboxo/js-sdk

v1.7.0

Published

JavaScript SDK for AppBoxo mini-app platform

Downloads

2,176

Readme

AppBoxo JS SDK

Appboxo JS SDK is a connection bridge between miniapp and native app, that has a rich API features that make your miniapp feel like a native. Using Appboxo JS SDK, host app can pass the user email to miniapp, to register the user automatically in the miniapp.

Usage

import appboxoSdk from '@appboxo/js-sdk';

// Sends event to client
appboxoSdk.send('AppBoxoWebAppInit');

// Subscribes to event, sended by client
appboxoSdk.subscribe(e => console.log(e));

For use in a browser, include the file dist/index.umd.js and use as follows

<script src="dist/index.umd.js"></script>

<script>
  // Sends event to client
  appboxoSdk.send('AppBoxoWebAppInit');
</script>

Native clients

Native clients (both Android and iOS) should call this to pass data to mini apps:

window.dispatchEvent(new window.CustomEvent('AppBoxoWebAppEvent', {
  bubbles: false,
  cancelable: false,
  detail: {
    type: 'AppBoxoWebAppGetInitData',
    data: {
      app_id: 234234,
      client_id: 344343,
      payload: 'asdlj2323ljaoiw',
      token: 'qerljljqwerqwe',
      request_id: 1
    }
  }
}))

Important

If an event triggered from mini app has request_id inside data (like on the example above), than it means that sendPromise has been called and same event with request_id and event type should be returned to resolve this promise.

Authentication

appboxoSdk.login(optionalProps)

Sends a message to native client to open confirm modal with default confirmation message. Upon confirmation it sends request to platform and returns resolved authentication token promise to miniapp.

Parameters

  • optionalProps optional Props to extend default login behavior

Example

try {
  const token = await appboxoSdk.login({
    confirmModalText: 'This is my custom confirmation message',
    postConfirmCallback: (isConfirmed) => { console.log('Confirmation status: ', isConfirmed) }
  });
} catch (error) {
  // Handling an error
}

appboxoSdk.logout()

Sends a message to native client to clear authentication tokens.

API Reference

appboxoSdk.sendPromise(method[, params])

Sends a message to native client and returns the Promise object with response data

Parameters

  • method required The AppBoxo js sdk method
  • params optional Message data object

Example

// Sending event to client
appboxoSdk
  .sendPromise('AppBoxoWebAppGetInitData')
  .then(data => {
    // Handling received data
    console.log(data.email);
  })
  .catch(error => {
    // Handling an error
  });

You can also use imperative way

try {
  const data = await appboxoSdk.sendPromise('AppBoxoWebAppGetInitData');

  // Handling received data
  console.log(data.email);
} catch (error) {
  // Handling an error
}

appboxoSdk.send(method[, params])

Sends a message to native client

Parameters

  • method required The AppBoxo js sdk method
  • params optional Message data object

Example

// App initialization
appboxoSdk.send('AppBoxoWebAppInit');

// Opening images
appboxoSdk.send('AppBoxoWebAppShowImages', {
  images: [
    "https://pp.userapi.com/c639229/v639229113/31b31/KLVUrSZwAM4.jpg",
    "https://pp.userapi.com/c639229/v639229113/31b94/mWQwkgDjav0.jpg",
    "https://pp.userapi.com/c639229/v639229113/31b3a/Lw2it6bdISc.jpg"
  ]
}

appboxoSdk.subscribe(fn)

Subscribes a function to events listening

Parameters

  • fn required Function to be subscribed to events

Example

// Subscribing to receiving events
appboxoSdk.subscribe(event => {
  if (!event.detail) {
    return;
  }

  const { type, data } = event.detail;

  if (type === 'AppBoxoWebAppOpenCodeReaderResult') {
    // Reading result of the Code Reader
    console.log(data.code_data);
  }

  if (type === 'AppBoxoWebAppOpenCodeReaderFailed') {
    // Catching the error
    console.log(data.error_type, data.error_data);
  }
});

// Sending method
appboxoSdk.send('AppBoxoWebAppOpenCodeReader', {});

appboxoSdk.unsubscribe(fn)

Unsubscribes a function from events listening

Parameters

  • fn required Event subscribed function

Example

const fn = event => {
  // ...
};

// Subscribing
appboxoSdk.subscribe(fn);

// Unsubscribing
appboxoSdk.unsubscribe(fn);

appboxoSdk.supports(method)

Checks if an event is available on the current device

Parameters

  • method required The AppBoxo js sdk method

appboxoSdk.isWebView()

Returns true if AppBoxo js sdk is running in mobile app, or false if not