genuka-api
Version:
Javascript(TS) Package to use Genuka API for a StoreFront website
246 lines (175 loc) • 5.09 kB
Markdown
# Genuka JS SDK
The Genuka JavaScript SDK allows developers to easily integrate the features of the Genuka platform into their web applications. This SDK provides methods to manage companies, shops, products, pages, blogs, articles, collections, customers, addresses, orders, carts, and payment methods.
## Installation
```bash
npm install genuka
```
or
```bash
yarn add genuka
```
## Usage
To start using the SDK, you must first import it into your project and initialize it with your company information.
```javascript
import genuka from "genuka";
// Initialize the instance with your company's domain
genuka.initialize({ domain: "your.domain.com" });
```
### Company
#### Initialization
Initialize your company information before using the SDK.
```javascript
await genuka.initialize({ domain: "domain_or_subdomain.genuka.com" });
```
#### Retrieving Company Details
To retrieve your company details:
```javascript
const company = await genuka.company.retrieve();
```
### Shops
#### Listing Shops
List all available shops:
```javascript
const shops = await genuka.shops.list();
```
#### Shop Details
To retrieve the details of a specific shop by its ID:
```javascript
const shop = await genuka.shops.retrieve({ id: "01hhfzx7ftzrqjxhx8fbb6ddfs" });
```
### Products
#### Counting Products
To count all available products:
```javascript
const productsCount = await genuka.products.count();
```
#### Listing Products
List all products:
```javascript
const products = await genuka.products.list();
```
#### Product Details
To retrieve the details of a specific product by its ID:
```javascript
const product = await genuka.products.retrieve({
id: "01hkav9sz3qsj4tfdn3yd7214p",
});
```
### Customers
#### Logging in a Customer
To log in a customer:
```javascript
const { token, customer } = await genuka.customers.login({
email: "customer@email.com",
password: "password",
});
Genuka.setToken(token);
```
#### Retrieving Customer Details
To retrieve the details of the current customer:
```javascript
const customerDetails = await genuka.customers.retrieve();
```
Sure, here are detailed sections of the documentation for the `orders` and `carts` parts of your Genuka package.
---
### Orders
#### List All Orders for a Customer
To list all orders for a customer, you must first log in the customer and then use the `list` method:
```javascript
// Log in the customer
const { token } = await genuka.customers.login({
email: "customer2@email.com",
password: "password",
});
genuka.setToken(token);
// List all orders for the customer
const orders = await genuka.orders.list();
```
#### Create an Order
To create a new order, use the `create` method. You must provide details about the customer, shipping, billing, and products included in the order:
```javascript
const order = await genuka.orders.create({
customer: {
first_name: "John",
last_name: "Doe",
phone: "123456789",
email: "customer@email.com",
},
shipping: {
mode: "delivery",
amount: 0,
address: {
first_name: "John",
last_name: "Doe",
phone: "123456789",
line1: "line1",
line2: "line2",
city: "city",
state: "state",
postal_code: "postal_code",
country: "country",
},
},
billing: {
method: "cash",
address: {
first_name: "John",
last_name: "Doe",
phone: "123456789",
line1: "line1",
line2: "line2",
city: "city",
state: "state",
postal_code: "postal_code",
country: "country",
},
},
products: [
{
title: "My product here",
price: 2000,
quantity: 1,
},
],
});
```
(Note: Add more details and available configurations as needed for your API.)
### Carts
#### Add to Cart
To add a product to the cart, use the `add` method by providing the necessary details:
```javascript
genuka.cart.add({
product_id: "product_id",
variant_id: "variant_id",
quantity: 1,
price: 2000,
});
```
#### Retrieve Cart
To retrieve the current contents of the cart:
```javascript
const cart = genuka.cart.retrieve();
```
#### Update Cart Item
To update the quantity of a specific item in the cart:
```javascript
genuka.cart.update("variant_id", {
quantity: 2,
});
const updatedCart = genuka.cart.retrieve();
```
#### Remove from Cart
To remove an item from the cart:
```javascript
genuka.cart.remove("variant_id");
const cartAfterRemoval = genuka.cart.retrieve();
```
#### Clear Cart
To empty the cart:
```javascript
genuka.cart.clear();
const emptyCart = genuka.cart.retrieve();
```
(Note: This is a basic example for the most important sections. You should continue this pattern for all other methods and classes you have defined, such as `pages`, `blogs`, `articles`, `collections`, `addresses`, and `paymentMethods`.)
## Contribution
If you wish to contribute to this SDK, please contact us via Whatsapp (+237 6 95 76 25 95) or send an email to wdjopa@lamater.tech. We welcome contributions in the form of pull requests, bug reports, and suggestions for new features.