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

blip-iframe

v1.6.4

Published

A type safe and intuitive API to communicate with the Blip platform

Downloads

815

Readme

Getting started

Install blip-iframe in your project:

npm i blip-iframe

Usage

You can use blip-iframe with any framework or even vanilla JavaScript. In this section, we'll show how to get started using React, but the same principles apply to any other tool or framework.

Usage with Iframe Message Proxy (default)

If you're using blip-iframe inside Blip (ex.: Blip Extensions), using Iframe Message Proxy is the recommended way to go. Luckily, this is also the default you can use the API commands and actions without any additional configuration, as such:

import { useState, useEffect } from 'react';
import { blip } from 'blip-iframe';

export default function Component() {
  const [application, setApplication] = useState(null);
  const [error, setError] = useState(null);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    // Fetches data about the current bot. If an error occurs, the data will be null.
    // The error is not thrown, but returned. This improves types and error awareness.
    blip.getApplication().then((response) => {
      setLoading(false);
      if (!response.success) {
        setError(response.error);
      } else {
        setApplication(response.data);
      }
    });
  }, []);

  if (loading) return <>Loading...</>;

  if (error) return <>An error ocurred!</>;

  // Shows data about the current bot
  return <pre>{JSON.stringify(application, null, 2)}</pre>;
}

Under the hood, blip-iframe will send the 'getApplication' action using the Iframe Message Proxy, and properly type the response.

All set! Now you can use the blip-iframe API to make calls inside your application.

This method only works if your web app is inside Blip

Using blip-iframe without setting up authentication only works in web applications rendered as an iframe inside Blip, because the authentication is done automatically by the platform.

If you want to make the same calls in a standalone app, follow the steps outlined below.

Usage with the REST API

To use blip-iframe in a standalone application, you need to use the REST API. In order to do that, you need to create a sender function. This function will take the commands parameters and send them using whatever method you like, in this case, the REST API.

This function should be passed as the second parameters of any blip-iframe helper function. See the example below.

Sender function using fetch and the REST API

import type { Message, Sender } from 'blip-iframe';
import { blip } from 'blip-iframe';
import { v4 as uuidv4 } from 'uuid';

const sender: Sender = async <TData = unknown>(message: Message) => {
  if (message.action !== 'sendCommand') {
    return {
      success: false,
      error: new Error("The REST API doesn't support actions, only commands"),
    } as const;
  }

  const response = await fetch('https://msging.net/commands', {
    method: 'POST',
    headers: {
      Authorization: 'Key your-authorization-key',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ id: uuidv4(), ...message.content.command }),
  });

  if (!response.ok) {
    return { success: false, error: new Error(response.statusText) } as const;
  }

  const { resource } = (await response.json()) as { resource: TData };

  return { success: true, data: resource } as const;
};

// Call any command using the sender function as the second parameter
blip.getTickets({ skip: 0, take: 20 }, sender);

Usage with using the Blip SDK

Coming soon...