0xDocs 0x.limo

Docs / JavaScript SDK

@0xlimo/platform API

Generated from the typings of @0xlimo/platform 0.1.1: every exported type, class and function.

Generated from @0xlimo/platform typings at build 3a4a58e45c+dirty. Do not edit by hand.

Typings: src/index.d.ts, src/launcher.d.ts, src/server.d.ts. For concepts and examples see the package guide.

#@0xlimo/platform

js
import { ... } from "@0xlimo/platform";

#Session

interface

ts
interface Session {
  accessToken: string;
  refreshToken: string;
  expiresAt: number;
  steamid: string | null;
  persona: string | null;
  guest: boolean;
}

#Lobby

interface

ts
interface Lobby {
  id: string;
  appid: number;
  owner: string;
  members: string[];
  data: Record<string, string>;
  max_members: number;
  type: number;
  joinable: boolean;
  [k: string]: unknown;
}

#LobbyFilter

interface

ts
interface LobbyFilter {
  kind: "string" | "numerical" | "near" | "slots" | "count" | "compatible";
  key?: string;
  value?: string | number;
  cmp?: number;
  lobby?: string;
}

#LeaderboardEntry

interface

ts
interface LeaderboardEntry {
  steamid: string;
  score: number;
  details: number[];
  ugc: string | null;
  rank: number;
  persona: string;
}

#X1Error

class

ts
class X1Error extends Error {
  status: number;
  body: unknown;
  path: string;
}

#Platform

interface

ts
interface Platform {
  readonly session: Session | null;
  auth: {
    guest(): Promise<Session>;
    password(username: string, password: string): Promise<Session>;
    refresh(): Promise<Session>;
    signOut(): Promise<void>;
    onChange(fn: (s: Session | null) => void): () => void;
  };
  me(): Promise<{ steamid: string; persona_name: string; [k: string]: unknown }>;
  lobbies: {
    /** type: 0 private, 1 friends only, 2 public (ELobbyType). */
    create(o?: { maxMembers?: number; type?: number }): Promise<Lobby>;
    search(filters?: LobbyFilter[]): Promise<{ lobbies: Lobby[]; [k: string]: unknown }>;
    get(id: string): Promise<Lobby>;
    join(id: string): Promise<{ response: number; lobby?: Lobby }>;
    leave(id: string): Promise<unknown>;
    setData(id: string, data: Record<string, string | null>): Promise<unknown>;
    setMemberData(id: string, data: Record<string, string | null>): Promise<unknown>;
    settings(id: string, s: Record<string, unknown>): Promise<unknown>;
    chat(id: string, message: string | Uint8Array): Promise<{ chat_id: number }>;
    invite(id: string, steamid: string): Promise<unknown>;
  };
  leaderboards: {
    find(name: string, o?: { create?: boolean; sort?: number; display?: number }): Promise<{ id: string; name: string; sort: number; display: number; entry_count: number }>;
    upload(board: string | number, score: number, o?: { details?: number[]; method?: "keep_best" | "force_update" }): Promise<{ changed: boolean; rank_new: number; rank_prev: number }>;
    entries(board: string | number, o?: { request?: "global" | "around_user" | "friends" | "users"; start?: number; end?: number; users?: string[] }): Promise<LeaderboardEntry[] | { entries: LeaderboardEntry[] }>;
  };
  stats: {
    get(steamid?: string): Promise<{ stats: Record<string, number>; achievements: Record<string, number | { achieved: boolean; unlocked_at?: number }> }>;
    set(v: { stats?: Record<string, number>; achievements?: Record<string, unknown> }): Promise<unknown>;
    global(days?: number): Promise<unknown>;
  };
  cloud: {
    list(): Promise<Array<{ name: string; size: number; timestamp: number }>>;
    read(path: string): Promise<Uint8Array>;
    readText(path: string): Promise<string>;
    write(path: string, data: string | Uint8Array): Promise<unknown>;
    remove(path: string): Promise<unknown>;
  };
  plays: {
    start(o?: { mode?: "web" | "native"; source?: "launcher" | "link" | "direct" | "other"; ref?: string }): Promise<{ id: string; beat(): Promise<unknown>; end(): Promise<unknown> }>;
    auto(o?: { mode?: "web" | "native"; source?: "launcher" | "link" | "direct" | "other"; ref?: string; everyMs?: number; window?: Window }): Promise<() => void>;
  };
  request(method: string, path: string, opts?: { body?: unknown; binary?: boolean }): Promise<any>;
}

