@shopi-lk/storefront-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -0
- package/dist/index.d.mts +397 -0
- package/dist/index.d.ts +397 -0
- package/dist/index.js +293 -0
- package/dist/index.mjs +267 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# @shopi-lk/storefront-sdk
|
|
2
|
+
|
|
3
|
+
Official Shopi.lk Storefront SDK for building custom storefronts across all business types — **Shop**, **Listing**, **Rental**, and **Service**.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @shopi-lk/storefront-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Shopi } from '@shopi-lk/storefront-sdk';
|
|
15
|
+
|
|
16
|
+
const shopi = new Shopi({
|
|
17
|
+
apiKey: 'shopi_pk_your_api_key_here',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Get shop info (includes business_type: "shop" | "listing" | "rental" | "service")
|
|
21
|
+
const info = await shopi.getShop();
|
|
22
|
+
console.log(info.business_type); // e.g. "shop"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Business Types
|
|
26
|
+
|
|
27
|
+
### Shop (E-Commerce)
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// List products with filtering, sorting & pagination
|
|
31
|
+
const { products, total } = await shopi.products.list({
|
|
32
|
+
category: 'Electronics',
|
|
33
|
+
search: 'phone',
|
|
34
|
+
limit: 12,
|
|
35
|
+
offset: 0,
|
|
36
|
+
sort_by: 'created_at',
|
|
37
|
+
sort_order: 'desc',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Get a single product by slug
|
|
41
|
+
const product = await shopi.products.getBySlug('iphone-15-pro');
|
|
42
|
+
|
|
43
|
+
// Get all categories
|
|
44
|
+
const categories = await shopi.categories.list();
|
|
45
|
+
|
|
46
|
+
// Create an order
|
|
47
|
+
const order = await shopi.checkout.createOrder({
|
|
48
|
+
customer_name: 'John Doe',
|
|
49
|
+
customer_email: 'john@example.com',
|
|
50
|
+
items: [
|
|
51
|
+
{ product_id: 'uuid-here', name: 'iPhone 15 Pro', price: 450000, quantity: 1 },
|
|
52
|
+
],
|
|
53
|
+
payment_method: 'cod',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Validate a promo code
|
|
57
|
+
const promo = await shopi.checkout.validatePromo({
|
|
58
|
+
code: 'SAVE10',
|
|
59
|
+
subtotal: 450000,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Listing (Showcase / Lead Generation)
|
|
64
|
+
|
|
65
|
+
For businesses like jewelry, vehicles, or gems — no cart/checkout, focused on inquiries.
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
// List all visible listings
|
|
69
|
+
const { listings, total } = await shopi.listings.list({
|
|
70
|
+
category: 'Rings',
|
|
71
|
+
search: 'diamond',
|
|
72
|
+
limit: 20,
|
|
73
|
+
sort_by: 'views_count',
|
|
74
|
+
sort_order: 'desc',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Get a single listing by slug
|
|
78
|
+
const listing = await shopi.listings.getBySlug('diamond-engagement-ring');
|
|
79
|
+
console.log(listing.price); // e.g. 125000
|
|
80
|
+
console.log(listing.availability_status); // e.g. "available"
|
|
81
|
+
console.log(listing.features); // e.g. ["18K Gold", "0.5ct Diamond"]
|
|
82
|
+
console.log(listing.contact_info); // e.g. { phone: "+94...", whatsapp: "..." }
|
|
83
|
+
console.log(listing.views_count); // e.g. 342
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Rental (Vehicle / Equipment Rental)
|
|
87
|
+
|
|
88
|
+
For businesses that rent items with availability tracking.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// List rental items
|
|
92
|
+
const { rental_items, total } = await shopi.rentalItems.list({
|
|
93
|
+
category: 'SUV',
|
|
94
|
+
limit: 10,
|
|
95
|
+
sort_by: 'daily_rate',
|
|
96
|
+
sort_order: 'asc',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Get a single rental item by slug
|
|
100
|
+
const item = await shopi.rentalItems.getBySlug('toyota-land-cruiser');
|
|
101
|
+
console.log(item.daily_rate); // e.g. 15000
|
|
102
|
+
console.log(item.weekly_rate); // e.g. 90000
|
|
103
|
+
console.log(item.available_quantity); // e.g. 3
|
|
104
|
+
console.log(item.deposit_required); // e.g. true
|
|
105
|
+
console.log(item.deposit_amount); // e.g. 50000
|
|
106
|
+
console.log(item.pickup_available); // e.g. true
|
|
107
|
+
console.log(item.delivery_available); // e.g. true
|
|
108
|
+
console.log(item.delivery_fee); // e.g. 2500
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Service (Appointments / Bookings)
|
|
112
|
+
|
|
113
|
+
For businesses offering appointments like salons, mehendi artists, or consultants.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// List services
|
|
117
|
+
const { services, total } = await shopi.services.list({
|
|
118
|
+
category: 'Bridal',
|
|
119
|
+
limit: 10,
|
|
120
|
+
sort_by: 'price',
|
|
121
|
+
sort_order: 'asc',
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Get a single service by slug
|
|
125
|
+
const service = await shopi.services.getBySlug('bridal-mehendi-package');
|
|
126
|
+
console.log(service.price); // e.g. 25000
|
|
127
|
+
console.log(service.duration_minutes); // e.g. 120
|
|
128
|
+
console.log(service.deposit_required); // e.g. true
|
|
129
|
+
console.log(service.deposit_amount); // e.g. 5000
|
|
130
|
+
console.log(service.max_bookings_per_slot); // e.g. 1
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Common APIs (All Business Types)
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// Store settings (name, logo, shipping, social links)
|
|
137
|
+
const settings = await shopi.getStoreSettings();
|
|
138
|
+
|
|
139
|
+
// Theme settings (colors, fonts, section layout)
|
|
140
|
+
const theme = await shopi.getThemeSettings();
|
|
141
|
+
|
|
142
|
+
// Payment methods & bank details
|
|
143
|
+
const { payment_methods, bank_details } = await shopi.getPaymentMethods();
|
|
144
|
+
|
|
145
|
+
// CMS pages
|
|
146
|
+
const pages = await shopi.pages.list();
|
|
147
|
+
const page = await shopi.pages.getBySlug('about-us');
|
|
148
|
+
|
|
149
|
+
// Blog posts
|
|
150
|
+
const { posts } = await shopi.blog.list({ limit: 5 });
|
|
151
|
+
const post = await shopi.blog.getBySlug('welcome-to-our-store');
|
|
152
|
+
|
|
153
|
+
// Product reviews (works for products)
|
|
154
|
+
const reviews = await shopi.reviews.list('product-uuid');
|
|
155
|
+
await shopi.reviews.submit({
|
|
156
|
+
product_id: 'product-uuid',
|
|
157
|
+
rating: 5,
|
|
158
|
+
review_text: 'Amazing quality!',
|
|
159
|
+
customer_name: 'Jane',
|
|
160
|
+
customer_email: 'jane@example.com',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Active discounts
|
|
164
|
+
const { shop_wide, product_specific } = await shopi.getDiscounts();
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## API Reference
|
|
168
|
+
|
|
169
|
+
### `new Shopi(config)`
|
|
170
|
+
|
|
171
|
+
| Param | Type | Required | Description |
|
|
172
|
+
|-------|------|----------|-------------|
|
|
173
|
+
| `apiKey` | `string` | ✅ | Your Storefront API key (must start with `shopi_pk_`) |
|
|
174
|
+
| `baseUrl` | `string` | ❌ | Override API URL (default: `https://apicall.shopi.lk/v1`) |
|
|
175
|
+
| `timeoutMs` | `number` | ❌ | Request timeout in ms (default: `10000`) |
|
|
176
|
+
|
|
177
|
+
### Methods
|
|
178
|
+
|
|
179
|
+
| Method | Scope | Description |
|
|
180
|
+
|--------|-------|-------------|
|
|
181
|
+
| `getShop()` | `shop:read` | Shop info (name, domain, business_type, theme) |
|
|
182
|
+
| `products.list(params?)` | `products:read` | List products with filters & pagination |
|
|
183
|
+
| `products.getBySlug(slug)` | `products:read` | Single product by slug |
|
|
184
|
+
| `categories.list()` | `products:read` | All product categories |
|
|
185
|
+
| `listings.list(params?)` | `listings:read` | List listings with filters & pagination |
|
|
186
|
+
| `listings.getBySlug(slug)` | `listings:read` | Single listing by slug |
|
|
187
|
+
| `rentalItems.list(params?)` | `rentals:read` | List rental items with filters & pagination |
|
|
188
|
+
| `rentalItems.getBySlug(slug)` | `rentals:read` | Single rental item by slug |
|
|
189
|
+
| `services.list(params?)` | `services:read` | List services with filters & pagination |
|
|
190
|
+
| `services.getBySlug(slug)` | `services:read` | Single service by slug |
|
|
191
|
+
| `getStoreSettings()` | `shop:read` | Store config (logo, shipping, social) |
|
|
192
|
+
| `getPaymentMethods()` | `shop:read` | Payment methods + bank details |
|
|
193
|
+
| `pages.list()` | `content:read` | CMS pages |
|
|
194
|
+
| `pages.getBySlug(slug)` | `content:read` | Single CMS page |
|
|
195
|
+
| `blog.list(params?)` | `content:read` | Blog posts (paginated) |
|
|
196
|
+
| `blog.getBySlug(slug)` | `content:read` | Single blog post |
|
|
197
|
+
| `reviews.list(productId)` | `products:read` | Product reviews |
|
|
198
|
+
| `reviews.submit(params)` | `checkout:write` | Submit a review |
|
|
199
|
+
| `getDiscounts()` | `products:read` | Active discounts |
|
|
200
|
+
| `getThemeSettings()` | `shop:read` | Theme colors, fonts, sections |
|
|
201
|
+
| `checkout.createOrder(params)` | `checkout:write` | Place an order |
|
|
202
|
+
| `checkout.validatePromo(params)` | `checkout:write` | Validate promo code |
|
|
203
|
+
|
|
204
|
+
### List Parameters
|
|
205
|
+
|
|
206
|
+
All `.list()` methods accept these common parameters:
|
|
207
|
+
|
|
208
|
+
| Param | Type | Default | Description |
|
|
209
|
+
|-------|------|---------|-------------|
|
|
210
|
+
| `category` | `string` | — | Filter by category name |
|
|
211
|
+
| `search` | `string` | — | Search by name (case-insensitive) |
|
|
212
|
+
| `limit` | `number` | `50` | Results per page (max 100) |
|
|
213
|
+
| `offset` | `number` | `0` | Pagination offset |
|
|
214
|
+
| `sort_by` | `string` | varies | Sort field (see type definitions for allowed values) |
|
|
215
|
+
| `sort_order` | `"asc" \| "desc"` | `"desc"` | Sort direction |
|
|
216
|
+
|
|
217
|
+
### Rate Limiting
|
|
218
|
+
|
|
219
|
+
After every request, the current rate-limit state is available:
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
const { products } = await shopi.products.list();
|
|
223
|
+
console.log(shopi.rateLimit);
|
|
224
|
+
// { limit: 60, remaining: 58, reset: 1720000000 }
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Error Handling
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import { Shopi, ShopiError } from '@shopi-lk/storefront-sdk';
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
const listings = await shopi.listings.list();
|
|
234
|
+
} catch (error) {
|
|
235
|
+
if (error instanceof ShopiError) {
|
|
236
|
+
console.error(error.message, error.status);
|
|
237
|
+
// error.status === 401 → invalid API key
|
|
238
|
+
// error.status === 403 → insufficient scope
|
|
239
|
+
// error.status === 404 → resource not found
|
|
240
|
+
// error.status === 408 → request timed out
|
|
241
|
+
// error.status === 429 → rate limit exceeded
|
|
242
|
+
// error.status === 0 → network error (offline, DNS failure)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Reliability
|
|
248
|
+
|
|
249
|
+
- **Automatic retries** — transient `5xx` and `429` responses are retried up to 2 times with exponential backoff (300ms, 600ms). For `429`, the SDK honours the `Retry-After` header.
|
|
250
|
+
- **Request timeouts** — every request is cancelled after 10s by default. Override with `timeoutMs`.
|
|
251
|
+
- **Safe JSON parsing** — non-JSON server responses (e.g. HTML gateway errors) throw a typed `ShopiError` instead of a raw `SyntaxError`.
|
|
252
|
+
- **Rate-limit awareness** — inspect `shopi.rateLimit` after any call to monitor your quota.
|
|
253
|
+
|
|
254
|
+
## Scopes
|
|
255
|
+
|
|
256
|
+
API keys can be scoped to limit access. Use `*` for full access or combine specific scopes:
|
|
257
|
+
|
|
258
|
+
| Scope | Access |
|
|
259
|
+
|-------|--------|
|
|
260
|
+
| `*` | Full access (all endpoints) |
|
|
261
|
+
| `shop:read` | Shop info, store settings, payment methods, theme |
|
|
262
|
+
| `products:read` | Products, categories, reviews, discounts |
|
|
263
|
+
| `listings:read` | Listings |
|
|
264
|
+
| `rentals:read` | Rental items |
|
|
265
|
+
| `services:read` | Services |
|
|
266
|
+
| `content:read` | Pages, blog posts |
|
|
267
|
+
| `checkout:write` | Orders, promo validation, review submission |
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
interface ShopiConfig {
|
|
2
|
+
/** Your Storefront API key (must start with shopi_pk_) */
|
|
3
|
+
apiKey: string;
|
|
4
|
+
/** Override the API base URL (default: https://apicall.shopi.lk/v1) */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Request timeout in milliseconds (default: 10000) */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
}
|
|
9
|
+
interface Shop {
|
|
10
|
+
id: string;
|
|
11
|
+
shop_name: string;
|
|
12
|
+
subdomain: string;
|
|
13
|
+
custom_domain: string | null;
|
|
14
|
+
primary_domain: string | null;
|
|
15
|
+
business_type: string | null;
|
|
16
|
+
is_active: boolean;
|
|
17
|
+
active_theme: number | null;
|
|
18
|
+
}
|
|
19
|
+
interface Product {
|
|
20
|
+
id: string;
|
|
21
|
+
shop_id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
slug: string;
|
|
24
|
+
description: string | null;
|
|
25
|
+
price: number;
|
|
26
|
+
compare_at_price: number | null;
|
|
27
|
+
category: string | null;
|
|
28
|
+
images: string[];
|
|
29
|
+
is_visible: boolean;
|
|
30
|
+
stock_quantity: number | null;
|
|
31
|
+
track_inventory: boolean;
|
|
32
|
+
sku: string | null;
|
|
33
|
+
weight: number | null;
|
|
34
|
+
variants: ProductVariant[] | null;
|
|
35
|
+
created_at: string;
|
|
36
|
+
updated_at: string;
|
|
37
|
+
}
|
|
38
|
+
interface ProductVariant {
|
|
39
|
+
name: string;
|
|
40
|
+
options: string[];
|
|
41
|
+
prices?: Record<string, number>;
|
|
42
|
+
}
|
|
43
|
+
interface ProductListParams {
|
|
44
|
+
category?: string;
|
|
45
|
+
search?: string;
|
|
46
|
+
limit?: number;
|
|
47
|
+
offset?: number;
|
|
48
|
+
sort_by?: "created_at" | "name" | "price" | "sales" | "updated_at";
|
|
49
|
+
sort_order?: "asc" | "desc";
|
|
50
|
+
}
|
|
51
|
+
interface ProductListResponse {
|
|
52
|
+
products: Product[];
|
|
53
|
+
total: number;
|
|
54
|
+
limit: number;
|
|
55
|
+
offset: number;
|
|
56
|
+
}
|
|
57
|
+
interface Category {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
image_url: string | null;
|
|
61
|
+
}
|
|
62
|
+
interface Listing {
|
|
63
|
+
id: string;
|
|
64
|
+
shop_id?: string;
|
|
65
|
+
name: string;
|
|
66
|
+
slug: string | null;
|
|
67
|
+
description: string | null;
|
|
68
|
+
price: number | null;
|
|
69
|
+
price_label: string | null;
|
|
70
|
+
currency: string | null;
|
|
71
|
+
category: string | null;
|
|
72
|
+
condition: string | null;
|
|
73
|
+
location: string | null;
|
|
74
|
+
images: string[] | null;
|
|
75
|
+
video: string | null;
|
|
76
|
+
features: string[] | null;
|
|
77
|
+
specifications: Record<string, any> | null;
|
|
78
|
+
contact_info: Record<string, any> | null;
|
|
79
|
+
availability_status: string | null;
|
|
80
|
+
is_featured: boolean | null;
|
|
81
|
+
views_count: number | null;
|
|
82
|
+
inquiries_count: number | null;
|
|
83
|
+
sort_order: number | null;
|
|
84
|
+
created_at: string;
|
|
85
|
+
updated_at: string;
|
|
86
|
+
}
|
|
87
|
+
interface ListingListParams {
|
|
88
|
+
category?: string;
|
|
89
|
+
search?: string;
|
|
90
|
+
limit?: number;
|
|
91
|
+
offset?: number;
|
|
92
|
+
sort_by?: "created_at" | "name" | "price" | "views_count" | "updated_at" | "sort_order";
|
|
93
|
+
sort_order?: "asc" | "desc";
|
|
94
|
+
}
|
|
95
|
+
interface ListingListResponse {
|
|
96
|
+
listings: Listing[];
|
|
97
|
+
total: number;
|
|
98
|
+
limit: number;
|
|
99
|
+
offset: number;
|
|
100
|
+
}
|
|
101
|
+
interface RentalItem {
|
|
102
|
+
id: string;
|
|
103
|
+
shop_id?: string;
|
|
104
|
+
name: string;
|
|
105
|
+
slug: string | null;
|
|
106
|
+
description: string | null;
|
|
107
|
+
category: string | null;
|
|
108
|
+
condition: string | null;
|
|
109
|
+
location: string | null;
|
|
110
|
+
images: string[] | null;
|
|
111
|
+
video: string | null;
|
|
112
|
+
specifications: Record<string, any> | null;
|
|
113
|
+
currency: string | null;
|
|
114
|
+
hourly_rate: number | null;
|
|
115
|
+
daily_rate: number | null;
|
|
116
|
+
weekly_rate: number | null;
|
|
117
|
+
monthly_rate: number | null;
|
|
118
|
+
deposit_required: boolean | null;
|
|
119
|
+
deposit_amount: number | null;
|
|
120
|
+
min_rental_duration_hours: number | null;
|
|
121
|
+
max_rental_duration_days: number | null;
|
|
122
|
+
total_quantity: number | null;
|
|
123
|
+
available_quantity: number | null;
|
|
124
|
+
pickup_available: boolean | null;
|
|
125
|
+
delivery_available: boolean | null;
|
|
126
|
+
delivery_fee: number | null;
|
|
127
|
+
is_featured: boolean | null;
|
|
128
|
+
sort_order: number | null;
|
|
129
|
+
created_at: string;
|
|
130
|
+
updated_at: string;
|
|
131
|
+
}
|
|
132
|
+
interface RentalItemListParams {
|
|
133
|
+
category?: string;
|
|
134
|
+
search?: string;
|
|
135
|
+
limit?: number;
|
|
136
|
+
offset?: number;
|
|
137
|
+
sort_by?: "created_at" | "name" | "daily_rate" | "updated_at" | "sort_order";
|
|
138
|
+
sort_order?: "asc" | "desc";
|
|
139
|
+
}
|
|
140
|
+
interface RentalItemListResponse {
|
|
141
|
+
rental_items: RentalItem[];
|
|
142
|
+
total: number;
|
|
143
|
+
limit: number;
|
|
144
|
+
offset: number;
|
|
145
|
+
}
|
|
146
|
+
interface Service {
|
|
147
|
+
id: string;
|
|
148
|
+
shop_id?: string;
|
|
149
|
+
name: string;
|
|
150
|
+
slug: string | null;
|
|
151
|
+
description: string | null;
|
|
152
|
+
price: number;
|
|
153
|
+
currency: string | null;
|
|
154
|
+
category: string | null;
|
|
155
|
+
duration_minutes: number;
|
|
156
|
+
images: string[] | null;
|
|
157
|
+
deposit_required: boolean | null;
|
|
158
|
+
deposit_amount: number | null;
|
|
159
|
+
max_bookings_per_slot: number | null;
|
|
160
|
+
buffer_before_minutes: number | null;
|
|
161
|
+
buffer_after_minutes: number | null;
|
|
162
|
+
sort_order: number | null;
|
|
163
|
+
created_at: string;
|
|
164
|
+
updated_at: string;
|
|
165
|
+
}
|
|
166
|
+
interface ServiceListParams {
|
|
167
|
+
category?: string;
|
|
168
|
+
search?: string;
|
|
169
|
+
limit?: number;
|
|
170
|
+
offset?: number;
|
|
171
|
+
sort_by?: "created_at" | "name" | "price" | "sort_order" | "updated_at";
|
|
172
|
+
sort_order?: "asc" | "desc";
|
|
173
|
+
}
|
|
174
|
+
interface ServiceListResponse {
|
|
175
|
+
services: Service[];
|
|
176
|
+
total: number;
|
|
177
|
+
limit: number;
|
|
178
|
+
offset: number;
|
|
179
|
+
}
|
|
180
|
+
interface StoreSettings {
|
|
181
|
+
shop_name: string;
|
|
182
|
+
tagline: string | null;
|
|
183
|
+
logo_url: string | null;
|
|
184
|
+
phone_number: string | null;
|
|
185
|
+
email: string | null;
|
|
186
|
+
address: string | null;
|
|
187
|
+
footer_text: string | null;
|
|
188
|
+
meta_title: string | null;
|
|
189
|
+
meta_description: string | null;
|
|
190
|
+
keywords: string | null;
|
|
191
|
+
business_category: string | null;
|
|
192
|
+
business_hours: any;
|
|
193
|
+
location_city: string | null;
|
|
194
|
+
location_country: string | null;
|
|
195
|
+
social_links: Record<string, string> | null;
|
|
196
|
+
shipping_regions: any;
|
|
197
|
+
is_free_shipping: boolean | null;
|
|
198
|
+
free_shipping_enabled: boolean | null;
|
|
199
|
+
free_shipping_threshold: number | null;
|
|
200
|
+
shipping_currency: string | null;
|
|
201
|
+
shipping_config: any;
|
|
202
|
+
international_shipping: any;
|
|
203
|
+
}
|
|
204
|
+
interface PaymentMethod {
|
|
205
|
+
method_id: string;
|
|
206
|
+
method_name: string;
|
|
207
|
+
enabled: boolean;
|
|
208
|
+
}
|
|
209
|
+
interface BankDetail {
|
|
210
|
+
bank_name: string;
|
|
211
|
+
branch_name: string | null;
|
|
212
|
+
account_number: string;
|
|
213
|
+
account_holder_name: string;
|
|
214
|
+
}
|
|
215
|
+
interface Page {
|
|
216
|
+
id: string;
|
|
217
|
+
title: string;
|
|
218
|
+
slug: string;
|
|
219
|
+
content: string | null;
|
|
220
|
+
is_visible: boolean;
|
|
221
|
+
sort_order: number | null;
|
|
222
|
+
meta_title: string | null;
|
|
223
|
+
meta_description: string | null;
|
|
224
|
+
rendered_html: string | null;
|
|
225
|
+
rendered_css: string | null;
|
|
226
|
+
}
|
|
227
|
+
interface BlogPost {
|
|
228
|
+
id: string;
|
|
229
|
+
title: string;
|
|
230
|
+
slug: string;
|
|
231
|
+
content?: string;
|
|
232
|
+
excerpt: string | null;
|
|
233
|
+
featured_image: string | null;
|
|
234
|
+
author_name: string | null;
|
|
235
|
+
published_at: string | null;
|
|
236
|
+
tags: string[] | null;
|
|
237
|
+
meta_title: string | null;
|
|
238
|
+
meta_description: string | null;
|
|
239
|
+
rendered_html?: string | null;
|
|
240
|
+
rendered_css?: string | null;
|
|
241
|
+
}
|
|
242
|
+
interface BlogListParams {
|
|
243
|
+
limit?: number;
|
|
244
|
+
offset?: number;
|
|
245
|
+
}
|
|
246
|
+
interface Review {
|
|
247
|
+
id: string;
|
|
248
|
+
product_id: string;
|
|
249
|
+
rating: number;
|
|
250
|
+
review_text: string | null;
|
|
251
|
+
image_url: string | null;
|
|
252
|
+
is_verified_purchase: boolean;
|
|
253
|
+
created_at: string;
|
|
254
|
+
}
|
|
255
|
+
interface Discount {
|
|
256
|
+
id: string;
|
|
257
|
+
name: string;
|
|
258
|
+
discount_percentage: number;
|
|
259
|
+
applies_to: string;
|
|
260
|
+
product_id: string | null;
|
|
261
|
+
start_date: string;
|
|
262
|
+
end_date: string;
|
|
263
|
+
}
|
|
264
|
+
interface ThemeSettings {
|
|
265
|
+
theme_id: number;
|
|
266
|
+
settings: Record<string, any>;
|
|
267
|
+
is_published: boolean;
|
|
268
|
+
}
|
|
269
|
+
interface CartItem {
|
|
270
|
+
product_id: string;
|
|
271
|
+
name: string;
|
|
272
|
+
price: number;
|
|
273
|
+
quantity: number;
|
|
274
|
+
image?: string;
|
|
275
|
+
variant?: string;
|
|
276
|
+
}
|
|
277
|
+
interface CreateOrderParams {
|
|
278
|
+
customer_name: string;
|
|
279
|
+
customer_email: string;
|
|
280
|
+
customer_phone?: string;
|
|
281
|
+
items: CartItem[];
|
|
282
|
+
shipping_address?: Record<string, any>;
|
|
283
|
+
shipping_method?: string;
|
|
284
|
+
payment_method?: string;
|
|
285
|
+
notes?: string;
|
|
286
|
+
promo_code_id?: string;
|
|
287
|
+
discount_amount?: number;
|
|
288
|
+
}
|
|
289
|
+
interface Order {
|
|
290
|
+
id: string;
|
|
291
|
+
order_number: string;
|
|
292
|
+
total: number;
|
|
293
|
+
status: string;
|
|
294
|
+
created_at: string;
|
|
295
|
+
}
|
|
296
|
+
interface PromoValidateParams {
|
|
297
|
+
code: string;
|
|
298
|
+
cart_items?: CartItem[];
|
|
299
|
+
subtotal?: number;
|
|
300
|
+
}
|
|
301
|
+
interface PromoValidateResult {
|
|
302
|
+
valid: boolean;
|
|
303
|
+
error?: string;
|
|
304
|
+
promo_code?: {
|
|
305
|
+
id: string;
|
|
306
|
+
code: string;
|
|
307
|
+
discount_type: string;
|
|
308
|
+
discount_value: number;
|
|
309
|
+
applies_to: string;
|
|
310
|
+
};
|
|
311
|
+
discount_amount?: number;
|
|
312
|
+
message?: string;
|
|
313
|
+
}
|
|
314
|
+
interface SubmitReviewParams {
|
|
315
|
+
product_id: string;
|
|
316
|
+
rating: number;
|
|
317
|
+
review_text?: string;
|
|
318
|
+
customer_name?: string;
|
|
319
|
+
customer_email?: string;
|
|
320
|
+
image_url?: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface RateLimitState {
|
|
324
|
+
/** Maximum requests allowed per window */
|
|
325
|
+
limit: number;
|
|
326
|
+
/** Requests remaining in the current window */
|
|
327
|
+
remaining: number;
|
|
328
|
+
/** Unix timestamp (seconds) when the window resets */
|
|
329
|
+
reset: number;
|
|
330
|
+
}
|
|
331
|
+
declare class Shopi {
|
|
332
|
+
private apiKey;
|
|
333
|
+
private baseUrl;
|
|
334
|
+
private timeoutMs;
|
|
335
|
+
/** Populated after every request — reflects the current rate-limit window. */
|
|
336
|
+
rateLimit: RateLimitState | null;
|
|
337
|
+
constructor(config: ShopiConfig);
|
|
338
|
+
private request;
|
|
339
|
+
getShop(): Promise<Shop>;
|
|
340
|
+
products: {
|
|
341
|
+
list: (params?: ProductListParams) => Promise<ProductListResponse>;
|
|
342
|
+
getBySlug: (slug: string) => Promise<Product>;
|
|
343
|
+
};
|
|
344
|
+
categories: {
|
|
345
|
+
list: () => Promise<Category[]>;
|
|
346
|
+
};
|
|
347
|
+
listings: {
|
|
348
|
+
list: (params?: ListingListParams) => Promise<ListingListResponse>;
|
|
349
|
+
getBySlug: (slug: string) => Promise<Listing>;
|
|
350
|
+
};
|
|
351
|
+
rentalItems: {
|
|
352
|
+
list: (params?: RentalItemListParams) => Promise<RentalItemListResponse>;
|
|
353
|
+
getBySlug: (slug: string) => Promise<RentalItem>;
|
|
354
|
+
};
|
|
355
|
+
services: {
|
|
356
|
+
list: (params?: ServiceListParams) => Promise<ServiceListResponse>;
|
|
357
|
+
getBySlug: (slug: string) => Promise<Service>;
|
|
358
|
+
};
|
|
359
|
+
getStoreSettings(): Promise<StoreSettings>;
|
|
360
|
+
getPaymentMethods(): Promise<{
|
|
361
|
+
payment_methods: PaymentMethod[];
|
|
362
|
+
bank_details: BankDetail[];
|
|
363
|
+
}>;
|
|
364
|
+
pages: {
|
|
365
|
+
list: () => Promise<Page[]>;
|
|
366
|
+
getBySlug: (slug: string) => Promise<Page>;
|
|
367
|
+
};
|
|
368
|
+
blog: {
|
|
369
|
+
list: (params?: BlogListParams) => Promise<{
|
|
370
|
+
posts: BlogPost[];
|
|
371
|
+
total: number;
|
|
372
|
+
}>;
|
|
373
|
+
getBySlug: (slug: string) => Promise<BlogPost>;
|
|
374
|
+
};
|
|
375
|
+
reviews: {
|
|
376
|
+
list: (productId: string, limit?: number) => Promise<Review[]>;
|
|
377
|
+
submit: (params: SubmitReviewParams) => Promise<{
|
|
378
|
+
id: string;
|
|
379
|
+
}>;
|
|
380
|
+
};
|
|
381
|
+
getDiscounts(): Promise<{
|
|
382
|
+
shop_wide: Discount[];
|
|
383
|
+
product_specific: Discount[];
|
|
384
|
+
}>;
|
|
385
|
+
getThemeSettings(): Promise<ThemeSettings | null>;
|
|
386
|
+
checkout: {
|
|
387
|
+
createOrder: (params: CreateOrderParams) => Promise<Order>;
|
|
388
|
+
validatePromo: (params: PromoValidateParams) => Promise<PromoValidateResult>;
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
declare class ShopiError extends Error {
|
|
392
|
+
status: number;
|
|
393
|
+
data: unknown;
|
|
394
|
+
constructor(message: string, status: number, data?: unknown);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export { type BankDetail, type BlogListParams, type BlogPost, type CartItem, type Category, type CreateOrderParams, type Discount, type Listing, type ListingListParams, type ListingListResponse, type Order, type Page, type PaymentMethod, type Product, type ProductListParams, type ProductListResponse, type ProductVariant, type PromoValidateParams, type PromoValidateResult, type RateLimitState, type RentalItem, type RentalItemListParams, type RentalItemListResponse, type Review, type Service, type ServiceListParams, type ServiceListResponse, type Shop, Shopi, type ShopiConfig, ShopiError, type StoreSettings, type SubmitReviewParams, type ThemeSettings };
|