npm package: @getklaim/klaim
Description: SDK for interacting with the Klaim API (credit, users, api-key, transactions, app-status)
Latest version: 0.0.2

# klaim SDK

The Klaim SDK wraps the endpoints provided by the API server into easy-to-use functions, making it simpler for clients to interact with the API.

This SDK provides a convenient interface for interacting with the Klaim API **(credit, users, api-key, transactions, app-status)**

---

## Installation

```
npm install @getklaim/klaim
```

## Documentation
Please refer to the link for more details. [(see klaim api docs)](https://klaim.gitbook.io/klaim-api)

## Usage

The SDK package needs to be configured with your account's secret key, which is available in the [klaim Dashboard.](https://app.getklaim.com/)



### 1. Import and Set Base URL

> **About `baseUrl`:**
>
> You can use the `setApiBaseUrl(baseUrl: string)` function to specify the base URL of the API server.
In the current version, no default server address is set, so you must configure it with the actual Klaim API server URL you intend to use.
>
> Example: `setApiBaseUrl('https://api.klaim.com')`
> ㅤ

**JavaScript**
```js
const { setApiBaseUrl } = require('@getklaim/klaim');
```

**TypeScript**

```ts
import { setApiBaseUrl } from '@getklaim/klaim';
```

### 2. Example: Get All Users Credits

**JavaScript**
```js
const { getAllUsersCredits } = require('@getklaim/klaim');

const apiKey = 'your-local-api-key';
(async () => {
  const credits = await getAllUsersCredits(apiKey);
  console.log(credits);
})();
```

**TypeScript**
```ts
import { getAllUsersCredits } from '@getklaim/klaim';

const apiKey = 'your-local-api-key';
(async () => {
  const credits = await getAllUsersCredits(apiKey);
  console.log(credits);
})();
```

### 3. Example: Get User Credit Balance

**JavaScript**
```js
const { getUserCreditBalance } = require('@getklaim/klaim');
const userId = 'test-user-id';
(async () => {
  const balance = await getUserCreditBalance(apiKey, userId);
  console.log(balance);
})();
```

**TypeScript**
```ts
import { getUserCreditBalance } from '@getklaim/klaim';
const userId = 'test-user-id';
(async () => {
  const balance = await getUserCreditBalance(apiKey, userId);
  console.log(balance);
})();
```

### 4. Example: Get App Status

**JavaScript**
```js
const { getAppStatus } = require('@getklaim/klaim');
(async () => {
  const status = await getAppStatus();
  console.log(status);
})();
```

**TypeScript**
```ts
import { getAppStatus } from '@getklaim/klaim';
(async () => {
  const status = await getAppStatus();
  console.log(status);
})();
```

---

## API Reference

The Klaim SDK provides a set of functions mapped directly to the main Klaim API endpoints. These functions allow you to easily manage credits, users, API keys, transactions, and check service status.

Below is a summary of the available endpoints and their roles:

1. **/credit**
    - `getAllUsersCredits` – Retrieve a list of credits for all users
    - `getUserCreditBalance` – Get the credit balance of a specific user
    - `getUserCreditUsage` – Get the credit usage history of a specific user
    - `putUserCredit` – Increase or decrease a user's credit (charge/deduct)

2. **/users**
    - `getUser` – Retrieve information of a specific user
    - `createUser` – Create a new user
    - `updateUser` – Update user information

3. **/api-key**
    - `getApiKey` – Retrieve API key information
    - `getApiKeyUsage` – Get API key usage history
    - `createApiKey` – Create a new API key
    - `deleteApiKey` – Delete (deactivate) an API key

4. **/transactions**
    - `getTransactions` – Retrieve transaction history

5. **/app-status**
    - `getAppStatus` – Check service status (health check)

---

## TypeScript & JavaScript Support

This package includes TypeScript declaration files, allowing for type-safe usage in TypeScript projects and immediate usability in JavaScript projects as well.

---

## Local Development & Testing

1. Build the SDK:
   ```
   npm run build
   ```
2. In a separate test project, install via relative path:
   ```
   npm install ../klaim-apis-npm
   ```
3. Import and use as shown above.

---

## License
MIT