npm package: @pandaauth/api
Description: Panda Pelican Development LLC API Wrapper
Author: 1intan99
Latest version: 1.0.1

# @pandaauth/api

A TypeScript/JavaScript SDK for integrating PandaAuth into your applications. This package serves as an API wrapper for Panda Pelican Development's authentication and licensing system, providing a simple and type-safe way to interact with the PandaAuth services.

## Table of Contents

- [Installation](#installation)
- [Getting Started](#getting-started)
  - [Prerequisites](#prerequisites)
  - [Authentication](#authentication)
- [Basic Usage](#basic-usage)
- [API Reference](#api-reference)
  - [PandaAuth Class](#pandaauth-class)
    - [getRevenueMode](#getrevenuemode)
    - [checkIdentifier](#checkidentifier)
    - [resetHwid](#resethwid)
    - [generateKeyGet](#generatekeyget)
    - [generateKeyPost](#generatekeypost)
    - [fetchKey](#fetchkey)
    - [keyEdit](#keyedit)
    - [keyDelete](#keydelete)
    - [generatedKeyEdit](#generatedkeyedit)
    - [generatedKeyDelete](#generatedkeydelete)
    - [executionFetch](#executionfetch)
    - [executionPush](#executionpush)
  - [V2Validation Class](#v2validation-class)
    - [validate](#validate)
- [TypeScript Support](#typescript-support)
- [Error Handling](#error-handling)
- [License](#license)

## Installation

```bash
# using npm
npm install @pandaauth/api

# using yarn
yarn add @pandaauth/api

# using pnpm
pnpm add @pandaauth/api
```

## Getting Started

### Prerequisites

Before you begin, ensure you have:

- Node.js version 12 or higher
- An API key from Panda Pelican Development
- `npm`, `yarn`, or `pnpm` package manager

### Authentication

1.  Obtain your API key from the Panda Pelican Development dashboard.
2.  Keep your API key secure and never expose it in client-side code.
3.  Use environment variables or secure configuration management for API key storage.

## Basic Usage

```typescript
import { PandaAuth } from "@pandaauth/api";

// Initialize client
const client = new PandaAuth({
  apiKey: process.env.PANDA_AUTH_API_KEY, // Recommended: Use environment variables
});

// Example: Get revenue mode
async function getRevenueMode() {
  try {
    const response = await client.getRevenueMode({ service: "your-service" });
    console.log(response);
  } catch (error) {
    console.error("Error fetching revenue mode:", error);
  }
}

getRevenueMode();
```

## API Reference

### PandaAuth Class

The `PandaAuth` class is the main entry point for interacting with the PandaAuth API.

#### `getRevenueMode`

Retrieves the revenue mode for a specific service.

- **Parameters**:
  - `service` (string, required): The name of the service.
- **Returns**: `Promise<GetRevenueModeResponse>`

**Example:**

```typescript
const response = await client.getRevenueMode({ service: "your-service" });
console.log(response);
```

**Response:**

```json
{
  "revenueMode": "enabled"
}
```

#### `checkIdentifier`

Validates an identifier against the PandaAuth system.

- **Parameters**:
  - `identifier` (string, required): The identifier to validate.
- **Returns**: `Promise<IdentifierCheckResponse>`

**Example:**

```typescript
const response = await client.checkIdentifier({
  identifier: "user-identifier",
});
console.log(response);
```

**Response:**

```json
{
  "message": "Identifier is valid.",
  "service": "your-service"
}
```

#### `resetHwid`

Resets the Hardware ID (HWID) for a given key.

- **Parameters**:
  - `service` (string, required): The service name.
  - `key` (string, required): The key for which to reset the HWID.
- **Returns**: `Promise<ResetHwidResponse>`

**Example:**

```typescript
const response = await client.resetHwid({
  service: "your-service",
  key: "user-key",
});
console.log(response);
```

**Response:**

```json
{
  "message": "HWID reset successfully."
}
```

#### `generateKeyGet`

Generates a new key using the GET method.

- **Parameters**:
  - `count` (number, required): The number of keys to generate.
  - `isPremium` (boolean, required): Whether the key is for premium access.
  - Other optional parameters as defined in `GenerateKeyQuery`.
- **Returns**: `Promise<GenerateKeyGetResponse>`

**Example:**

```typescript
const response = await client.generateKeyGet({ count: 1, isPremium: true });
console.log(response);
```

**Response:**

```json
{
  "message": "Keys generated successfully.",
  "generatedKeys": [
    {
      "value": "PREMIUM-KEY-123",
      "expiresAt": "2025-12-31T23:59:59.000Z",
      "note": "Generated for testing",
      "isPremium": true,
      "expiresByDaysKey": false,
      "daysKey": 0,
      "noHwidValidation": false
    }
  ]
}
```

#### `generateKeyPost`

Generates a new key using the POST method.

- **Parameters**:
  - `count` (number, required): The number of keys to generate.
  - `isPremium` (boolean, required): Whether the key is for premium access.
  - Other optional parameters as defined in `GenerateKeyQuery`.
- **Returns**: `Promise<GenerateKeyGetResponse>`

**Example:**

```typescript
const response = await client.generateKeyPost({ count: 1, isPremium: false });
console.log(response);
```

**Response:**

```json
{
  "message": "Keys generated successfully.",
  "generatedKeys": [
    {
      "value": "STANDARD-KEY-456",
      "expiresAt": "2025-12-31T23:59:59.000Z",
      "note": "Generated for testing",
      "isPremium": false,
      "expiresByDaysKey": false,
      "daysKey": 0,
      "noHwidValidation": false
    }
  ]
}
```

#### `fetchKey`

Fetches details for a specific key.

- **Parameters**:
  - `fetch` (string, required): The key to fetch.
- **Returns**: `Promise<FetchKeyResponse>`

**Example:**

```typescript
const response = await client.fetchKey({ fetch: "user-key" });
console.log(response);
```

**Response:**

```json
{
  "key": {
    "id": "key-id-123",
    "value": "user-key",
    "note": "User's primary key",
    "isPremium": true,
    "expiresAt": "2025-12-31T23:59:59.000Z",
    "hwid": "user-hwid-123",
    "noHwidValidation": false
  }
}
```

#### `keyEdit`

Edits an existing key.

- **Parameters**:
  - `keyValue` (string, required): The value of the key to edit.
  - Other optional parameters as defined in `KeyEditBody`.
- **Returns**: `Promise<KeyEditResponse>`

**Example:**

```typescript
const response = await client.keyEdit({
  keyValue: "user-key",
  note: "Updated note",
});
console.log(response);
```

**Response:**

```json
{
  "message": "Key updated successfully.",
  "key": {
    "id": "key-id-123",
    "value": "user-key",
    "note": "Updated note",
    "isPremium": true,
    "expiresAt": "2025-12-31T23:59:59.000Z",
    "hwid": "user-hwid-123",
    "noHwidValidation": false
  }
}
```

#### `keyDelete`

Deletes a key.

- **Parameters**:
  - `keyValue` (string, required): The value of the key to delete.
- **Returns**: `Promise<KeyDeleteResponse>`

**Example:**

```typescript
const response = await client.keyDelete({ keyValue: "user-key" });
console.log(response);
```

**Response:**

```json
{
  "message": "Key deleted successfully."
}
```

#### `generatedKeyEdit`

Edits a generated key.

- **Parameters**:
  - `keyValue` (string, required): The value of the generated key to edit.
- **Returns**: `Promise<KeyEditResponse>`

**Example:**

```typescript
const response = await client.generatedKeyEdit({
  keyValue: "generated-key-123",
  note: "New note for generated key",
});
console.log(response);
```

**Response:**

```json
{
  "message": "Key updated successfully.",
  "key": {
    "id": "gen-key-id-456",
    "value": "generated-key-123",
    "note": "New note for generated key",
    "isPremium": false,
    "expiresAt": "2025-12-31T23:59:59.000Z",
    "hwid": null,
    "noHwidValidation": true
  }
}
```

#### `generatedKeyDelete`

Deletes a generated key.

- **Parameters**:
  - `keyValue` (string, required): The value of the generated key to delete.
- **Returns**: `Promise<KeyDeleteResponse>`

**Example:**

```typescript
const response = await client.generatedKeyDelete({
  keyValue: "generated-key-123",
});
console.log(response);
```

**Response:**

```json
{
  "message": "Key deleted successfully."
}
```

#### `executionFetch`

Fetches execution details.

- **Returns**: `Promise<FetchExecutionResponse>`

**Example:**

```typescript
const response = await client.executionFetch();
console.log(response);
```

**Response:**

```json
{
  "executionCount": 125
}
```

#### `executionPush`

Pushes execution data.

- **Returns**: `Promise<ExecutionPushResponse>`

**Example:**

```typescript
const response = await client.executionPush();
console.log(response);
```

**Response:**

```json
{
  "success": true,
  "message": "Execution data pushed successfully."
}
```

### V2Validation Class

The `V2Validation` class provides an enhanced security validation system.

#### `validate`

Validates a key using the V2 validation system.

- **Parameters**:
  - `key` (string, required): The key to validate.
  - `hwid` (string, required): The Hardware ID to validate against.
- **Returns**: `Promise<V2_ValidationResponse>`

**Example:**

```typescript
const validation = new V2Validation({ service: "your-service" });
const response = await validation.validate({
  key: "user-key",
  hwid: "user-hwid",
});
console.log(response);
```

**Response:**

```json
{
  "status": true,
  "message": "Validation successful."
}
```

## TypeScript Support

This package is written in TypeScript and includes type definitions. You'll get full IntelliSense and type-checking out of the box when using TypeScript.

## Error Handling

The package includes proper error handling and will throw appropriate errors for:

- Invalid API keys
- Network issues
- Invalid parameters
- Server errors

Example:

```typescript
try {
  const response = await client.generateKeyGet({
    count: 1,
    isPremium: false,
  });
} catch (error) {
  // Handle error appropriately
  console.error(error);
}
```

## License

This project is licensed under the MIT License.