#siteApi

function

The platform API URL of a hosted game: x1.json api, else https://api.0x.limo.

ts
function siteApi(o?: { x1json?: string; fallback?: string; fetch?: typeof fetch }): Promise<string>;

#findAppid

function

A listed game's app id by its store id (x1.config.json "id"), from the public catalog; null while unlisted.

ts
function findAppid(o: { baseUrl: string; id: string; fetch?: typeof fetch }): Promise<number | null>;

#createPlatform

function

ts
function createPlatform(o: {
  /** The backend, e.g. https://api.0x.limo (or http://localhost:8080 in development). */
  baseUrl: string;
  appid?: number;
  /** Where the session is kept: localStorage by default, null for memory only. */
  storage?: Pick<Storage, "getItem" | "setItem" | "removeItem"> | null;
  fetch?: typeof fetch;
}): Platform;

#@0xlimo/platform/launcher

js
import { ... } from "@0xlimo/platform/launcher";

#Plan

interface

ts
interface Plan {
  id: string;
  name: string;
  description: string;
  entitlement: string;
  currency: string;
  prices: { week?: number; month: number; year?: number };
  active?: boolean;
}

#Subscription

interface

ts
interface Subscription {
  id: string;
  plan_id: string;
  plan_name: string;
  entitlement: string;
  period: "week" | "month" | "year";
  price: number;
  currency: string;
  status: "active" | "grace" | "paused" | "ended";
  cancel_at_period_end: boolean;
  current_period_end: number;
  entitled: boolean;
  [k: string]: unknown;
}

#SubscriptionStatus

interface

ts
interface SubscriptionStatus {
  appid: number;
  signedIn: boolean;
  entitlements: string[];
  subscriptions: Subscription[];
  plans: Plan[];
  subscription_only: boolean;
}

#SubscribeResult

interface

ts
interface SubscribeResult {
  outcome: "subscribed" | "already_subscribed" | "canceled" | "signed_out" | "insufficient_funds" | "failed";
  status: SubscriptionStatus;
}

#LauncherError

class

ts
class LauncherError extends Error {
  code: string;
  detail?: string;
}

#Launcher

interface

ts
interface Launcher {
  readonly embedded: boolean;
  request<T = unknown>(type: string, payload?: Record<string, unknown>, opts?: { timeoutMs?: number }): Promise<T>;
  hello(): Promise<{ launcher: "0x1"; version: number; appid: number; signedIn: boolean }>;
  on(type: string, fn: (event: { x1: "event"; type: string; [k: string]: unknown }) => void): () => void;
  subscriptions: {
    status(): Promise<SubscriptionStatus>;
    has(entitlement: string): Promise<boolean>;
    subscribe(plan: string, period?: "week" | "month" | "year"): Promise<SubscribeResult>;
  };
  playTicket(): Promise<string>;
  close(): void;
}

#createLauncher

function

ts
function createLauncher(o?: { launcherOrigins?: string[]; timeoutMs?: number; window?: Window }): Launcher;

#@0xlimo/platform/server

js
import { ... } from "@0xlimo/platform/server";

#EntitlementError

class

ts
class EntitlementError extends Error {
  status: number;
  body: unknown;
}

#TicketCheck

interface

ts
interface TicketCheck {
  valid: boolean;
  steamid?: string;
  appid?: number;
  entitlements: string[];
  entitled?: boolean;
}

#checkTicket

function

ts
function checkTicket(o: { api: string; ticket: string; entitlement?: string; appid?: number; fetch?: typeof fetch; timeoutMs?: number }): Promise<TicketCheck>;

#hasEntitlement

function

ts
function hasEntitlement(o: { api: string; ticket: string; entitlement: string; appid?: number; fetch?: typeof fetch; timeoutMs?: number }): Promise<boolean>;

#serverEntitlement

function

ts
function serverEntitlement(o: { api: string; session: string; steamid: string; entitlement: string; fetch?: typeof fetch; timeoutMs?: number }): Promise<{ steamid: string; appid: number; entitlement: string; entitled: boolean; entitlements: string[] }>;