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

hieuwax-wuffi-tap-mini-app-lib

v0.0.15

Published

`wuffi-tap-mini-app-lib` is a utility library designed for embedding mini-apps inside the **Wuffi Tap** platform. This library provides functionality to interact with the host app, handle authentication, and manage game states seamlessly. It simplifies co

Downloads

866

Readme

🐾 Wuffi Tap Mini App Library

wuffi-tap-mini-app-lib is a utility library designed for embedding mini-apps inside the Wuffi Tap platform. This library provides functionality to interact with the host app, handle authentication, and manage game states seamlessly. It simplifies communication between the mini-app and the Wuffi Tap host.

✨ Features

  • Authentication: Retrieve user authentication data (JWT, user info, etc.).
  • Game Management: Ability to close the game from within the mini-app.
  • Cross-window Communication: Send and receive messages between the mini-app and the Wuffi Tap host via postMessage.

📦 Installation

Install the package using npm or yarn:

npm install wuffi-tap-mini-app-lib

or

yarn add wuffi-tap-mini-app-lib

🚀 Usage

Example Mini-App Component

Below is an example of how to use the library to create a simple mini-game that interacts with the Wuffi Tap host:

import { useEffect, useState } from "react";
import { IAuthenData, miniAppWrapper } from "wuffi-tap-mini-app-lib";

export function MiniGameExample() {
  const [userData, setUserData] = useState<IAuthenData | null>();

  useEffect(() => {
    miniAppWrapper
      .requestAuthData()
      .then((data) => {
        setUserData(data);
      })
      .catch((err) => {
        console.error("Error fetching auth data", err);
      });
  }, []);

  const handleClose = () => {
    miniAppWrapper.closeGame();
  };

  return (
    <div>
      <h1>Mini Game</h1>
      {userData ? (
        <div>
          <p>
            Welcome {userData.user.first_name} {userData.user.last_name}
          </p>
          <p>Total Paws: {userData.tapStatus?.totalPawsEarned}</p>
        </div>
      ) : (
        <p>Loading user data...</p>
      )}

      {/* Game logic goes here */}

      <button onClick={handleClose}>Close Game</button>
    </div>
  );
}

📋 Methods Available

requestAuthData()

Requests authentication data from the Wuffi Tap host app.

miniAppWrapper.requestAuthData().then((authData: IAuthenData) => {
  console.log("User JWT:", authData.jwt);
});

closeGame()

Sends a message to the Wuffi Tap host app to close the mini-game.

miniAppWrapper.closeGame();

🛠 Data Structures

IAuthenData

This interface defines the authentication data structure.

export interface IAuthenData {
  jwt: string;
  user: IUser;
  tapStatus?: ITapStatus;
}

IUser

This interface defines the user data structure.

export interface IUser {
  id: string;
  first_name: string;
  last_name: string;
}

ITapStatus

This interface defines the tap status information, including energy levels and tap counts.

export interface ITapStatus {
  totalPawsEarned: number;
  totalTapsCount: number;
  currentEnergy: number;
  currentEnergyUpdateTime: number;
  respondTime: number;
  receivedTime: number;
  totalSeasonPawsEarned: number;
}

📡 Communication Mechanism

The library uses the postMessage API to communicate between the mini-app and the Wuffi Tap host app. It listens for incoming messages and handles them appropriately based on the action type.

🎮 Actions

  • REQUEST_AUTH_DATA: Requests authentication data from the host app.
  • SEND_AUTH_DATA: Receives the authentication data sent from the host app.
  • CLOSE_GAME: Sends a request to the host app to close the mini-game.

🛠 Development

Build

To build the library, run:

npm run build

Testing

To run tests:

npm run test