@liquidcommerce/elements-sdk 2.2.2 → 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.
Files changed (62) hide show
  1. package/README.md +1608 -557
  2. package/dist/index.esm.js +10170 -8144
  3. package/dist/types/core/auth.service.d.ts +10 -4
  4. package/dist/types/core/base-component.service.d.ts +3 -0
  5. package/dist/types/core/circuit-breaker.service.d.ts +54 -0
  6. package/dist/types/core/client/client-action.service.d.ts +13 -11
  7. package/dist/types/core/client/client-config.service.d.ts +5 -3
  8. package/dist/types/core/command/common-command.service.d.ts +2 -1
  9. package/dist/types/core/debug-panel/debug-panel.service.d.ts +43 -0
  10. package/dist/types/core/debug-panel/debug-panel.styles.d.ts +1 -0
  11. package/dist/types/core/fingerprint.service.d.ts +4 -9
  12. package/dist/types/core/google-tag-manager.service.d.ts +127 -2
  13. package/dist/types/core/logger/logger-factory.d.ts +3 -0
  14. package/dist/types/core/logger/logger.service.d.ts +8 -5
  15. package/dist/types/core/pubsub/interfaces/core.interface.d.ts +2 -3
  16. package/dist/types/core/pubsub/interfaces/product.interface.d.ts +0 -5
  17. package/dist/types/core/store/interfaces/cart.interface.d.ts +0 -1
  18. package/dist/types/core/store/interfaces/checkout.interface.d.ts +0 -1
  19. package/dist/types/core/store/interfaces/core.interface.d.ts +2 -2
  20. package/dist/types/core/store/interfaces/product.interface.d.ts +0 -1
  21. package/dist/types/core/store/store.service.d.ts +1 -0
  22. package/dist/types/core/telemetry/telemetry.interface.d.ts +80 -0
  23. package/dist/types/core/telemetry/telemetry.service.d.ts +27 -0
  24. package/dist/types/enums/core.enum.d.ts +0 -1
  25. package/dist/types/enums/debug.enum.d.ts +6 -0
  26. package/dist/types/enums/index.d.ts +1 -0
  27. package/dist/types/interfaces/core.interface.d.ts +2 -2
  28. package/dist/types/modules/address/address.command.d.ts +1 -3
  29. package/dist/types/modules/cart/cart.commands.d.ts +1 -1
  30. package/dist/types/modules/cart/cart.component.d.ts +1 -2
  31. package/dist/types/modules/cart/components/cart-footer.component.d.ts +1 -0
  32. package/dist/types/modules/cart/components/cart-item.component.d.ts +2 -6
  33. package/dist/types/modules/checkout/checkout.commands.d.ts +3 -2
  34. package/dist/types/modules/checkout/checkout.component.d.ts +1 -2
  35. package/dist/types/modules/checkout/components/checkout-summary-section.component.d.ts +2 -0
  36. package/dist/types/modules/checkout/components/information/checkout-delivery-information-form.component.d.ts +1 -1
  37. package/dist/types/modules/checkout/components/summary/checkout-item-quantity.component.d.ts +0 -2
  38. package/dist/types/modules/checkout/components/summary/checkout-item.component.d.ts +2 -1
  39. package/dist/types/modules/checkout/components/summary/checkout-items.component.d.ts +1 -0
  40. package/dist/types/modules/checkout/components/summary/checkout-place-order-button.component.d.ts +0 -1
  41. package/dist/types/modules/checkout/constant.d.ts +0 -1
  42. package/dist/types/modules/product/components/index.d.ts +1 -0
  43. package/dist/types/modules/product/components/product-add-to-cart-section.component.d.ts +1 -0
  44. package/dist/types/modules/product/components/product-interactions.component.d.ts +4 -1
  45. package/dist/types/modules/product/components/product-price.component.d.ts +1 -0
  46. package/dist/types/modules/product/components/product-retailers.component.d.ts +1 -0
  47. package/dist/types/modules/product/product.commands.d.ts +1 -1
  48. package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +13 -11
  49. package/dist/types/modules/ui-components/engraving/engraving-view.component.d.ts +4 -9
  50. package/dist/types/static/icon/index.d.ts +0 -1
  51. package/dist/types/utils/format.d.ts +2 -1
  52. package/docs/ACTIONS.md +1235 -0
  53. package/docs/BROWSER_SUPPORT.md +279 -0
  54. package/docs/CONFIGURATION.md +613 -0
  55. package/docs/DOCUMENTATION_INDEX.md +311 -0
  56. package/docs/EVENTS.md +532 -0
  57. package/docs/PROXY.md +228 -0
  58. package/docs/THEMING.md +592 -0
  59. package/docs/TROUBLESHOOTING.md +755 -0
  60. package/package.json +17 -17
  61. package/umd/elements.js +1 -1
  62. package/dist/types/static/icon/completed.icon.d.ts +0 -2
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
+ ```