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

@enigma-lake/zoot-platform-sdk

v1.0.17

Published

Zoot Platform SDK

Downloads

2,052

Readme

Zoot Platform SDK

The Zoot Platform SDK is a TypeScript library designed to seamlessly integrate games into the Enigma Lake Zoot platform. This SDK provides developers with the necessary tools to enhance the user experience by accessing user information such as nickname, session data, and avatar, expanding or collapsing the game view, as well as utilizing Enigma Lake Zoot's currency system.

Features

  • User Information: Retrieve user data including nickname, session information, and avatar.
  • Currency Integration: Utilize Enigma Lake Zoot's currency system within your game.
  • Balance Query: Check the user's current balance of Enigma Lake Zoot's currency.
  • Currency Management: Change the current currency being used within the game.
  • Expand/Collapse game view: Toggle the game view.
  • Play limits: Fetch the play limits associated with each currency
  • Notify about the play outcome: Trigger a toast about the play outcome
  • Modal Triggers: Trigger login or purchase modals to facilitate in-game transactions.

Getting Started

To start using the Zoot Platform SDK, follow these steps:

  1. Installation: Install the SDK via npm:
npm install @enigma-lake/zoot-platform-sdk
  1. Integration: You can import the entire package using the syntax
import * as zootSDK from '@enigma-lake/zoot-platform-sdk';

or you can import specific types, events, and methods individually, such as:

 import { Currency } from '@enigma-lake/zoot-platform-sdk';
  1. Usage: Utilize SDK methods to access user information and integrate Enigma Lake Zoot's features into your game.

To establish communication with the Enigma Lake Zoot platform, it is essential to listen to ZootEvent messages. This can be achieved by registering an event listener as follows:

window.addEventListener('message', (event: MessageEvent<ZootEvent>) => {
    if (event.data.event_id === EVENTS.EL_GET_USER_CURRENCY) {
        // Handle ZootEvent for retrieving user currency
        // Example: do something...
    }
    if (event.data.event_id === EVENTS.EL_USER_BALANCE) {
        // Handle ZootEvent for user balance information
        // Example: do something...
    }
    if (event.data.event_id === EVENTS.EL_USER_INFORMATION) {
        // Handle ZootEvent for user information retrieval
        // Example: do something...
    }
    if (event.data.event_id === EVENTS.EL_GET_EXPANDED_GAME_VIEW) {
        // Handle ZootEvent for toggling game view
        // Example: do something...
    }
     if (event.data.event_id === EVENTS.EL_SET_PLAY_LIMITS) {
        // Handle ZootEvent for fetching the play limits
        // Example: do something...
    }
});

To facilitate these events, you can easily trigger them by calling specific methods based on your information needs:

  • To retrieve the user balance, utilize the method getUserBalanceEvent().
  • For acquiring user currency information, use getUserCurrencyEvent().
  • To change the user currency, use setUserCurrencyEvent(data: UserCurrency).
  • To get the play limits associated with each currency, use getPlayLimitsEvent().
  • To toggle the game view, use toggleGameViewEvent(data: GameExpandedView).
  • If you require user information such as nickname, session, or avatar, call getUserInformationEvent().
  • To initiate the purchase flow for acquiring coins, utilize purchaseCoinsEvent().
  • For triggering the login flow, use loginUserEvent().
  • To notify the platform about the play outcome, use notifyWithPlayOutcome(payload: PlayOutcomePayload).
  • If you want to request all user data and the game view at once, simply invoke the function requestInitData().
  • Alternatively, you can dispatch toast notification messages directly to the Enigma Lake Zoot client by invoking the method showNotificationEvent(message: Notification).

Data Types

These data types define the events, user information, currency details, and notifications used within the Enigma Lake Zoot platform integration.

enum EVENTS {
  EL_USER_BALANCE = "EL_USER_BALANCE",
  EL_GET_USER_CURRENCY = "EL_GET_USER_CURRENCY",
  EL_SET_USER_CURRENCY = "EL_SET_USER_CURRENCY",
  EL_SET_GAME_ROUND_STATE = "EL_SET_GAME_ROUND_STATE",
  EL_USER_INFORMATION = "EL_USER_INFORMATION",
  EL_LOGIN_USER = "EL_LOGIN_USER",
  EL_PURCHASE_COINS = "EL_PURCHASE_COINS",
  EL_SHOW_TOAST = "EL_SHOW_TOAST",
  EL_TOGGLE_EXPAND_GAME_VIEW = "EL_TOGGLE_EXPAND_GAME_VIEW",
  EL_GET_EXPANDED_GAME_VIEW = 'EL_GET_EXPANDED_GAME_VIEW',
  EL_SHOW_PLAY_OUTCOME = 'EL_SHOW_PLAY_OUTCOME',
  EL_GET_PLAY_LIMITS = "EL_GET_PLAY_LIMITS",
  EL_SET_PLAY_LIMITS = "EL_SET_PLAY_LIMITS",
}

interface UserBalance {
  sweepsBalance: number;
  goldBalance: number;
}

interface UserCurrency {
  currency: Currency;
}

interface GameExpandedView {
  expanded: boolean;
  isMobileView: boolean;
}

type UserInformation = {
  id: number;
  nickname?: string;
  avatar?: string;
  accessToken: string;
};

interface PlayOutcomePayload {
  winMultiplier: number;
  playAmount: number;
  currency: Currency;
}

interface PlayLimits {
  [Currency.SWEEPS]: {
    limits: {
      min: number;
      max: number;
    };
    defaultValues: number[];
  };
  [Currency.GOLD]: {
    limits: {
      min: number;
      max: number;
    };
    defaultValues: number[];
  };
}

interface Notification {
  type: "success" | "error" | "info" | "custom";
  message: string;
}

enum Currency {
  SWEEPS = "sweeps",
  GOLD = "gold",
}

type RequestDataEvent = UserBalance | UserCurrency | Notification | UserInformation | GameExpandedView ;

interface GetUserInformationEvent {
  type: EVENTS.EL_USER_INFORMATION;
  event_id: EVENTS.EL_USER_INFORMATION;
  data: UserInformation;
}

interface GetUserCurrencyEvent {
  type: EVENTS.EL_GET_USER_CURRENCY;
  event_id: EVENTS.EL_GET_USER_CURRENCY;
  data: UserCurrency;
}

interface GetUserBalanceEvent {
  type: EVENTS.EL_USER_BALANCE;
  event_id: EVENTS.EL_USER_BALANCE;
  data: UserBalance;
}


export interface GetGameExpandedView {
  type: EVENTS.EL_GET_EXPANDED_GAME_VIEW;
  event_id: EVENTS.EL_GET_EXPANDED_GAME_VIEW;
  data: GameExpandedView;
}

export interface GetPlayLimitsEvents {
  type: EVENTS.EL_SET_PLAY_LIMITS;
  event_id: EVENTS.EL_SET_PLAY_LIMITS;
  data: PlayLimits;
}

export type ZootEvent =
  | GetUserBalanceEvent
  | GetUserCurrencyEvent
  | GetUserInformationEvent
  | GetGameExpandedView
  | GetPlayLimitsEvents;

Currency Information

Enigma Lake Zoot supports two currencies: sweeps and gold. You can visually represent these coins using the CSS classes sweeps_icon for sweeps and gold_icon for gold after importing the CSS file into your root file:

import '@enigma-lake/zoot-platform-sdk/dist/bundle.css';