@ecommaps/client 1.1.0 โ 1.2.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 +134 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# @ecommaps/client
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@ecommaps/client)
|
|
4
|
+
[](https://opensource.org/licenses/ISC)
|
|
5
|
+
|
|
6
|
+
The official, high-performance JavaScript/TypeScript SDK for building custom, headless storefronts on the **Ecommaps** ecosystem. Designed for developers and AI agents to build, scale, and manage modern commerce experiences with ease.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ๐ Quick Start
|
|
11
|
+
|
|
12
|
+
### Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @ecommaps/client
|
|
16
|
+
# or
|
|
17
|
+
pnpm add @ecommaps/client
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Configuration
|
|
21
|
+
|
|
22
|
+
The client automatically reads from environment variables but can also be configured per request.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { ecommapsClient } from "@ecommaps/client";
|
|
26
|
+
|
|
27
|
+
// Set these in your .env
|
|
28
|
+
// NEXT_PUBLIC_ECOMMAPS_API_URL=http://localhost:8001/api/v1/storefront
|
|
29
|
+
// ECOMMAPS_API_KEY=your_store_key
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## ๐ Features & Examples
|
|
35
|
+
|
|
36
|
+
### ๐ Authentication & Customer Profile
|
|
37
|
+
Handle customer sessions using industry-standard JWT.
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// Login
|
|
41
|
+
const { token, user } = await ecommapsClient.auth.login({
|
|
42
|
+
email: "customer@example.com",
|
|
43
|
+
password: "secure_password"
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Get Current User Profile (Authenticated)
|
|
47
|
+
const { customer } = await ecommapsClient.auth.me({
|
|
48
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Add Address to Customer Profile
|
|
52
|
+
await ecommapsClient.auth.addAddress({
|
|
53
|
+
line1: "123 Main St",
|
|
54
|
+
city: "Algiers",
|
|
55
|
+
state: "16",
|
|
56
|
+
country: "DZ",
|
|
57
|
+
postal_code: "16000",
|
|
58
|
+
phone: "0555000000",
|
|
59
|
+
label: "Home"
|
|
60
|
+
}, {
|
|
61
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### ๐ฆ Products & Collections
|
|
66
|
+
Retrieve catalog data with built-in pagination.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// List Products
|
|
70
|
+
const products = await ecommapsClient.products.list({ limit: 10, offset: 0 });
|
|
71
|
+
|
|
72
|
+
// Retrieve Single Product by Slug
|
|
73
|
+
const product = await ecommapsClient.products.retrieve("summer-t-shirt");
|
|
74
|
+
|
|
75
|
+
// List Collections
|
|
76
|
+
const { data: collections } = await ecommapsClient.collections.list();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### ๐ Cart Management
|
|
80
|
+
Highly flexible cart APIs optimized for sub-second performance.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// Create a new Cart
|
|
84
|
+
const cart = await ecommapsClient.cart.create();
|
|
85
|
+
|
|
86
|
+
// Add Item
|
|
87
|
+
await ecommapsClient.cart.addItem(cart.id, {
|
|
88
|
+
product_id: "prod_123",
|
|
89
|
+
quantity: 2
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Retrieve Cart
|
|
93
|
+
const currentCart = await ecommapsClient.cart.retrieve(cart.id);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### ๐งพ Orders
|
|
97
|
+
Seamless order management from creation to tracking.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// List Customer Orders (Authenticated)
|
|
101
|
+
const { data: orders } = await ecommapsClient.orders.list({
|
|
102
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
103
|
+
params: { limit: 5 }
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Retrieve Order Details
|
|
107
|
+
const order = await ecommapsClient.orders.retrieve("ECORD-2024-XXXX");
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## ๐ค AI Agent Integration (Skills)
|
|
113
|
+
|
|
114
|
+
This SDK is **Agent-Ready**. If you are an AI agent building for a user, follow these conventions:
|
|
115
|
+
|
|
116
|
+
1. **Mapping**: Always map the backend JSON structure to the UI components (e.g., Use `line1` for `address_1`, `name` for `title`).
|
|
117
|
+
2. **Context**: Use `ecommapsClient.auth.me` to verify user status before attempting protected operations.
|
|
118
|
+
3. **Optimistic UI**: Use the returned data from cart/order operations to update local state immediately.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## ๐ Developing the Storefront
|
|
123
|
+
|
|
124
|
+
To build a complete store:
|
|
125
|
+
1. Initialize a Next.js 14+ project.
|
|
126
|
+
2. Install `@ecommaps/client`.
|
|
127
|
+
3. Use Next.js **Server Actions** to wrap SDK calls (see `auth` and `cart`).
|
|
128
|
+
4. Implement **Dynamic Routing** (`/[slug]`) using `products.retrieve`.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## ๐ License
|
|
133
|
+
|
|
134
|
+
Distributed under the ISC License. ยฉ 2026 EcoBaseAI.
|