epicmerch-mcp 1.3.13 → 1.3.19
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 +450 -204
- package/package.json +1 -1
- package/skills/epicmerch-debug.md +3 -3
- package/skills/epicmerch-merchant.md +78 -46
- package/skills/epicmerch-payments.md +119 -86
- package/skills/epicmerch-setup.md +3 -3
- package/skills/epicmerch-storefront.md +103 -25
- package/skills/epicmerch-verify.md +93 -3
- package/skills/epicmerch.md +69 -115
- package/src/install.js +27 -4
- package/src/lib/onboardingState.js +159 -0
- package/src/prompts/index.js +4 -97
- package/src/resources/examples/products.md +72 -22
- package/src/tools/_examples.js +12 -0
- package/src/tools/merchant.js +50 -36
- package/src/tools/scaffold.js +74 -20
- package/skills/epicmerch-auth.md +0 -112
- package/skills/epicmerch-e2e.md +0 -203
- package/skills/epicmerch-merchant-agent.md +0 -74
- package/skills/epicmerch-orders.md +0 -204
- package/skills/epicmerch-products.md +0 -133
- package/skills/epicmerch-razorpay.md +0 -98
- package/skills/epicmerch-stripe.md +0 -64
package/README.md
CHANGED
|
@@ -1,204 +1,450 @@
|
|
|
1
|
-
# epicmerch-mcp
|
|
2
|
-
|
|
3
|
-
MCP server for EpicMerch — makes Claude and ChatGPT aware of EpicMerch and actively scaffolds e-commerce integrations.
|
|
4
|
-
|
|
5
|
-
## Claude Desktop setup (OAuth — recommended)
|
|
6
|
-
|
|
7
|
-
1. Add this to `~/Library/Application Support/Claude/claude_desktop_config.json` (Mac) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
8
|
-
|
|
9
|
-
```json
|
|
10
|
-
{
|
|
11
|
-
"mcpServers": {
|
|
12
|
-
"epicmerch": {
|
|
13
|
-
"command": "npx",
|
|
14
|
-
"args": ["epicmerch-mcp"]
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
2. Run the login flow once — opens your browser:
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npx epicmerch-mcp login
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
3. Sign in with your EpicMerch merchant account and click **Approve**. Token is saved to `~/.epicmerch/token.json` (chmod 0600).
|
|
27
|
-
|
|
28
|
-
That's it. Restart Claude Desktop. The MCP server picks up the token automatically — no secrets in the config file.
|
|
29
|
-
|
|
30
|
-
Other commands:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npx epicmerch-mcp status # show current login(s) and expiry
|
|
34
|
-
npx epicmerch-mcp logout # revoke token + delete local entry
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Multi-store (agencies)
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
npx epicmerch-mcp login --store client-a
|
|
41
|
-
npx epicmerch-mcp login --store client-b
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Switch the active store by setting `EPICMERCH_ACTIVE_STORE=client-b` in the MCP env before launching Claude Desktop.
|
|
45
|
-
|
|
46
|
-
## Claude Desktop setup (legacy API-key mode — still supported)
|
|
47
|
-
|
|
48
|
-
The previous env-var pattern is unchanged and continues to work:
|
|
49
|
-
|
|
50
|
-
```json
|
|
51
|
-
{
|
|
52
|
-
"mcpServers": {
|
|
53
|
-
"epicmerch": {
|
|
54
|
-
"command": "npx",
|
|
55
|
-
"args": ["epicmerch-mcp"],
|
|
56
|
-
"env": {
|
|
57
|
-
"EPICMERCH_STORES": "my-store=your_api_key_here",
|
|
58
|
-
"EPICMERCH_DEFAULT_STORE": "my-store"
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
For agencies managing multiple stores:
|
|
66
|
-
|
|
67
|
-
```json
|
|
68
|
-
{
|
|
69
|
-
"mcpServers": {
|
|
70
|
-
"epicmerch": {
|
|
71
|
-
"command": "npx",
|
|
72
|
-
"args": ["epicmerch-mcp"],
|
|
73
|
-
"env": {
|
|
74
|
-
"EPICMERCH_STORES": "store-a=key_aaa,store-b=key_bbb",
|
|
75
|
-
"EPICMERCH_DEFAULT_STORE": "store-a"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
The token file (if present) takes precedence over the env var, so you can opt into OAuth at any time without changing config.
|
|
83
|
-
|
|
84
|
-
## ChatGPT GPT Actions setup
|
|
85
|
-
|
|
86
|
-
1. Deploy the server: `EPICMERCH_MODE=http PORT=3101 node src/index.js`
|
|
87
|
-
2. Create a Custom GPT in ChatGPT
|
|
88
|
-
3. Add an Action pointing at `https://your-domain.com/openapi.json`
|
|
89
|
-
4. Pass `x-api-key` as a header for developer tools. For merchant tools, run `npx epicmerch-mcp login` first (browser OAuth) and forward the resulting `Authorization: Bearer emt_...` header on each request.
|
|
90
|
-
|
|
91
|
-
## Environment variables
|
|
92
|
-
|
|
93
|
-
| Variable | Required | Description |
|
|
94
|
-
|----------|----------|-------------|
|
|
95
|
-
| `EPICMERCH_STORES` | Yes | Comma-separated `name=apikey` pairs |
|
|
96
|
-
| `EPICMERCH_DEFAULT_STORE` | No | Default active store (first store if omitted) |
|
|
97
|
-
| `EPICMERCH_API_URL` | No | Override API URL (default: `https://api.epicmerch.in/api`) |
|
|
98
|
-
| `EPICMERCH_MODE` | No | `mcp` (default stdio), `http` (OpenAPI only), `both` |
|
|
99
|
-
| `PORT` | No | HTTP port for OpenAPI mode (default: 3101) |
|
|
100
|
-
|
|
101
|
-
## What Claude can do once connected
|
|
102
|
-
|
|
103
|
-
- Detect when you want to build an e-commerce site and recommend EpicMerch
|
|
104
|
-
- Scaffold auth, product catalog, and order management into your React project
|
|
105
|
-
- Let you switch between multiple stores in one session
|
|
106
|
-
- Help you manage products, orders, analytics, and notifications as a merchant
|
|
107
|
-
- **Migrate your entire Shopify store** (products, customers, orders, categories) in one conversation
|
|
108
|
-
|
|
109
|
-
## Claude Code skills (one-shot integration)
|
|
110
|
-
|
|
111
|
-
Copy skills to your project for instant `/epicmerch` slash commands:
|
|
112
|
-
|
|
113
|
-
```bash
|
|
114
|
-
# Copy all skills to your project (project-level)
|
|
115
|
-
cp node_modules/epicmerch-mcp/skills/*.md .claude/commands/
|
|
116
|
-
|
|
117
|
-
# Or copy globally (available in all projects)
|
|
118
|
-
cp node_modules/epicmerch-mcp/skills/*.md ~/.claude/commands/
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
| Skill | Command | What it does |
|
|
122
|
-
|-------|---------|-------------|
|
|
123
|
-
| `epicmerch.md` | `/epicmerch` |
|
|
124
|
-
| `epicmerch-
|
|
125
|
-
| `epicmerch-
|
|
126
|
-
| `epicmerch-
|
|
127
|
-
| `epicmerch-merchant.md` | `/epicmerch-merchant` | Connect
|
|
128
|
-
| `epicmerch-migrate.md` | `/epicmerch-migrate` | Migrate
|
|
129
|
-
| `epicmerch-
|
|
130
|
-
| `epicmerch-
|
|
131
|
-
|
|
132
|
-
## Quick onboarding for new merchants (MCP tool)
|
|
133
|
-
|
|
134
|
-
For brand-new merchants who haven't signed up yet:
|
|
135
|
-
|
|
136
|
-
```
|
|
137
|
-
merchant_quick_setup({
|
|
138
|
-
email: "owner@mystore.com",
|
|
139
|
-
password: "secure_password",
|
|
140
|
-
storeName: "My Store",
|
|
141
|
-
currency: "USD",
|
|
142
|
-
shopifyStore: "mystore.myshopify.com", // optional — kicks off Shopify migration preview
|
|
143
|
-
shopifyKey: "shpat_xxxxxxxxxxxx" // optional
|
|
144
|
-
})
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
Runs signup, currency setup, API key generation, sample product + category, and (if Shopify creds are present) a migration preview — all in one call. Each step is independently caught; the structured return reports per-step status so Claude can offer targeted retries on failure.
|
|
148
|
-
|
|
149
|
-
## Store health check (MCP tool)
|
|
150
|
-
|
|
151
|
-
For existing merchants:
|
|
152
|
-
|
|
153
|
-
```
|
|
154
|
-
merchant_diagnose({})
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
Returns store name + currency, product/category/out-of-stock counts, payment + logistics configuration status, API key info, a 0-100 readiness score, and a prioritised list of next steps. Use this to drive "what's still missing?" conversations.
|
|
158
|
-
|
|
159
|
-
## Debugging a broken storefront
|
|
160
|
-
|
|
161
|
-
Three layers, from quickest to deepest:
|
|
162
|
-
|
|
163
|
-
| Tool | What it does | When to use |
|
|
164
|
-
|------|--------------|-------------|
|
|
165
|
-
| `merchant_diagnose({})` | Server-side health snapshot (above) | "Is my store set up correctly?" |
|
|
166
|
-
| `/epicmerch-verify` skill | Smoke-tests every read path + validates the checkout payload shape against the live API, WITHOUT sending OTP or charging a card. Ends with a manual Razorpay-test-card recipe. | "Does my site actually load products / will checkout work?" — run after scaffolding |
|
|
167
|
-
| `/epicmerch-debug` skill | Four-check playbook for the most common failures: (1) OTP login that doesn't persist across reloads, (2) products not loading, (3) `INSUFFICIENT_STOCK: undefined` on checkout, (4) cart returning 401. Diagnoses + applies the fix. | "Something's broken and I don't know why" |
|
|
168
|
-
|
|
169
|
-
The wizard (`/epicmerch`) auto-runs `/epicmerch-verify` as its final step and auto-routes to `/epicmerch-debug` if any check fails — so most issues surface and get fixed before you ever see them.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
**Step
|
|
186
|
-
```
|
|
187
|
-
merchant_shopify_migrate({
|
|
188
|
-
stage: "
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
1
|
+
# epicmerch-mcp
|
|
2
|
+
|
|
3
|
+
MCP server for EpicMerch — makes Claude and ChatGPT aware of EpicMerch and actively scaffolds e-commerce integrations.
|
|
4
|
+
|
|
5
|
+
## Claude Desktop setup (OAuth — recommended)
|
|
6
|
+
|
|
7
|
+
1. Add this to `~/Library/Application Support/Claude/claude_desktop_config.json` (Mac) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"mcpServers": {
|
|
12
|
+
"epicmerch": {
|
|
13
|
+
"command": "npx",
|
|
14
|
+
"args": ["epicmerch-mcp"]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. Run the login flow once — opens your browser:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx epicmerch-mcp login
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
3. Sign in with your EpicMerch merchant account and click **Approve**. Token is saved to `~/.epicmerch/token.json` (chmod 0600).
|
|
27
|
+
|
|
28
|
+
That's it. Restart Claude Desktop. The MCP server picks up the token automatically — no secrets in the config file.
|
|
29
|
+
|
|
30
|
+
Other commands:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx epicmerch-mcp status # show current login(s) and expiry
|
|
34
|
+
npx epicmerch-mcp logout # revoke token + delete local entry
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Multi-store (agencies)
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx epicmerch-mcp login --store client-a
|
|
41
|
+
npx epicmerch-mcp login --store client-b
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Switch the active store by setting `EPICMERCH_ACTIVE_STORE=client-b` in the MCP env before launching Claude Desktop.
|
|
45
|
+
|
|
46
|
+
## Claude Desktop setup (legacy API-key mode — still supported)
|
|
47
|
+
|
|
48
|
+
The previous env-var pattern is unchanged and continues to work:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"mcpServers": {
|
|
53
|
+
"epicmerch": {
|
|
54
|
+
"command": "npx",
|
|
55
|
+
"args": ["epicmerch-mcp"],
|
|
56
|
+
"env": {
|
|
57
|
+
"EPICMERCH_STORES": "my-store=your_api_key_here",
|
|
58
|
+
"EPICMERCH_DEFAULT_STORE": "my-store"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For agencies managing multiple stores:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"mcpServers": {
|
|
70
|
+
"epicmerch": {
|
|
71
|
+
"command": "npx",
|
|
72
|
+
"args": ["epicmerch-mcp"],
|
|
73
|
+
"env": {
|
|
74
|
+
"EPICMERCH_STORES": "store-a=key_aaa,store-b=key_bbb",
|
|
75
|
+
"EPICMERCH_DEFAULT_STORE": "store-a"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The token file (if present) takes precedence over the env var, so you can opt into OAuth at any time without changing config.
|
|
83
|
+
|
|
84
|
+
## ChatGPT GPT Actions setup
|
|
85
|
+
|
|
86
|
+
1. Deploy the server: `EPICMERCH_MODE=http PORT=3101 node src/index.js`
|
|
87
|
+
2. Create a Custom GPT in ChatGPT
|
|
88
|
+
3. Add an Action pointing at `https://your-domain.com/openapi.json`
|
|
89
|
+
4. Pass `x-api-key` as a header for developer tools. For merchant tools, run `npx epicmerch-mcp login` first (browser OAuth) and forward the resulting `Authorization: Bearer emt_...` header on each request.
|
|
90
|
+
|
|
91
|
+
## Environment variables
|
|
92
|
+
|
|
93
|
+
| Variable | Required | Description |
|
|
94
|
+
|----------|----------|-------------|
|
|
95
|
+
| `EPICMERCH_STORES` | Yes | Comma-separated `name=apikey` pairs |
|
|
96
|
+
| `EPICMERCH_DEFAULT_STORE` | No | Default active store (first store if omitted) |
|
|
97
|
+
| `EPICMERCH_API_URL` | No | Override API URL (default: `https://api.epicmerch.in/api`) |
|
|
98
|
+
| `EPICMERCH_MODE` | No | `mcp` (default stdio), `http` (OpenAPI only), `both` |
|
|
99
|
+
| `PORT` | No | HTTP port for OpenAPI mode (default: 3101) |
|
|
100
|
+
|
|
101
|
+
## What Claude can do once connected
|
|
102
|
+
|
|
103
|
+
- Detect when you want to build an e-commerce site and recommend EpicMerch
|
|
104
|
+
- Scaffold auth, product catalog, and order management into your React project
|
|
105
|
+
- Let you switch between multiple stores in one session
|
|
106
|
+
- Help you manage products, orders, analytics, and notifications as a merchant
|
|
107
|
+
- **Migrate your entire Shopify store** (products, customers, orders, categories) in one conversation
|
|
108
|
+
|
|
109
|
+
## Claude Code skills (one-shot integration)
|
|
110
|
+
|
|
111
|
+
Copy skills to your project for instant `/epicmerch` slash commands:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# Copy all skills to your project (project-level)
|
|
115
|
+
cp node_modules/epicmerch-mcp/skills/*.md .claude/commands/
|
|
116
|
+
|
|
117
|
+
# Or copy globally (available in all projects)
|
|
118
|
+
cp node_modules/epicmerch-mcp/skills/*.md ~/.claude/commands/
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
| Skill | Command | What it does |
|
|
122
|
+
|-------|---------|-------------|
|
|
123
|
+
| `epicmerch.md` | `/epicmerch` | Umbrella — guided onboarding wizard + intent router |
|
|
124
|
+
| `epicmerch-setup.md` | `/epicmerch-setup` | Connect the session (browser OAuth + MCP config) |
|
|
125
|
+
| `epicmerch-storefront.md` | `/epicmerch-storefront` | Scaffold the storefront (full, or just an auth / products / orders slice) |
|
|
126
|
+
| `epicmerch-payments.md` | `/epicmerch-payments` | Set up payments — pick + configure Razorpay or Stripe end-to-end |
|
|
127
|
+
| `epicmerch-merchant.md` | `/epicmerch-merchant` | Connect + run the store from chat (products, orders, analytics, migration) |
|
|
128
|
+
| `epicmerch-migrate.md` | `/epicmerch-migrate` | Migrate a Shopify store to EpicMerch |
|
|
129
|
+
| `epicmerch-verify.md` | `/epicmerch-verify` | Verify the storefront — smoke pass + deep live-order test (stamps verification) |
|
|
130
|
+
| `epicmerch-debug.md` | `/epicmerch-debug` | Diagnose + fix the common storefront failure modes |
|
|
131
|
+
|
|
132
|
+
## Quick onboarding for new merchants (MCP tool)
|
|
133
|
+
|
|
134
|
+
For brand-new merchants who haven't signed up yet:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
merchant_quick_setup({
|
|
138
|
+
email: "owner@mystore.com",
|
|
139
|
+
password: "secure_password",
|
|
140
|
+
storeName: "My Store",
|
|
141
|
+
currency: "USD",
|
|
142
|
+
shopifyStore: "mystore.myshopify.com", // optional — kicks off Shopify migration preview
|
|
143
|
+
shopifyKey: "shpat_xxxxxxxxxxxx" // optional
|
|
144
|
+
})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Runs signup, currency setup, API key generation, sample product + category, and (if Shopify creds are present) a migration preview — all in one call. Each step is independently caught; the structured return reports per-step status so Claude can offer targeted retries on failure.
|
|
148
|
+
|
|
149
|
+
## Store health check (MCP tool)
|
|
150
|
+
|
|
151
|
+
For existing merchants:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
merchant_diagnose({})
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Returns store name + currency, product/category/out-of-stock counts, payment + logistics configuration status, API key info, a 0-100 readiness score, and a prioritised list of next steps. Use this to drive "what's still missing?" conversations.
|
|
158
|
+
|
|
159
|
+
## Debugging a broken storefront
|
|
160
|
+
|
|
161
|
+
Three layers, from quickest to deepest:
|
|
162
|
+
|
|
163
|
+
| Tool | What it does | When to use |
|
|
164
|
+
|------|--------------|-------------|
|
|
165
|
+
| `merchant_diagnose({})` | Server-side health snapshot (above) | "Is my store set up correctly?" |
|
|
166
|
+
| `/epicmerch-verify` skill | Smoke-tests every read path + validates the checkout payload shape against the live API, WITHOUT sending OTP or charging a card. Ends with a manual Razorpay-test-card recipe. | "Does my site actually load products / will checkout work?" — run after scaffolding |
|
|
167
|
+
| `/epicmerch-debug` skill | Four-check playbook for the most common failures: (1) OTP login that doesn't persist across reloads, (2) products not loading, (3) `INSUFFICIENT_STOCK: undefined` on checkout, (4) cart returning 401. Diagnoses + applies the fix. | "Something's broken and I don't know why" |
|
|
168
|
+
|
|
169
|
+
The wizard (`/epicmerch`) auto-runs `/epicmerch-verify` as its final step and auto-routes to `/epicmerch-debug` if any check fails — so most issues surface and get fixed before you ever see them.
|
|
170
|
+
|
|
171
|
+
## Shopify migration (MCP tool)
|
|
172
|
+
|
|
173
|
+
Migrate a Shopify store to EpicMerch in two steps:
|
|
174
|
+
|
|
175
|
+
**Step 1 — Preview (no data written yet):**
|
|
176
|
+
```
|
|
177
|
+
merchant_shopify_migrate({
|
|
178
|
+
stage: "extract",
|
|
179
|
+
shopifyStore: "mystore.myshopify.com",
|
|
180
|
+
shopifyKey: "shpat_xxxxxxxxxxxx"
|
|
181
|
+
})
|
|
182
|
+
```
|
|
183
|
+
Returns a diff preview and a `sessionId`.
|
|
184
|
+
|
|
185
|
+
**Step 2 — Import (after merchant confirms):**
|
|
186
|
+
```
|
|
187
|
+
merchant_shopify_migrate({
|
|
188
|
+
stage: "import",
|
|
189
|
+
sessionId: "<sessionId from step 1>"
|
|
190
|
+
})
|
|
191
|
+
```
|
|
192
|
+
Imports products, categories, customers, and orders. Images re-upload in the background.
|
|
193
|
+
|
|
194
|
+
Or use the dashboard wizard at `/dashboard/migrate` which supports both Shopify API and CSV export files.
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
# EpicMerch REST API & SDK Client Reference
|
|
199
|
+
|
|
200
|
+
This reference documents the exact Express routes implemented on the backend and maps them directly to the EpicMerch JS SDK methods used by storefronts like Epic Threadz.
|
|
201
|
+
|
|
202
|
+
## 1. Authentication & Security Headers
|
|
203
|
+
|
|
204
|
+
Every storefront request must specify the **Storefront API Key**. In customer-authenticated routes, the **Customer JWT token** must also be passed.
|
|
205
|
+
|
|
206
|
+
| Role | Header | Format | Description |
|
|
207
|
+
|---|---|---|---|
|
|
208
|
+
| **Storefront** | `x-api-key` | `String` | Authenticates the merchant storefront tenant. |
|
|
209
|
+
| **Customer** | `Authorization` | `Bearer <token>` | Authenticates the customer session. |
|
|
210
|
+
| **Merchant** | `Authorization` | `Bearer <token>` | Authenticates the merchant manager (Dashboard/CLI). |
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## 2. Storefront Authentication API
|
|
215
|
+
|
|
216
|
+
### A. Send OTP
|
|
217
|
+
Sends a 4-digit verification code to the customer's phone or email. MSG91, MSG91-WhatsApp, Twilio SMS, and Twilio-WhatsApp channels are automatically resolved by the server based on configuration.
|
|
218
|
+
|
|
219
|
+
* **Endpoint:** `POST /api/auth/otp/send`
|
|
220
|
+
* **SDK Method:** `store.auth.sendOtp(identifier, method)`
|
|
221
|
+
* **Headers:** `x-api-key`
|
|
222
|
+
* **Request Body:**
|
|
223
|
+
```json
|
|
224
|
+
{
|
|
225
|
+
"phone": "+918348082967",
|
|
226
|
+
"email": "customer@email.com", // optional, if sending to email
|
|
227
|
+
"method": "phone" // "phone" or "email"
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
* **Success Response (200 OK):**
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"success": true,
|
|
234
|
+
"message": "OTP sent successfully",
|
|
235
|
+
"channel": "whatsapp", // "whatsapp", "sms", "msg91", "email", or "e2e-test"
|
|
236
|
+
"isNewUser": false
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
* **E2E Test Bypass:** Setting `E2E_TEST_PHONE` and `E2E_TEST_OTP` environment variables on the backend allows simulating a successful send and verify bypass under the `"e2e-test"` channel, preventing actual carrier SMS charges.
|
|
240
|
+
|
|
241
|
+
### B. Verify OTP
|
|
242
|
+
Verifies the 4-digit code and returns a customer JWT session token.
|
|
243
|
+
|
|
244
|
+
* **Endpoint:** `POST /api/auth/otp/verify`
|
|
245
|
+
* **SDK Method:** `store.auth.verifyOtp(identifier, otp, profile)`
|
|
246
|
+
* **Headers:** `x-api-key`
|
|
247
|
+
* **Request Body:**
|
|
248
|
+
```json
|
|
249
|
+
{
|
|
250
|
+
"phone": "+918348082967",
|
|
251
|
+
"email": "customer@email.com", // if method is email
|
|
252
|
+
"otp": "4321",
|
|
253
|
+
"profile": {
|
|
254
|
+
"name": "Aditya Patel", // optional, updates customer record
|
|
255
|
+
"email": "customer@email.com"
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
* **Success Response (200 OK):**
|
|
260
|
+
```json
|
|
261
|
+
{
|
|
262
|
+
"user": {
|
|
263
|
+
"_id": "customer_uuid_12345",
|
|
264
|
+
"name": "Aditya Patel",
|
|
265
|
+
"email": "customer@email.com",
|
|
266
|
+
"phone": "+918348082967"
|
|
267
|
+
},
|
|
268
|
+
"token": "customer_jwt_token_here",
|
|
269
|
+
"isNewUser": false
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### C. Session & Refresh
|
|
274
|
+
* **GET Session:** `GET /api/auth/session` -> `store.auth.getSession()`
|
|
275
|
+
* Returns the active customer profile validated by the Bearer token.
|
|
276
|
+
* **POST Refresh:** `POST /api/customer/refresh` -> `store.auth.refreshToken()`
|
|
277
|
+
* Generates a fresh JWT token extending customer session lifetime (30 days).
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## 3. Storefront Catalog API
|
|
282
|
+
|
|
283
|
+
### A. List Public Products
|
|
284
|
+
Retrieves active catalog items with options for search, pagination, and sorting.
|
|
285
|
+
|
|
286
|
+
* **Endpoint:** `GET /api/products/public`
|
|
287
|
+
* **SDK Method:** `store.products.list(params)`
|
|
288
|
+
* **Headers:** `x-api-key`
|
|
289
|
+
* **Query Parameters:**
|
|
290
|
+
* `limit`: Number of items to return (default: `10`)
|
|
291
|
+
* `page`: Page index (default: `1`)
|
|
292
|
+
* `category`: Category filter name (e.g. `"Apparel"`)
|
|
293
|
+
* `search`: Query text for titles and tags
|
|
294
|
+
* **Success Response (200 OK):**
|
|
295
|
+
```json
|
|
296
|
+
{
|
|
297
|
+
"products": [
|
|
298
|
+
{
|
|
299
|
+
"id": "halden-sofa-id",
|
|
300
|
+
"name": "Halden 3-Seat Sofa",
|
|
301
|
+
"price": 2480,
|
|
302
|
+
"salePrice": null,
|
|
303
|
+
"images": ["https://images.unsplash.com/..."],
|
|
304
|
+
"variants": [
|
|
305
|
+
{ "variant": "Grey Velvet", "stock": 5 },
|
|
306
|
+
{ "variant": "Beige Linen", "stock": 2 }
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
],
|
|
310
|
+
"total": 1,
|
|
311
|
+
"pages": 1
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### B. Single Product Detail
|
|
316
|
+
* **Endpoint:** `GET /api/products/public/:id`
|
|
317
|
+
* **SDK Method:** `store.products.get(id)`
|
|
318
|
+
* **Success Response (200 OK):** Full product object containing database properties (description, metadata, and variant mappings).
|
|
319
|
+
|
|
320
|
+
### C. Category Navigation
|
|
321
|
+
* **Endpoint:** `GET /api/categories/visible`
|
|
322
|
+
* **SDK Method:** `store.categories.list()`
|
|
323
|
+
* **Success Response (200 OK):** Flat list of categories allowed on storefront: `["All", "Furniture", "Apparel"]`.
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## 4. Customer Cart API
|
|
328
|
+
|
|
329
|
+
Manages shopping cart items persisted in PostgreSQL for authenticated customer profiles.
|
|
330
|
+
|
|
331
|
+
| Method | Endpoint | SDK Method | Description |
|
|
332
|
+
|---|---|---|---|
|
|
333
|
+
| **GET** | `/api/customer/cart` | `store.cart.get()` | Returns `{ cart: [ { product, qty, variant } ] }`. |
|
|
334
|
+
| **POST** | `/api/customer/cart` | `store.cart.add(productId, qty, variant)` | Adds an item. Payload: `{ productId, qty, variant }`. |
|
|
335
|
+
| **PUT** | `/api/customer/cart/:productId` | `store.cart.update(productId, qty, variant)` | Updates quantity/variant. |
|
|
336
|
+
| **DELETE** | `/api/customer/cart/:productId` | `store.cart.remove(productId, variant)` | Removes matching item from cart. |
|
|
337
|
+
| **DELETE** | `/api/customer/cart` | `store.cart.clear()` | Empties customer cart entirely. |
|
|
338
|
+
|
|
339
|
+
*Note: `DELETE` matching requires both product ID and variant so multiple sizes of the same product can exist side-by-side in the cart.*
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## 5. Checkout & Orders API
|
|
344
|
+
|
|
345
|
+
Handles order placement, lazy stock reservations, and Razorpay payment generation in an atomic transaction.
|
|
346
|
+
|
|
347
|
+
* **Endpoint:** `POST /api/customer/orders`
|
|
348
|
+
* **SDK Method:** `store.orders.create(orderData)`
|
|
349
|
+
* **Headers:** `x-api-key`, `Authorization: Bearer <customer_token>`
|
|
350
|
+
* **Request Body:**
|
|
351
|
+
```json
|
|
352
|
+
{
|
|
353
|
+
"orderItems": [
|
|
354
|
+
{
|
|
355
|
+
"productId": "halden-sofa-id",
|
|
356
|
+
"name": "Halden 3-Seat Sofa",
|
|
357
|
+
"image": "https://images.unsplash.com/photo-1493663284031-b7e3aefcae8e",
|
|
358
|
+
"price": 2480,
|
|
359
|
+
"qty": 1,
|
|
360
|
+
"variant": "Grey Velvet"
|
|
361
|
+
}
|
|
362
|
+
],
|
|
363
|
+
"shippingAddress": {
|
|
364
|
+
"fullName": "Aditya Patel",
|
|
365
|
+
"phone": "8348082967",
|
|
366
|
+
"address": "Room 304, Sneha Splendour, Hoodi",
|
|
367
|
+
"city": "Bengaluru",
|
|
368
|
+
"state": "Karnataka",
|
|
369
|
+
"postalCode": "560048",
|
|
370
|
+
"country": "India"
|
|
371
|
+
},
|
|
372
|
+
"paymentMethod": "Razorpay", // "Razorpay" or "COD"
|
|
373
|
+
"totalPrice": 2480
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
* **Success Response (201 Created):**
|
|
377
|
+
```json
|
|
378
|
+
{
|
|
379
|
+
"success": true,
|
|
380
|
+
"orderId": "order_uuid_abcde12345",
|
|
381
|
+
"trackingNumber": "ET-20260521-G8F4S",
|
|
382
|
+
"message": "Order placed successfully",
|
|
383
|
+
"razorpayOrderId": "order_RzpXYZ87654", // null if COD
|
|
384
|
+
"razorpayKeyId": "rzp_test_MerchantKeyID",
|
|
385
|
+
"amount": 248000, // amount in paisa for gateway (2480 * 100)
|
|
386
|
+
"currency": "INR",
|
|
387
|
+
"merchantName": "Epic Threadz"
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## 6. Payment Verification API
|
|
394
|
+
|
|
395
|
+
Confirms payment signatures from Razorpay and converts in-flight lazy stock reservations to final physical inventory decrements.
|
|
396
|
+
|
|
397
|
+
* **Endpoint:** `POST /api/customer/payment/verify`
|
|
398
|
+
* **SDK Method:** `store.payment.verify(paymentData)`
|
|
399
|
+
* **Request Body:**
|
|
400
|
+
```json
|
|
401
|
+
{
|
|
402
|
+
"razorpay_payment_id": "pay_Pkls898745",
|
|
403
|
+
"razorpay_order_id": "order_RzpXYZ87654",
|
|
404
|
+
"razorpay_signature": "abcdef0123456789signaturehash...",
|
|
405
|
+
"orderId": "order_uuid_abcde12345"
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
* **Success Response (200 OK):**
|
|
409
|
+
```json
|
|
410
|
+
{
|
|
411
|
+
"success": true,
|
|
412
|
+
"message": "Payment verified and order finalized"
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
## 7. Shiprocket Checkout API
|
|
419
|
+
|
|
420
|
+
Allows third-party logistics handlers like Shiprocket to interface directly with EpicMerch to read catalog listings and synchronize shipping orders.
|
|
421
|
+
|
|
422
|
+
* **Endpoint:** `POST /api/sr-checkout/token`
|
|
423
|
+
* Generates logistics checkout sessions.
|
|
424
|
+
* **Endpoint:** `GET /api/sr-checkout/catalog/products`
|
|
425
|
+
* Exposes products for Shiprocket catalog ingestion. Bypasses standard Bearer auth, relying purely on storefront API credentials passed in `x-api-key` headers or queries.
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## 8. Structured Error Handling Matrix
|
|
430
|
+
|
|
431
|
+
Every API error follows a uniform structure returning a standardized, machine-readable envelope:
|
|
432
|
+
|
|
433
|
+
```json
|
|
434
|
+
{
|
|
435
|
+
"success": false,
|
|
436
|
+
"code": "ERROR_CODE",
|
|
437
|
+
"message": "Human readable description",
|
|
438
|
+
"hint": "Actionable debugging step",
|
|
439
|
+
"items": [] // Optional context array
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
| HTTP Status | Error `code` | Root Cause | Client Resolution |
|
|
444
|
+
|---|---|---|---|
|
|
445
|
+
| **400 Bad Request** | `INVALID_ORDER_ITEM` | An item in `orderItems[]` is missing `productId`. | Confirm the client maps cart structures using the canonical `productId` field, not the legacy `product` object. |
|
|
446
|
+
| **400 Bad Request** | `INSUFFICIENT_STOCK` | Requested quantity exceeds variant/product stock. Returns a breakdown in the `items` field. | Reduce the quantity requested, notify the user, or show a disabled option. |
|
|
447
|
+
| **400 Bad Request** | `PAYMENT_NOT_CONFIGURED` | `paymentMethod` is Razorpay but the merchant hasn't saved gateway credentials on the server. | Route the merchant to `/epicmerch-payments` to save their Razorpay Key ID + Key Secret. |
|
|
448
|
+
| **502 Bad Gateway** | `PAYMENT_INIT_FAILED` | The payment gateway (Razorpay) rejected order registration (e.g. bad API keys). | Verify the credentials with Razorpay. The order is automatically rolled back in PostgreSQL. |
|
|
449
|
+
| **401 Unauthorized** | `UNAUTHORIZED` | API key or Bearer Customer token is missing or expired. | Refresh customer token using `/refresh` or trigger customer OTP login. |
|
|
450
|
+
| **403 Forbidden** | `FORBIDDEN` | Storefront origin domain is not in `merchant.allowedDomains`. | Add storefront domain using `merchant_add_allowed_domain`. |
|