0xDocs 0x.limo

Docs / JavaScript SDK

@0xlimo/iap API

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

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

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

#@0xlimo/iap

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

#IapErrorCode

type

ts
type IapErrorCode =
  | "canceled" | "insufficient_funds" | "limit_reached" | "already_owned" | "not_found"
  | "not_signed_in" | "unavailable" | "busy" | "failed" | "timeout" | "not_in_launcher";

#IapError

class

ts
class IapError extends Error {
  code: IapErrorCode | string;
}

#Purchase

interface

ts
interface Purchase {
  id: string;
  appid: number;
  sku: string;
  name?: string;
  kind: "consumable" | "permanent";
  quantity: number;
  consumed?: number;
  remaining?: number;
  amount?: number;
  amountUsd?: string;
  status?: "paid" | "refunded";
  [k: string]: unknown;
}

#Item

interface

ts
interface Item {
  sku: string;
  name: string;
  description?: string;
  price: number;
  priceUsd: string;
  kind: "consumable" | "permanent";
  max_per_player?: number | null;
  owned?: unknown;
  [k: string]: unknown;
}

#Entitlement

interface

ts
interface Entitlement {
  sku: string;
  name: string;
  kind: "consumable" | "permanent";
  owned?: boolean;
  available?: number;
  [k: string]: unknown;
}

#IapClient

interface

ts
interface IapClient {
  available(): boolean;
  purchase(sku: string, opts?: { quantity?: number }): Promise<{ purchase: Purchase; receipt: string }>;
  items(): Promise<{ items: Item[]; balance: number | null; balanceUsd: string | null }>;
  inventory(): Promise<{ entitlements: Entitlement[]; purchases: Purchase[] }>;
  close(): void;
}

#createIapClient

function

ts
function createIapClient(opts?: { window?: Window; launcherOrigin?: string | null }): IapClient;

#available

function

ts
function available(): boolean;

#purchase

function

ts
function purchase(sku: string, opts?: { quantity?: number }): Promise<{ purchase: Purchase; receipt: string }>;

#items

function

ts
function items(): Promise<{ items: Item[]; balance: number | null; balanceUsd: string | null }>;

#inventory

function

ts
function inventory(): Promise<{ entitlements: Entitlement[]; purchases: Purchase[] }>;

@0xlimo/iap/client has the same typings as @0xlimo/iap.

#@0xlimo/iap/server

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

#IapError

class

ts
class IapError extends Error {
  code: string;
  status?: number;
  body?: unknown;
}

#ReceiptKey

interface

ts
interface ReceiptKey { kid: string; ed25519: string; [k: string]: unknown }

#Keys

type

ts
type Keys = { keys: ReceiptKey[] } | ReceiptKey[] | Record<string, string>;

#ReceiptPurchase

interface

ts
interface ReceiptPurchase {
  id: string;
  appid: number;
  steamid: string;
  sku: string;
  kind: "consumable" | "permanent";
  quantity: number;
  amount: number;
  currency: string;
  iat: number;
}

#VerifyResult

type

ts
type VerifyResult = { valid: true; purchase: ReceiptPurchase; payload: Record<string, unknown> } | { valid: false; reason: string };

#publicKeyFromHex

function

ts
function publicKeyFromHex(hex: string): KeyObject;

#decodeReceipt

function

ts
function decodeReceipt(receipt: string): Record<string, unknown> | null;

#verifyReceipt

function

ts
function verifyReceipt(receipt: string, opts: { keys: Keys; appid?: number | string | null }): VerifyResult;

#fetchKeys

function

ts
function fetchKeys(api?: string, opts?: { maxAgeMs?: number; force?: boolean; fetch?: typeof fetch }): Promise<Keys>;

#IapServer

class

ts
class IapServer {
  constructor(opts: { api?: string; key: string; appid?: number | string | null; fetch?: typeof fetch });
  static fromEnv(opts?: { api?: string; appid?: number | string | null; fetch?: typeof fetch }): IapServer;
  api: string;
  appid: string | null;
  verify(what: string | { receipt: string } | { purchase: string }): Promise<{ valid: boolean; reason?: string; purchase?: Record<string, unknown> }>;
  consume(purchaseOrReceipt: string, opts?: { quantity?: number; idempotencyKey?: string }): Promise<{ purchase: Record<string, unknown>; consumed_now: number }>;
  inventory(steamid: string | number): Promise<{ steamid: string; appid: number; entitlements: unknown[]; purchases: unknown[] }>;
  verifyOffline(receipt: string): Promise<VerifyResult>;
}

#KEY_FILE

const

ts
const KEY_FILE: "x1-iap.key";

#hasServerKey

function

ts
function hasServerKey(): boolean;