@liquidcommerce/elements-sdk 2.3.0 → 2.4.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/dist/index.esm.js +7942 -7627
- package/dist/types/core/google-tag-manager.service.d.ts +1 -0
- package/dist/types/modules/cart/components/cart-footer.component.d.ts +1 -0
- package/dist/types/modules/cart/components/cart-item.component.d.ts +1 -0
- package/dist/types/modules/checkout/components/checkout-summary-section.component.d.ts +2 -0
- package/dist/types/modules/checkout/components/summary/checkout-items.component.d.ts +1 -0
- package/dist/types/modules/ui-components/engraving/engraving-view.component.d.ts +1 -0
- package/docs/ACTIONS.md +1235 -0
- package/docs/BROWSER_SUPPORT.md +279 -0
- package/docs/CONFIGURATION.md +613 -0
- package/docs/DOCUMENTATION_INDEX.md +311 -0
- package/docs/EVENTS.md +532 -0
- package/docs/PROXY.md +228 -0
- package/docs/THEMING.md +592 -0
- package/docs/TROUBLESHOOTING.md +755 -0
- package/package.json +8 -5
- package/umd/elements.js +1 -1
package/docs/PROXY.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Proxy Configuration Guide
|
|
2
|
+
|
|
3
|
+
Configure the LiquidCommerce Elements SDK to route API requests through your own server to avoid ad blockers.
|
|
4
|
+
|
|
5
|
+
## Quick Setup
|
|
6
|
+
|
|
7
|
+
### 1. Configure the SDK
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
const elements = await Elements('your-api-key', {
|
|
11
|
+
env: 'production',
|
|
12
|
+
proxy: {
|
|
13
|
+
baseUrl: 'https://yourdomain.com/api/liquidcommerce'
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### 2. How It Works
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
Without Proxy: Your App → LiquidCommerce API
|
|
22
|
+
With Proxy: Your App → Your Server → LiquidCommerce API
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The SDK automatically:
|
|
26
|
+
- Changes API calls from `https://elements.liquidcommerce.us/api/*` to `https://yourdomain.com/api/liquidcommerce/api/*`
|
|
27
|
+
- Adds `X-Liquid-Proxy-Target` header with the original LiquidCommerce URL
|
|
28
|
+
- Sends all required LiquidCommerce headers that your proxy must forward
|
|
29
|
+
|
|
30
|
+
## Required Headers
|
|
31
|
+
|
|
32
|
+
The SDK sends these headers that **must be forwarded** to LiquidCommerce:
|
|
33
|
+
|
|
34
|
+
### Authentication Headers
|
|
35
|
+
- `X-Liquid-Api-Key` - Your LiquidCommerce API key
|
|
36
|
+
- `X-Liquid-Api-Env` - Environment (staging, production, development)
|
|
37
|
+
- `Authorization` - Bearer token (added automatically after authentication)
|
|
38
|
+
|
|
39
|
+
### Tracking Headers
|
|
40
|
+
- `X-Liquid-Api-Sdk` - Source URL (usually `window.location.href`)
|
|
41
|
+
- `X-Liquid-Sdk-Version` - SDK version for debugging
|
|
42
|
+
- `X-Liquid-Proxy` - Always `true` when using a proxy
|
|
43
|
+
|
|
44
|
+
### Proxy Headers
|
|
45
|
+
- `X-Liquid-Proxy-Target` - Original LiquidCommerce API URL to forward to
|
|
46
|
+
- `Content-Type` - Always `application/json`
|
|
47
|
+
|
|
48
|
+
### Your Custom Headers (optional)
|
|
49
|
+
- Any headers you add in `proxy.headers` config
|
|
50
|
+
|
|
51
|
+
## Next.js Implementation
|
|
52
|
+
|
|
53
|
+
### API Route: `pages/api/liquidcommerce/[...path].js`
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
export default async function handler(req, res) {
|
|
57
|
+
// Get the API path from the dynamic route
|
|
58
|
+
const { path } = req.query;
|
|
59
|
+
const apiPath = Array.isArray(path) ? path.join('/') : path;
|
|
60
|
+
|
|
61
|
+
// Get target URL from SDK header
|
|
62
|
+
const targetUrl = req.headers['x-liquid-proxy-target'];
|
|
63
|
+
|
|
64
|
+
if (!targetUrl) {
|
|
65
|
+
return res.status(400).json({ error: 'Missing target URL' });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Security: Validate target URL
|
|
69
|
+
const allowedTargets = [
|
|
70
|
+
'https://elements.liquidcommerce.us',
|
|
71
|
+
'https://staging-elements.liquidcommerce.us'
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
if (!allowedTargets.includes(targetUrl)) {
|
|
75
|
+
return res.status(400).json({ error: 'Invalid target URL' });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
// Forward the request to LiquidCommerce with ALL required headers
|
|
80
|
+
const response = await fetch(`${targetUrl}/api/${apiPath}`, {
|
|
81
|
+
method: req.method,
|
|
82
|
+
headers: {
|
|
83
|
+
// Required LiquidCommerce headers
|
|
84
|
+
'Content-Type': 'application/json',
|
|
85
|
+
'X-Liquid-Api-Key': req.headers['x-liquid-api-key'],
|
|
86
|
+
'X-Liquid-Api-Env': req.headers['x-liquid-api-env'],
|
|
87
|
+
'X-Liquid-Api-Sdk': req.headers['x-liquid-api-sdk'],
|
|
88
|
+
'X-Liquid-Sdk-Version': req.headers['x-liquid-sdk-version'],
|
|
89
|
+
'X-Liquid-Proxy': req.headers['x-liquid-proxy'],
|
|
90
|
+
'Authorization': req.headers['authorization'],
|
|
91
|
+
// Don't forward the proxy target header to LiquidCommerce
|
|
92
|
+
// 'X-Liquid-Proxy-Target': NOT forwarded
|
|
93
|
+
},
|
|
94
|
+
body: req.method !== 'GET' ? JSON.stringify(req.body) : undefined,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const data = await response.json();
|
|
98
|
+
res.status(response.status).json(data);
|
|
99
|
+
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error('Proxy error:', error);
|
|
102
|
+
res.status(500).json({ error: 'Proxy error' });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### App Router: `app/api/liquidcommerce/[...path]/route.js`
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
export async function GET(request, { params }) {
|
|
111
|
+
return handleRequest(request, params, 'GET');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function POST(request, { params }) {
|
|
115
|
+
return handleRequest(request, params, 'POST');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function PUT(request, { params }) {
|
|
119
|
+
return handleRequest(request, params, 'PUT');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function handleRequest(request, params, method) {
|
|
123
|
+
const apiPath = params.path.join('/');
|
|
124
|
+
const targetUrl = request.headers.get('x-liquid-proxy-target');
|
|
125
|
+
|
|
126
|
+
if (!targetUrl) {
|
|
127
|
+
return Response.json({ error: 'Missing target URL' }, { status: 400 });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Security check
|
|
131
|
+
const allowedTargets = [
|
|
132
|
+
'https://elements.liquidcommerce.us',
|
|
133
|
+
'https://staging-elements.liquidcommerce.us'
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
if (!allowedTargets.includes(targetUrl)) {
|
|
137
|
+
return Response.json({ error: 'Invalid target URL' }, { status: 400 });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
const body = method !== 'GET' ? await request.json() : undefined;
|
|
142
|
+
|
|
143
|
+
const response = await fetch(`${targetUrl}/api/${apiPath}`, {
|
|
144
|
+
method,
|
|
145
|
+
headers: {
|
|
146
|
+
// Required LiquidCommerce headers
|
|
147
|
+
'Content-Type': 'application/json',
|
|
148
|
+
'X-Liquid-Api-Key': request.headers.get('x-liquid-api-key'),
|
|
149
|
+
'X-Liquid-Api-Env': request.headers.get('x-liquid-api-env'),
|
|
150
|
+
'X-Liquid-Api-Sdk': request.headers.get('x-liquid-api-sdk'),
|
|
151
|
+
'X-Liquid-Sdk-Version': request.headers.get('x-liquid-sdk-version'),
|
|
152
|
+
'Authorization': request.headers.get('authorization'),
|
|
153
|
+
// Don't forward the proxy target header to LiquidCommerce
|
|
154
|
+
// 'X-Liquid-Proxy-Target': NOT forwarded
|
|
155
|
+
},
|
|
156
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const data = await response.json();
|
|
160
|
+
return Response.json(data, { status: response.status });
|
|
161
|
+
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error('Proxy error:', error);
|
|
164
|
+
return Response.json({ error: 'Proxy error' }, { status: 500 });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Testing
|
|
170
|
+
|
|
171
|
+
### 1. Test the proxy endpoint directly:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
curl -X GET "https://yourdomain.com/api/liquidcommerce/configs" \
|
|
175
|
+
-H "Content-Type: application/json" \
|
|
176
|
+
-H "X-Liquid-Proxy-Target: https://staging-elements.liquidcommerce.us" \
|
|
177
|
+
-H "X-Liquid-Api-Key: your-api-key" \
|
|
178
|
+
-H "X-Liquid-Api-Env: staging" \
|
|
179
|
+
-H "X-Liquid-Api-Sdk: https://yoursite.com" \
|
|
180
|
+
-H "X-Liquid-Sdk-Version: 1.0.0"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 2. Use the SDK with proxy:
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
// This will automatically use your proxy
|
|
187
|
+
const elements = await Elements('your-api-key', {
|
|
188
|
+
env: 'staging',
|
|
189
|
+
proxy: {
|
|
190
|
+
baseUrl: 'https://yourdomain.com/api/liquidcommerce'
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
await elements.prepare(); // Uses proxy for all API calls
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Security
|
|
198
|
+
|
|
199
|
+
1. **Validate target URLs** - Only allow known LiquidCommerce domains
|
|
200
|
+
2. **Forward required headers only** - Forward the headers listed above, exclude internal ones
|
|
201
|
+
3. **Don't forward `X-Liquid-Proxy-Target`** - This is for your proxy only, not LiquidCommerce
|
|
202
|
+
4. **Add rate limiting** if needed
|
|
203
|
+
5. **Log requests** for monitoring
|
|
204
|
+
|
|
205
|
+
## Important Notes
|
|
206
|
+
|
|
207
|
+
- **All SDK headers must be forwarded** - Missing headers will cause authentication failures
|
|
208
|
+
- **`Authorization` header is added automatically** - After the SDK authenticates with your API key
|
|
209
|
+
- **`X-Liquid-Proxy-Target` stays with your proxy** - Don't send this to LiquidCommerce
|
|
210
|
+
- **Content-Type must be `application/json`** - Required for all API requests
|
|
211
|
+
|
|
212
|
+
## Benefits
|
|
213
|
+
|
|
214
|
+
- ✅ **Bypass ad blockers** - Requests come from your domain
|
|
215
|
+
- ✅ **Control requests** - Monitor and modify API calls
|
|
216
|
+
- ✅ **Add authentication** - Include your own auth headers
|
|
217
|
+
- ✅ **Zero client changes** - Transparent to the SDK
|
|
218
|
+
|
|
219
|
+
## Configuration Options
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
proxy: {
|
|
223
|
+
baseUrl: 'https://yourdomain.com/api/liquidcommerce', // Required: Full proxy endpoint URL
|
|
224
|
+
headers: { // Optional: Custom headers
|
|
225
|
+
'X-Custom-Header': 'value'
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|