Advanced TypeScript-first library for the GermanMiner API.
- 🔒 Type-safe - Full TypeScript support with runtime validation using Zod
- ⚡ Smart caching - Automatic request limit tracking with cache expiration
- 🚀 Lazy loading - Optional deferred data loading for better performance
- 🔄 Cross-runtime - Works with Deno, Node.js and also on every web browser
- 🛡️ Error handling - Comprehensive custom error classes
- 🐛 Debug mode - Built-in debugging support
import { GMClient } from "jsr:@devdariush/germanminerjs";# for npm:
npx jsr add @devdariush/germanminerjs
# or yarn:
yarn add jsr:@devdariush/germanminerjs
# or pnpm:
pnpm i jsr:@devdariush/germanminerjsimport { GMClient } from "@devdariush/germanminerjs";
// Create client with API key
const client = await GMClient.create({
apiKey: "your-api-key-here", // Your GermanMiner API key (default: environment variables)
lazyMode: false, // Load data immediately (default: false)
debugMode: false // Enable debug logging (default: false)
});
// Get API info
const info = await client.getApiInfo();
console.log(`Requests: ${info.requests}/${info.limit}`);
// Check remaining requests
const remaining = await client.getRemainingRequests();
console.log(`Remaining: ${remaining}`);The client can automatically load your API key from environment variables:
GM_API_KEYorAPI_KEY- Your GermanMiner API keyNODE_ENV=development(Node.js) orDENO_ENV=development(Deno) - Enables debug mode
// No need to pass apiKey if set in environment
const client = await GMClient.create();| Option | Type | Default | Description |
|---|---|---|---|
apiKey |
string |
from env | Your GermanMiner API key |
lazyMode |
boolean |
false |
Defer loading data until explicitly requested |
debugMode |
boolean |
from env | Enable debug logging |
// Get a specific bank account
const account = await client.bank("DEF04317923");
console.log(account.accountNumber);
console.log(account.balance);
console.log(account.accountType); // "Privatkonto" or "Firma"
// In lazy mode, load data manually
const client = await GMClient.create({ lazyMode: true });
const account = await client.bank("DEF04317923");
await account.load(); // Load balance, type, and bearer
console.log(account.balance);
// List all accounts owned by API key owner
const allAccounts = await client.bank().listAll();
console.log(`You have ${allAccounts.length} accounts`);
// Filter accounts
const privateAccounts = allAccounts.filter(
acct => acct.accountType === "Privatkonto"
);// Get player by name
const player = await client.player().fromPlayername("Steve");
console.log(player.uuid);
console.log(player.playerName);
// Get player by UUID
const player = await client.player().fromUuid("69bfb349-a17d-476a-8142-67df65a86039");
console.log(player.playerName);
console.log(player.uuid);// Check if limit is reached
if (client.isLimitReached()) {
console.log("Request limit reached!");
}
// Get remaining requests
const remaining = await client.getRemainingRequests();
console.log(`${remaining} requests remaining`);
// Get detailed API info
const info = await client.getApiInfo();
console.log(`Limit: ${info.limit}`);
console.log(`Current requests: ${info.requests}`);
console.log(`Outstanding costs: ${info.outstandingCosts}`);Main client class for interacting with the GermanMiner API.
GMClient.create(options?)- Create and initialize a client instance (async)
getApiInfo(ignoreCache?)- Get API usage informationgetRemainingRequests()- Get number of remaining API requestsisLimitReached()- Check if request limit has been reachedbank()- Get BankService instancebank(accountNumber)- Get specific BankAccountplayer()- Get PlayerService instance
Represents a bank account.
accountNumber: string- The account numberbalance?: number- Account balance (loaded based on lazy mode)accountType?: "Privatkonto" | "Firma"- Type of accountbearer?: Player | string- Account owner (Player for private accounts)
load()- Manually load account data
Service for bank-related operations.
get(accountNumber)- Get a specific bank accountlistAll()- List all accounts owned by API key owner
Represents a Minecraft player.
playerName?: string- Player's usernameuuid?: string- Player's UUID
load()- Manually load player data
Service for player-related operations.
fromPlayername(playerName)- Get player by usernamefromUuid(uuid)- Get player by UUID
The library provides custom error classes:
import { GMClient } from "@devdariush/germanminerjs";
try {
const client = await GMClient.create({ apiKey: "invalid" });
} catch (error) {
if (error instanceof ApiError) {
console.error(`API Error: ${error.message}`);
console.error(`Status: ${error.status}`);
} else if (error instanceof GmClientError) {
console.error(`Client Error: ${error.message}`);
} else if (error instanceof LimitReachedError) {
console.error(`Limit reached: ${error.currentRequests}/${error.limit}`);
}
}ApiError- API request failedGmClientError- Client configuration or usage errorLimitReachedError- Request limit has been reached
Lazy mode defers loading data until explicitly requested, saving API requests:
// Without lazy mode (default)
const client = await GMClient.create({ lazyMode: false });
const account = await client.bank("ACC123"); // Data loaded immediately
console.log(account.balance); // Available
// With lazy mode
const client = await GMClient.create({ lazyMode: true });
const account = await client.bank("ACC123"); // Data NOT loaded yet
console.log(account.balance); // undefined
await account.load(); // Now load the data
console.log(account.balance); // AvailableEnable debug mode to see detailed logging:
const client = await GMClient.create({ debugMode: true });
// Will log:
// - Request count updates
// - Schema validation results
// - Fetch operations and responses (API key masked in DEBUG logs)
// - ... and much more- Deno 2.x or newer
# Set your API key
export GM_API_KEY="your-api-key"
# or use a .env file in the root folder
# Run the example
deno task devdeno lintdeno fmtThis project is licensed under the AGPL-3.0 License - see the LICENSE file for details.
Dariush Komeili
https://github.com/devDariush/germanminerjs