omni-sync-sdk 0.7.0 → 0.7.2

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/LICENSE ADDED
File without changes
package/README.md CHANGED
@@ -449,6 +449,8 @@ console.log(order.message); // 'Order created successfully'
449
449
  // Cart is automatically cleared after successful order
450
450
  ```
451
451
 
452
+ > **🔄 Automatic Tracking:** If "Track Guest Checkouts" is enabled in your connection settings (OmniSync Admin), `submitGuestOrder()` will automatically create a tracked checkout session before placing the order. This allows you to see abandoned carts and checkout sessions in your admin dashboard - **no code changes needed!**
453
+
452
454
  #### Keep Cart After Order
453
455
 
454
456
  ```typescript
@@ -498,31 +500,26 @@ interface GuestOrderResponse {
498
500
 
499
501
  ---
500
502
 
501
- ### Tracked Guest Checkout (Optional)
503
+ ### Tracked Guest Checkout (Automatic)
504
+
505
+ > **Note:** As of SDK v0.7.1, `submitGuestOrder()` automatically handles tracking. You don't need to use these methods unless you want explicit control over the checkout flow.
502
506
 
503
- By default, guest checkouts are stored only in localStorage until the order is placed. If you want the store admin to see checkout sessions and abandoned carts, you can enable **Guest Checkout Tracking** in the connection settings.
507
+ When **"Track Guest Checkouts"** is enabled in your connection settings, checkout sessions are automatically created on the server, allowing:
504
508
 
505
- When enabled, checkout sessions are created on the server, allowing:
506
509
  - Visibility of checkout sessions in admin dashboard
507
510
  - Abandoned cart tracking
508
511
  - Future: abandoned cart recovery emails
509
512
 
510
- #### Check if Tracking is Available
513
+ #### How to Enable
511
514
 
512
- ```typescript
513
- // When customer goes to checkout page
514
- const result = await omni.startGuestCheckout();
515
+ 1. Go to OmniSync Admin → Integrations → Vibe-Coded Sites
516
+ 2. Click on your connection Settings
517
+ 3. Enable "Track Guest Checkouts"
518
+ 4. Save - that's it! No code changes needed.
515
519
 
516
- if (result.tracked) {
517
- // Tracking is enabled - use tracked flow
518
- console.log('Checkout session created:', result.checkoutId);
519
- } else {
520
- // Tracking not enabled - use regular flow
521
- console.log('Using local-only checkout');
522
- }
523
- ```
520
+ #### Advanced: Manual Tracking Control
524
521
 
525
- #### Tracked Checkout Flow
522
+ If you need explicit control over the tracking flow (e.g., to track checkout steps before the user places an order):
526
523
 
527
524
  ```typescript
528
525
  // 1. Start tracked checkout (sends cart items to server)
package/dist/index.d.mts CHANGED
@@ -1983,7 +1983,10 @@ declare class OmniSyncClient {
1983
1983
  /**
1984
1984
  * Create order directly from local cart (guest checkout)
1985
1985
  * This is the main checkout method for vibe-coded sites!
1986
- * Sends cart data to server and creates order in ONE API call.
1986
+ *
1987
+ * **Automatic Tracking:** If "Track Guest Checkouts" is enabled in the connection
1988
+ * settings, this method will automatically create a tracked checkout session
1989
+ * (visible in admin) before creating the order. No code changes needed!
1987
1990
  *
1988
1991
  * @example
1989
1992
  * ```typescript
@@ -1992,12 +1995,11 @@ declare class OmniSyncClient {
1992
1995
  * omni.setLocalCartCustomer({ email: 'john@example.com', firstName: 'John' });
1993
1996
  * omni.setLocalCartShippingAddress({ ... });
1994
1997
  *
1995
- * // Then submit the order
1998
+ * // Then submit the order - tracking is automatic if enabled in admin!
1996
1999
  * const result = await omni.submitGuestOrder();
1997
2000
  * console.log('Order created:', result.orderId);
1998
2001
  *
1999
- * // Clear cart after successful order
2000
- * omni.clearLocalCart();
2002
+ * // Cart is automatically cleared on success
2001
2003
  * ```
2002
2004
  */
2003
2005
  submitGuestOrder(options?: {
@@ -2049,9 +2051,7 @@ declare class OmniSyncClient {
2049
2051
  */
2050
2052
  completeGuestCheckout(checkoutId: string, options?: {
2051
2053
  clearCartOnSuccess?: boolean;
2052
- }): Promise<{
2053
- orderId: string;
2054
- }>;
2054
+ }): Promise<GuestOrderResponse>;
2055
2055
  /**
2056
2056
  * Create order from custom data (not from local cart)
2057
2057
  * Use this if you manage cart state yourself
package/dist/index.d.ts CHANGED
@@ -1983,7 +1983,10 @@ declare class OmniSyncClient {
1983
1983
  /**
1984
1984
  * Create order directly from local cart (guest checkout)
1985
1985
  * This is the main checkout method for vibe-coded sites!
1986
- * Sends cart data to server and creates order in ONE API call.
1986
+ *
1987
+ * **Automatic Tracking:** If "Track Guest Checkouts" is enabled in the connection
1988
+ * settings, this method will automatically create a tracked checkout session
1989
+ * (visible in admin) before creating the order. No code changes needed!
1987
1990
  *
1988
1991
  * @example
1989
1992
  * ```typescript
@@ -1992,12 +1995,11 @@ declare class OmniSyncClient {
1992
1995
  * omni.setLocalCartCustomer({ email: 'john@example.com', firstName: 'John' });
1993
1996
  * omni.setLocalCartShippingAddress({ ... });
1994
1997
  *
1995
- * // Then submit the order
1998
+ * // Then submit the order - tracking is automatic if enabled in admin!
1996
1999
  * const result = await omni.submitGuestOrder();
1997
2000
  * console.log('Order created:', result.orderId);
1998
2001
  *
1999
- * // Clear cart after successful order
2000
- * omni.clearLocalCart();
2002
+ * // Cart is automatically cleared on success
2001
2003
  * ```
2002
2004
  */
2003
2005
  submitGuestOrder(options?: {
@@ -2049,9 +2051,7 @@ declare class OmniSyncClient {
2049
2051
  */
2050
2052
  completeGuestCheckout(checkoutId: string, options?: {
2051
2053
  clearCartOnSuccess?: boolean;
2052
- }): Promise<{
2053
- orderId: string;
2054
- }>;
2054
+ }): Promise<GuestOrderResponse>;
2055
2055
  /**
2056
2056
  * Create order from custom data (not from local cart)
2057
2057
  * Use this if you manage cart state yourself
package/dist/index.js CHANGED
@@ -1705,7 +1705,10 @@ var OmniSyncClient = class {
1705
1705
  /**
1706
1706
  * Create order directly from local cart (guest checkout)
1707
1707
  * This is the main checkout method for vibe-coded sites!
1708
- * Sends cart data to server and creates order in ONE API call.
1708
+ *
1709
+ * **Automatic Tracking:** If "Track Guest Checkouts" is enabled in the connection
1710
+ * settings, this method will automatically create a tracked checkout session
1711
+ * (visible in admin) before creating the order. No code changes needed!
1709
1712
  *
1710
1713
  * @example
1711
1714
  * ```typescript
@@ -1714,12 +1717,11 @@ var OmniSyncClient = class {
1714
1717
  * omni.setLocalCartCustomer({ email: 'john@example.com', firstName: 'John' });
1715
1718
  * omni.setLocalCartShippingAddress({ ... });
1716
1719
  *
1717
- * // Then submit the order
1720
+ * // Then submit the order - tracking is automatic if enabled in admin!
1718
1721
  * const result = await omni.submitGuestOrder();
1719
1722
  * console.log('Order created:', result.orderId);
1720
1723
  *
1721
- * // Clear cart after successful order
1722
- * omni.clearLocalCart();
1724
+ * // Cart is automatically cleared on success
1723
1725
  * ```
1724
1726
  */
1725
1727
  async submitGuestOrder(options) {
@@ -1733,6 +1735,26 @@ var OmniSyncClient = class {
1733
1735
  if (!cart.shippingAddress) {
1734
1736
  throw new OmniSyncError("Shipping address is required", 400);
1735
1737
  }
1738
+ try {
1739
+ const trackingResult = await this.startGuestCheckout();
1740
+ if (trackingResult.tracked) {
1741
+ await this.updateGuestCheckoutAddress(trackingResult.checkoutId, {
1742
+ shippingAddress: cart.shippingAddress,
1743
+ billingAddress: cart.billingAddress
1744
+ });
1745
+ const orderResult = await this.completeGuestCheckout(trackingResult.checkoutId, {
1746
+ clearCartOnSuccess: options?.clearCartOnSuccess
1747
+ });
1748
+ return {
1749
+ orderId: orderResult.orderId,
1750
+ orderNumber: orderResult.orderNumber || orderResult.orderId,
1751
+ status: orderResult.status || "pending",
1752
+ total: orderResult.total ?? 0,
1753
+ message: orderResult.message || "Order created successfully"
1754
+ };
1755
+ }
1756
+ } catch {
1757
+ }
1736
1758
  const orderData = {
1737
1759
  items: cart.items.map((item) => ({
1738
1760
  productId: item.productId,
package/dist/index.mjs CHANGED
@@ -1680,7 +1680,10 @@ var OmniSyncClient = class {
1680
1680
  /**
1681
1681
  * Create order directly from local cart (guest checkout)
1682
1682
  * This is the main checkout method for vibe-coded sites!
1683
- * Sends cart data to server and creates order in ONE API call.
1683
+ *
1684
+ * **Automatic Tracking:** If "Track Guest Checkouts" is enabled in the connection
1685
+ * settings, this method will automatically create a tracked checkout session
1686
+ * (visible in admin) before creating the order. No code changes needed!
1684
1687
  *
1685
1688
  * @example
1686
1689
  * ```typescript
@@ -1689,12 +1692,11 @@ var OmniSyncClient = class {
1689
1692
  * omni.setLocalCartCustomer({ email: 'john@example.com', firstName: 'John' });
1690
1693
  * omni.setLocalCartShippingAddress({ ... });
1691
1694
  *
1692
- * // Then submit the order
1695
+ * // Then submit the order - tracking is automatic if enabled in admin!
1693
1696
  * const result = await omni.submitGuestOrder();
1694
1697
  * console.log('Order created:', result.orderId);
1695
1698
  *
1696
- * // Clear cart after successful order
1697
- * omni.clearLocalCart();
1699
+ * // Cart is automatically cleared on success
1698
1700
  * ```
1699
1701
  */
1700
1702
  async submitGuestOrder(options) {
@@ -1708,6 +1710,26 @@ var OmniSyncClient = class {
1708
1710
  if (!cart.shippingAddress) {
1709
1711
  throw new OmniSyncError("Shipping address is required", 400);
1710
1712
  }
1713
+ try {
1714
+ const trackingResult = await this.startGuestCheckout();
1715
+ if (trackingResult.tracked) {
1716
+ await this.updateGuestCheckoutAddress(trackingResult.checkoutId, {
1717
+ shippingAddress: cart.shippingAddress,
1718
+ billingAddress: cart.billingAddress
1719
+ });
1720
+ const orderResult = await this.completeGuestCheckout(trackingResult.checkoutId, {
1721
+ clearCartOnSuccess: options?.clearCartOnSuccess
1722
+ });
1723
+ return {
1724
+ orderId: orderResult.orderId,
1725
+ orderNumber: orderResult.orderNumber || orderResult.orderId,
1726
+ status: orderResult.status || "pending",
1727
+ total: orderResult.total ?? 0,
1728
+ message: orderResult.message || "Order created successfully"
1729
+ };
1730
+ }
1731
+ } catch {
1732
+ }
1711
1733
  const orderData = {
1712
1734
  items: cart.items.map((item) => ({
1713
1735
  productId: item.productId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-sync-sdk",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
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",
@@ -16,14 +16,6 @@
16
16
  "dist",
17
17
  "README.md"
18
18
  ],
19
- "scripts": {
20
- "build": "tsup src/index.ts --format cjs,esm --dts",
21
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
22
- "lint": "eslint \"src/**/*.ts\"",
23
- "test": "vitest run",
24
- "test:watch": "vitest",
25
- "prepublishOnly": "pnpm build"
26
- },
27
19
  "keywords": [
28
20
  "omni-sync",
29
21
  "e-commerce",
@@ -72,5 +64,12 @@
72
64
  "typescript": {
73
65
  "optional": true
74
66
  }
67
+ },
68
+ "scripts": {
69
+ "build": "tsup src/index.ts --format cjs,esm --dts",
70
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
71
+ "lint": "eslint \"src/**/*.ts\"",
72
+ "test": "vitest run",
73
+ "test:watch": "vitest"
75
74
  }
76
- }
75
+ }