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

@ledgelabs/typescript-api-client

v0.1.10

Published

Partnership SDK for integrating with Game Studios in order to provide a full event experience.

Downloads

143

Readme

ledge-typescript-api-client

This is an early version of Ledge Developer Docs. Our API is still in active early stages of development and is subject to change.

Welcome to Ledge Developer Docs. We are constantly improving and we'd greatly appreciate your feedback, so please feel free to create issues or chat with [email protected].

[COMING SOON] We also have a developer chat in our Discord.

Table of Contents

Important Notes

  • We recommend you use our SDK on the server side for performance and security.
  • We recommend you track user activity in batches.
  • Have our SDK integrated and ready for testing 1-2 weeks before the event start date.
  • Register your users as early as possible to begin tracking their in game activity.

Quick Start

Requirements:

  1. API_KEY from one of the Ledge Admins, get in contact ([email protected])!
  2. API_URL from one of the Ledge Admins, get in contact ([email protected])!

1. Install our npm package at npm package

npm i @ledgelabs/typescript-api-client

or

yarn add @ledgelabs/typescript-api-client

2. Setup Configuration

import { Configuration } from "@ledgelabs/typescript-api-client";

const config = new Configuration({
  apiKey: API_KEY
  basePath: API_URL,
});

3. Register user so we can track activity

  • Register this user as soon as possible, ideally when they open the game. so that we can start tracking player activity and reward progress towards quests.
  • Original creation date is when this user first joined your game.
import { ExternalApi } from "@ledgelabs/typescript-api-client";

const ledgeApi = new ExternalApi(config);

await ledgeApi.registerUser("fake-api-key", {
    userId: "fake-user-id",
    username: "random-fake-username",
    originalCreationDate: new Date().toISOString(),
});

4. Track in-game user activity

await ledgeApi.trackActivity({
    activityId: "kill-5-ogres",
    occurrence: "2024-04-20T18:18:03.369Z",
    userId: "fake-user-id",
    count: 1,
  });

SDK Reference

Description

Registers this user (externally) with Ledge, so we can begin tracking their in game activity

Ideally, call this method as soon as this user starts the game.

Params

export interface ExternalUser {
    originalCreationDate?: string;
    userId: string;
    username: string;
}

originalCreationDate is used for attribution purposes and revenue sharing but is optional, leaving this undefined will simply not attribute this user's acquisition and consequently no revenue shared. Input this parameter if unsure.

username does not need to be unique.

userId must be unique for each player within a game (per API_KEY)

Return Type

export interface RegisterUser200Response {
    linkingCode: string;
    ledgeLink: string;
}

linkingCode is a unique code per user per game, used to identify your registered user with a Ledge account.

ledgeLink is a link to Ledge login page with a linking code.

Description

Tracks a single game activity/event from a user.

In order to prevent tracking duplicate activities each userId, activityId, and occurrence when combined should be unique.

Use this method, if there are no plans to track activities in batches. Otherwise, tracking activities in batches is preferred for efficiency and to reduce load on our systems.

Params

export interface TrackActivityInput {
    occurrence: string;
    count?: number;
    activityId: string;
    userId: string;
}

occurrence is the datetime of when this event occurred in ISO format. Example: 2024-04-20T18:18:03.369Z

count is the number of times this event happened. Default is 1.

activityId is similar to an analytics tracking event name which is used to identify activities with their quests.

userId is the same userId used to register this user.

Return Type

export interface TrackActivity200Response {
  message: string;
  data: {
    activityId: string;
    userId: string;
    count: number;
    occurence: Date;
    processed: boolean;
  } | null;
}

message indicating activity has been successfully recorded and has been queued for processing.

data is null if no activity was tracked. Otherwise, returns tracked activity data.

Description

Track an array of game activities (events) for a given user ID.

This method is similar to trackActivity, but it allows tracking multiple activities in a single request.

Params

userId: string

export interface TrackBatchActivitiesInput = {
  activityId: string;
  count?: number;
  occurrence: string;
}[];

See trackActivity for details about params.

Return Type

export interface TrackBatchActivitiesByUser200Response {
    'count': number;
    'message': string;
}

count indicating the number of succesfully inserted activities.

message indicating activity has been successfully recorded and has been queued for processing.

Ledge Client Error Types

ApiError

| Property | Description | | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | code | Ledge Specific status code which follows HTTP response status codes for the most part. | | message | Error message associated with this error code |

Error Codes

403 Invalid Api Key. Please reach out to Ledge.

400 Bad Request (e.g missing data, invalid inputs).

409 Conflict: User not registered, skipping this user. Make sure this user is registered with the ledge via registerUser

500 Internal Server Error.