0.0.4 • Published 10 months ago

@wibus-studio/keygen-node v0.0.4

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

Keygen Node.js SDK

Node.js SDK for Keygen.sh. Specially customized for private use.

Motivation

The Keygen.sh platform does not provide any usable SDK, with only an official keygen-go and an unofficial keygen-rust. Neither of these SDKs align with my technology stack, so I had to write my own...

Additionally, these SDKs are merely implementations of the API Reference, requiring users to implement all the necessary details themselves. I need a convenient SDK that can easily handle product activation/validation/deactivation processes... and to achieve this, we need to create our own library...

There are many customizations that I have made to the SDK, so it is not suitable for public use.

Features

  • License Validation
  • Machine Activation
  • Machine Deactivation
  • Get System Information

Usage

pnpm install @wibus-studio/keygen-node

Basic Usage

If you are inside my studio, you can use the following code to initialize the client:

Initialize Client

import { KeygenClient } from "@wibus-studio/keygen-node";

const client = new KeygenClient({
  accountId: "YOUR_ACCOUNT_ID",
  productId: "YOUR_PRODUCT_ID",
  // Optional configuration
  baseUrl: "https://api.keygen.sh/v1",
  // Whether to require fingerprint validation
  requireFingerprintValidation: true,
  // System identifier configuration
  systemIdentifier: {
    includeFingerprint: true,
    includePlatform: true,
    includeHostname: true,
    includeIp: true,
    includeCores: true,
    metadata: {
      // Custom metadata
    },
  },
});

License Validation

!IMPORTANT You need to check the validity of the license yourself. For more information, please refer to the API Reference.

// Basic validation
const validation = await client.validateLicense("LICENSE_KEY");
if (validation.meta.valid) {
  // ⚠️ You need to check the validity of the license yourself!!!
  console.log("License is valid");
  console.log("License details:", validation.data);
} else {
  console.log("License is invalid:", validation.meta.detail);
}

// Validation with system information
const validationWithSystem =
  await client.validateLicenseWithSystem("LICENSE_KEY");

Machine Activation

// Activate machine
const activation = await client.activateMachine("LICENSE_ID", "LICENSE_KEY");
console.log("Machine activated:", activation.data);

// Deactivate machine
await client.deactivateMachine("MACHINE_ID", "LICENSE_KEY");

Error Handling

All errors are thrown as Error objects.

We provide a ApiError type to help you handle errors. It's following the API Reference.

import type { ApiError } from "@wibus-studio/keygen-node";

API Reference

KeygenClient Configuration Options

interface KeygenConfig {
  // Required parameters
  accountId: string; // Keygen account ID
  productId: string; // Product ID

  // Optional parameters
  baseUrl?: string; // API base URL
  version?: string; // API version
  requireFingerprintValidation?: boolean; // Whether to require fingerprint validation
  systemIdentifier?: SystemIdentifierConfig; // System identifier configuration
}

interface SystemIdentifierConfig {
  includeFingerprint?: boolean; // Whether to include fingerprint
  includePlatform?: boolean; // Whether to include platform information
  includeHostname?: boolean; // Whether to include hostname
  includeIp?: boolean; // Whether to include IP
  includeCores?: boolean; // Whether to include CPU cores
  metadata?: Record<string, any>; // Custom metadata
}

License Status

License may have the following statuses:

enum LicenseStatus {
  ACTIVE = "ACTIVE", // Active
  INACTIVE = "INACTIVE", // Inactive
  EXPIRING = "EXPIRING", // Expiring
  EXPIRED = "EXPIRED", // Expired
  SUSPENDED = "SUSPENDED", // Suspended
  BANNED = "BANNED", // Banned
}

Validation Status

Validation response will contain one of the following statuses:

enum LicenseValidationStatus {
  VALID = "VALID", // Valid
  SUSPENDED = "SUSPENDED", // Suspended
  EXPIRED = "EXPIRED", // Expired
  OVERDUE = "OVERDUE", // Overdue
  NOT_FOUND = "NOT_FOUND", // Not found
  NO_MACHINE = "NO_MACHINE", // No machine
  NO_MACHINES = "NO_MACHINES", // No machine group
  TOO_MANY_MACHINES = "TOO_MANY_MACHINES", // Too many machines
  // ... More statuses please refer to type definition
}

References

Author

Keygen Node.js SDK © Wibus. Created on Jan 19, 2025. All rights reserved.

Personal Website · Blog · GitHub @wibus-wee · Telegram @wibus✪

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago