omni-sync-sdk 0.21.3 → 0.21.4
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 +60 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -148,23 +148,61 @@ const order = await omni.submitGuestOrder();
|
|
|
148
148
|
- Guest user + Local cart → `startGuestCheckout()` or `submitGuestOrder()`
|
|
149
149
|
- Logged-in user + Server cart → `createCheckout({ cartId })`
|
|
150
150
|
|
|
151
|
-
### 2.
|
|
151
|
+
### 2. ⛔ NEVER Create Local Interfaces - Use SDK Types!
|
|
152
|
+
|
|
153
|
+
**This causes type errors and runtime bugs!**
|
|
152
154
|
|
|
153
155
|
```typescript
|
|
154
|
-
// ❌ WRONG - Don't create
|
|
155
|
-
interface
|
|
156
|
-
|
|
156
|
+
// ❌ WRONG - Don't create your own interfaces!
|
|
157
|
+
interface CartItem {
|
|
158
|
+
id: string;
|
|
159
|
+
name: string; // WRONG - it's item.product.name!
|
|
160
|
+
price: number; // WRONG - prices are strings!
|
|
161
|
+
}
|
|
157
162
|
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
// ❌ WRONG - Don't use 'as unknown as' casting!
|
|
164
|
+
const item = result as unknown as MyLocalType;
|
|
165
|
+
|
|
166
|
+
// ✅ CORRECT - Import ALL types from SDK
|
|
167
|
+
import type {
|
|
168
|
+
Product,
|
|
169
|
+
ProductVariant,
|
|
170
|
+
Cart,
|
|
171
|
+
CartItem,
|
|
172
|
+
Checkout,
|
|
173
|
+
CheckoutLineItem,
|
|
174
|
+
Order,
|
|
175
|
+
OrderItem,
|
|
176
|
+
CustomerProfile,
|
|
177
|
+
CustomerAddress,
|
|
178
|
+
ShippingRate,
|
|
179
|
+
PaymentProvider,
|
|
180
|
+
PaymentIntent,
|
|
181
|
+
PaymentStatus,
|
|
182
|
+
SearchSuggestions,
|
|
161
183
|
ProductSuggestion,
|
|
162
184
|
CategorySuggestion,
|
|
163
|
-
|
|
185
|
+
OAuthAuthorizeResponse,
|
|
186
|
+
CustomerOAuthProvider,
|
|
164
187
|
} from 'omni-sync-sdk';
|
|
165
188
|
```
|
|
166
189
|
|
|
167
|
-
|
|
190
|
+
**⚠️ SDK Type Facts - Trust These!**
|
|
191
|
+
|
|
192
|
+
| What | Correct | Wrong |
|
|
193
|
+
| ------------------------ | ----------------------------- | --------------------- |
|
|
194
|
+
| Prices | `string` (use `parseFloat()`) | `number` |
|
|
195
|
+
| Cart item name | `item.product.name` | `item.name` |
|
|
196
|
+
| Order item name | `item.name` | `item.product.name` |
|
|
197
|
+
| Cart item image | `item.product.images[0]` | `item.image` |
|
|
198
|
+
| Order item image | `item.image` | `item.product.images` |
|
|
199
|
+
| Address state/province | `region` | `state` or `province` |
|
|
200
|
+
| OAuth redirect URL | `authorizationUrl` | `url` |
|
|
201
|
+
| OAuth providers response | `{ providers: [...] }` | `[...]` directly |
|
|
202
|
+
|
|
203
|
+
**If you think a type is "wrong", YOU are wrong. Read the SDK types!**
|
|
204
|
+
|
|
205
|
+
### 3. formatPrice Expects Options Object
|
|
168
206
|
|
|
169
207
|
```typescript
|
|
170
208
|
// ❌ WRONG
|
|
@@ -174,7 +212,7 @@ formatPrice(amount, 'USD');
|
|
|
174
212
|
formatPrice(amount, { currency: 'USD' });
|
|
175
213
|
```
|
|
176
214
|
|
|
177
|
-
###
|
|
215
|
+
### 4. Cart/Checkout vs Order - Different Item Structures!
|
|
178
216
|
|
|
179
217
|
**IMPORTANT:** Cart and Checkout items have NESTED product data. Order items are FLAT.
|
|
180
218
|
|
|
@@ -200,7 +238,7 @@ order.items.forEach((item) => {
|
|
|
200
238
|
| `CheckoutLineItem` | `item.product.name` | `item.product.images` |
|
|
201
239
|
| `OrderItem` | `item.name` | `item.image` |
|
|
202
240
|
|
|
203
|
-
###
|
|
241
|
+
### 5. Payment Status is 'succeeded', not 'completed'
|
|
204
242
|
|
|
205
243
|
```typescript
|
|
206
244
|
// ❌ WRONG
|
|
@@ -210,7 +248,7 @@ if (status.status === 'completed')
|
|
|
210
248
|
if (status.status === 'succeeded')
|
|
211
249
|
```
|
|
212
250
|
|
|
213
|
-
###
|
|
251
|
+
### 6. ProductSuggestion vs Product - Different Types
|
|
214
252
|
|
|
215
253
|
`getSearchSuggestions()` returns `ProductSuggestion[]`, NOT `Product[]`.
|
|
216
254
|
This is intentional - suggestions are lightweight for autocomplete.
|
|
@@ -224,7 +262,7 @@ This is intentional - suggestions are lightweight for autocomplete.
|
|
|
224
262
|
// Product has many more fields
|
|
225
263
|
```
|
|
226
264
|
|
|
227
|
-
###
|
|
265
|
+
### 7. All Prices Are Strings - Use parseFloat()
|
|
228
266
|
|
|
229
267
|
```typescript
|
|
230
268
|
// ❌ WRONG - assuming number
|
|
@@ -238,7 +276,7 @@ import { formatPrice } from 'omni-sync-sdk';
|
|
|
238
276
|
const display = formatPrice(item.price, { currency: 'USD' });
|
|
239
277
|
```
|
|
240
278
|
|
|
241
|
-
###
|
|
279
|
+
### 8. Variant Attributes Are `Record<string, string>`
|
|
242
280
|
|
|
243
281
|
```typescript
|
|
244
282
|
// Accessing variant attributes:
|
|
@@ -246,7 +284,7 @@ const color = variant.attributes?.['Color']; // string
|
|
|
246
284
|
const size = variant.attributes?.['Size']; // string
|
|
247
285
|
```
|
|
248
286
|
|
|
249
|
-
###
|
|
287
|
+
### 9. Address Uses `region`, NOT `state`
|
|
250
288
|
|
|
251
289
|
```typescript
|
|
252
290
|
// ❌ WRONG
|
|
@@ -266,7 +304,7 @@ const address: SetShippingAddressDto = {
|
|
|
266
304
|
};
|
|
267
305
|
```
|
|
268
306
|
|
|
269
|
-
###
|
|
307
|
+
### 10. OAuth - Use `authorizationUrl`, NOT `url`
|
|
270
308
|
|
|
271
309
|
```typescript
|
|
272
310
|
// ❌ WRONG
|
|
@@ -278,7 +316,7 @@ const response = await omni.getOAuthAuthorizeUrl('GOOGLE', { redirectUrl });
|
|
|
278
316
|
window.location.href = response.authorizationUrl; // Correct property name
|
|
279
317
|
```
|
|
280
318
|
|
|
281
|
-
###
|
|
319
|
+
### 11. OAuth Provider Type is Exported
|
|
282
320
|
|
|
283
321
|
```typescript
|
|
284
322
|
// ❌ WRONG - creating your own type
|
|
@@ -292,7 +330,7 @@ const provider: CustomerOAuthProvider = 'GOOGLE';
|
|
|
292
330
|
await omni.getOAuthAuthorizeUrl(provider, { redirectUrl });
|
|
293
331
|
```
|
|
294
332
|
|
|
295
|
-
###
|
|
333
|
+
### 12. getAvailableOAuthProviders Returns Object, Not Array
|
|
296
334
|
|
|
297
335
|
```typescript
|
|
298
336
|
// ❌ WRONG - expecting array directly
|
|
@@ -304,7 +342,7 @@ const response = await omni.getAvailableOAuthProviders();
|
|
|
304
342
|
response.providers.forEach(p => ...); // response.providers is the array
|
|
305
343
|
```
|
|
306
344
|
|
|
307
|
-
###
|
|
345
|
+
### 13. SDK Uses `null`, Not `undefined`
|
|
308
346
|
|
|
309
347
|
Optional fields in SDK types use `null`, not `undefined`:
|
|
310
348
|
|
|
@@ -320,7 +358,7 @@ if (product.slug !== null) {
|
|
|
320
358
|
}
|
|
321
359
|
```
|
|
322
360
|
|
|
323
|
-
###
|
|
361
|
+
### 14. Cart Has No `total` Field - Use `getCartTotals()` Helper
|
|
324
362
|
|
|
325
363
|
```typescript
|
|
326
364
|
// ❌ WRONG - these fields don't exist on Cart
|
|
@@ -344,7 +382,7 @@ const total = subtotal - discount;
|
|
|
344
382
|
- Cart has NO `total` field - use `getCartTotals()` or calculate
|
|
345
383
|
- Checkout DOES have a `total` field, but Cart does not
|
|
346
384
|
|
|
347
|
-
###
|
|
385
|
+
### 15. SearchSuggestions - Products Have `price`, Not `basePrice`
|
|
348
386
|
|
|
349
387
|
```typescript
|
|
350
388
|
// In SearchSuggestions, ProductSuggestion has:
|
|
@@ -358,7 +396,7 @@ suggestions.products.map(p => (
|
|
|
358
396
|
));
|
|
359
397
|
```
|
|
360
398
|
|
|
361
|
-
###
|
|
399
|
+
### 16. Forgetting to Clear Cart After Payment
|
|
362
400
|
|
|
363
401
|
**This causes "ghost items" in the cart after successful payment!**
|
|
364
402
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omni-sync-sdk",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.4",
|
|
4
4
|
"description": "Official SDK for building e-commerce storefronts with OmniSync Platform. Perfect for vibe-coded sites, AI-built stores (Cursor, Lovable, v0), and custom storefronts.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|