npm package: @singlespace/singlespace-sdk
Description: SDK for integrating SingleSpace e-commerce platform.
Author: Abilash TS
Latest version: 1.0.0

# @singlespace/singlespace-sdk

Official JavaScript/TypeScript SDK for the SingleSpace API.

## Installation

```bash
npm install @singlespace/singlespace-sdk
```

## Usage

Here's a quick example of how to use the SDK to list all products:

```typescript
import { SingleSpaceSDK } from '@singlespace/singlespace-sdk';

async function main() {
  const sdk = new SingleSpaceSDK({
    seller: 'YOUR_SELLER_SLUG',
    apiKey: 'YOUR_API_KEY',
  });

  try {
    const response = await sdk.products.list();
    console.log('Products:', response.products);
  } catch (error) {
    console.error('Error fetching products:', error);
  }
}

main();
```

## API Reference

The SDK is organized into resources, each providing methods to interact with the SingleSpace API.

### `SingleSpaceSDK`

The main entry point for the SDK.

- `new SingleSpaceSDK(options)`: Creates a new SDK instance.
  - `options.seller` (string, required): Your seller slug.
  - `options.apiKey` (string, required): Your API key.
  - `options.apiVersion` (string, optional): The API version to use (defaults to `v2`).

- `setApiKey(apiKey)`: Updates the API key used for subsequent requests.

### `sdk.products`

- `list(params)`: Fetches a list of products.
  - `params.page` (number, optional): The page number for pagination.
  - `params.category` (string, optional): Filter products by category slug.
  - `params.brand` (string, optional): Filter products by brand slug.

<details>
<summary>Sample Response</summary>

```json
{
    "status": "success",
    "code": 200,
    "message": "Request successful",
    "data": {
        "products": [
            {
                "name": "SAMSUNG Galaxy S23 5G (Cr...",
                "slug": "samsung-galaxy-s23-5g-cream-128-gb-8-gb-ram",
                "is_saved": false,
                "category": "Mobiles",
                "brand": "Samsung",
                "category_slug": "mobiles",
                "image": "https://singlespace.s3.ap-south-1.amazonaws.com/ss/jR8Q5hcmto1VbAxc7lLpabgIBl1THBpG.webp",
                "price": "₹74,999",
                "total": "₹89,999",
                "offer": "₹15,000 off",
                "delivery": "Free Delivery",
                "attributes": [
                    {
                        "label": "In The Box",
                        "value": "Handset, Sim Ejection Pin, USB Cable, Manual"
                    },
                    {
                        "label": "Operating System",
                        "value": "Android 13"
                    },
                    {
                        "label": "Processor Type",
                        "value": "Qualcomm Snapdragon 8 Gen 2"
                    }
                ],
                "rating": 0,
                "review_count": 0
            }
        ],
        "pagination": 1
    }
}
```

</details>

- `getBySlug(slug)`: Fetches a single product by its slug.

- `getAttributes(slug)`: Fetches the attributes for a single product by its slug.

### `sdk.categoryWiseProducts`

- `list()`: Fetches all categories with their associated products.

### `sdk.categories`

- `list()`: Fetches a list of all categories.

- `getBySlug(slug)`: Fetches the sub-categories for a given category by its slug.

### `sdk.auth`

- `login(params)`: Login with email and password, or mobile.
  - `params.username` (string): The user's email.
  - `params.password` (string): The user's password.
  
- `sendOtp(email)`: Sends an OTP to the user's email for password reset.

- `verifyOtp(token, otp)`: Verifies the OTP for password reset.

- `resetPassword(token, password)`: Resets the user's password.

## License

This SDK is licensed under the ISC License.