omni-sync-sdk 0.4.1 → 0.6.1

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.d.mts CHANGED
@@ -69,6 +69,7 @@ interface Product {
69
69
  id: string;
70
70
  name: string;
71
71
  description?: string | null;
72
+ descriptionFormat?: 'text' | 'html' | 'markdown';
72
73
  sku: string;
73
74
  basePrice: number;
74
75
  salePrice?: number | null;
@@ -537,6 +538,108 @@ interface MergeCartsDto {
537
538
  sourceSessionToken: string;
538
539
  targetCustomerId: string;
539
540
  }
541
+ /**
542
+ * Local cart item stored in localStorage/cookies
543
+ * Used for guest checkout without server-side cart
544
+ */
545
+ interface LocalCartItem {
546
+ productId: string;
547
+ variantId?: string;
548
+ quantity: number;
549
+ name?: string;
550
+ sku?: string;
551
+ price?: string;
552
+ image?: string;
553
+ addedAt: string;
554
+ }
555
+ /**
556
+ * Local cart stored in localStorage/cookies
557
+ * Complete client-side cart for guest users
558
+ */
559
+ interface LocalCart {
560
+ items: LocalCartItem[];
561
+ couponCode?: string;
562
+ customer?: {
563
+ email: string;
564
+ firstName?: string;
565
+ lastName?: string;
566
+ phone?: string;
567
+ };
568
+ shippingAddress?: {
569
+ firstName: string;
570
+ lastName: string;
571
+ line1: string;
572
+ line2?: string;
573
+ city: string;
574
+ region?: string;
575
+ postalCode: string;
576
+ country: string;
577
+ phone?: string;
578
+ };
579
+ billingAddress?: {
580
+ firstName: string;
581
+ lastName: string;
582
+ line1: string;
583
+ line2?: string;
584
+ city: string;
585
+ region?: string;
586
+ postalCode: string;
587
+ country: string;
588
+ phone?: string;
589
+ };
590
+ notes?: string;
591
+ updatedAt: string;
592
+ }
593
+ /**
594
+ * DTO for creating order directly (guest checkout)
595
+ */
596
+ interface CreateGuestOrderDto {
597
+ items: Array<{
598
+ productId: string;
599
+ variantId?: string;
600
+ quantity: number;
601
+ }>;
602
+ customer: {
603
+ email: string;
604
+ firstName?: string;
605
+ lastName?: string;
606
+ phone?: string;
607
+ };
608
+ shippingAddress: {
609
+ firstName: string;
610
+ lastName: string;
611
+ line1: string;
612
+ line2?: string;
613
+ city: string;
614
+ region?: string;
615
+ postalCode: string;
616
+ country: string;
617
+ phone?: string;
618
+ };
619
+ billingAddress?: {
620
+ firstName: string;
621
+ lastName: string;
622
+ line1: string;
623
+ line2?: string;
624
+ city: string;
625
+ region?: string;
626
+ postalCode: string;
627
+ country: string;
628
+ phone?: string;
629
+ };
630
+ couponCode?: string;
631
+ notes?: string;
632
+ }
633
+ /**
634
+ * Response from guest order creation
635
+ */
636
+ interface GuestOrderResponse {
637
+ orderId: string;
638
+ orderNumber: string;
639
+ status: string;
640
+ total: number;
641
+ message: string;
642
+ }
540
643
  type CheckoutStatus = 'PENDING' | 'SHIPPING_SET' | 'PAYMENT_PENDING' | 'PAYMENT_PROCESSING' | 'COMPLETED' | 'FAILED' | 'EXPIRED';
541
644
  interface CheckoutAddress {
542
645
  firstName: string;
@@ -823,6 +926,63 @@ interface PublishProductResponse {
823
926
  error?: string;
824
927
  }>;
825
928
  }
929
+ type CustomApiAuthType = 'api_key' | 'bearer' | 'basic' | 'oauth2';
930
+ type CustomApiSyncDirection = 'inbound' | 'outbound' | 'bidirectional';
931
+ type CustomApiConnectionStatus = 'CONNECTED' | 'DISCONNECTED' | 'PAUSED' | 'ERROR';
932
+ interface CustomApiCredentials {
933
+ apiKey?: string;
934
+ bearerToken?: string;
935
+ username?: string;
936
+ password?: string;
937
+ headerName?: string;
938
+ }
939
+ interface CustomApiSyncConfig {
940
+ products?: boolean;
941
+ orders?: boolean;
942
+ inventory?: boolean;
943
+ }
944
+ interface CustomApiIntegration {
945
+ id: string;
946
+ storeId: string;
947
+ name: string;
948
+ description?: string | null;
949
+ baseUrl: string;
950
+ authType: CustomApiAuthType;
951
+ credentials?: CustomApiCredentials;
952
+ status: CustomApiConnectionStatus;
953
+ enabled: boolean;
954
+ syncDirection: CustomApiSyncDirection;
955
+ syncConfig?: CustomApiSyncConfig | null;
956
+ lastSyncAt?: string | null;
957
+ lastError?: string | null;
958
+ lastErrorAt?: string | null;
959
+ createdAt: string;
960
+ updatedAt: string;
961
+ }
962
+ interface CreateCustomApiDto {
963
+ name: string;
964
+ description?: string;
965
+ baseUrl: string;
966
+ authType: CustomApiAuthType;
967
+ credentials?: CustomApiCredentials;
968
+ syncDirection?: CustomApiSyncDirection;
969
+ syncConfig?: CustomApiSyncConfig;
970
+ }
971
+ interface UpdateCustomApiDto {
972
+ name?: string;
973
+ description?: string;
974
+ baseUrl?: string;
975
+ authType?: CustomApiAuthType;
976
+ credentials?: CustomApiCredentials;
977
+ enabled?: boolean;
978
+ syncDirection?: CustomApiSyncDirection;
979
+ syncConfig?: CustomApiSyncConfig;
980
+ }
981
+ interface CustomApiTestResult {
982
+ success: boolean;
983
+ latency?: number;
984
+ error?: string;
985
+ }
826
986
  interface OmniSyncApiError {
827
987
  statusCode: number;
828
988
  message: string;
@@ -1556,7 +1716,7 @@ declare class OmniSyncClient {
1556
1716
  * await omni.clearCart('cart_123');
1557
1717
  * ```
1558
1718
  */
1559
- clearCart(cartId: string): Promise<void>;
1719
+ clearCart(cartId: string): Promise<Cart>;
1560
1720
  /**
1561
1721
  * Apply a coupon to the cart
1562
1722
  *
@@ -1700,6 +1860,149 @@ declare class OmniSyncClient {
1700
1860
  * ```
1701
1861
  */
1702
1862
  completeCheckout(checkoutId: string): Promise<CompleteCheckoutResponse>;
1863
+ private readonly LOCAL_CART_KEY;
1864
+ /**
1865
+ * Check if localStorage is available (browser environment)
1866
+ */
1867
+ private isLocalStorageAvailable;
1868
+ /**
1869
+ * Get local cart from localStorage
1870
+ * Returns empty cart if none exists
1871
+ *
1872
+ * @example
1873
+ * ```typescript
1874
+ * const cart = omni.getLocalCart();
1875
+ * console.log('Items in cart:', cart.items.length);
1876
+ * ```
1877
+ */
1878
+ getLocalCart(): LocalCart;
1879
+ /**
1880
+ * Save local cart to localStorage
1881
+ */
1882
+ private saveLocalCart;
1883
+ /**
1884
+ * Add item to local cart (NO API call)
1885
+ * If item already exists, updates quantity
1886
+ *
1887
+ * @example
1888
+ * ```typescript
1889
+ * omni.addToLocalCart({
1890
+ * productId: 'prod_123',
1891
+ * quantity: 2,
1892
+ * name: 'Cool Shirt',
1893
+ * price: '29.99',
1894
+ * });
1895
+ * ```
1896
+ */
1897
+ addToLocalCart(item: Omit<LocalCartItem, 'addedAt'>): LocalCart;
1898
+ /**
1899
+ * Update item quantity in local cart
1900
+ * Set quantity to 0 to remove item
1901
+ *
1902
+ * @example
1903
+ * ```typescript
1904
+ * omni.updateLocalCartItem('prod_123', 3); // Set quantity to 3
1905
+ * omni.updateLocalCartItem('prod_123', 0); // Remove item
1906
+ * ```
1907
+ */
1908
+ updateLocalCartItem(productId: string, quantity: number, variantId?: string): LocalCart;
1909
+ /**
1910
+ * Remove item from local cart
1911
+ *
1912
+ * @example
1913
+ * ```typescript
1914
+ * omni.removeFromLocalCart('prod_123');
1915
+ * omni.removeFromLocalCart('prod_456', 'variant_789');
1916
+ * ```
1917
+ */
1918
+ removeFromLocalCart(productId: string, variantId?: string): LocalCart;
1919
+ /**
1920
+ * Clear all items from local cart
1921
+ *
1922
+ * @example
1923
+ * ```typescript
1924
+ * omni.clearLocalCart();
1925
+ * ```
1926
+ */
1927
+ clearLocalCart(): LocalCart;
1928
+ /**
1929
+ * Set customer info on local cart
1930
+ *
1931
+ * @example
1932
+ * ```typescript
1933
+ * omni.setLocalCartCustomer({
1934
+ * email: 'john@example.com',
1935
+ * firstName: 'John',
1936
+ * lastName: 'Doe',
1937
+ * });
1938
+ * ```
1939
+ */
1940
+ setLocalCartCustomer(customer: LocalCart['customer']): LocalCart;
1941
+ /**
1942
+ * Set shipping address on local cart
1943
+ *
1944
+ * @example
1945
+ * ```typescript
1946
+ * omni.setLocalCartShippingAddress({
1947
+ * firstName: 'John',
1948
+ * lastName: 'Doe',
1949
+ * line1: '123 Main St',
1950
+ * city: 'Tel Aviv',
1951
+ * postalCode: '6100000',
1952
+ * country: 'IL',
1953
+ * });
1954
+ * ```
1955
+ */
1956
+ setLocalCartShippingAddress(address: LocalCart['shippingAddress']): LocalCart;
1957
+ /**
1958
+ * Set billing address on local cart
1959
+ */
1960
+ setLocalCartBillingAddress(address: LocalCart['billingAddress']): LocalCart;
1961
+ /**
1962
+ * Set coupon code on local cart
1963
+ */
1964
+ setLocalCartCoupon(couponCode: string | undefined): LocalCart;
1965
+ /**
1966
+ * Get total items count in local cart
1967
+ */
1968
+ getLocalCartItemCount(): number;
1969
+ /**
1970
+ * Create order directly from local cart (guest checkout)
1971
+ * This is the main checkout method for vibe-coded sites!
1972
+ * Sends cart data to server and creates order in ONE API call.
1973
+ *
1974
+ * @example
1975
+ * ```typescript
1976
+ * // Build up the local cart first
1977
+ * omni.addToLocalCart({ productId: 'prod_123', quantity: 2 });
1978
+ * omni.setLocalCartCustomer({ email: 'john@example.com', firstName: 'John' });
1979
+ * omni.setLocalCartShippingAddress({ ... });
1980
+ *
1981
+ * // Then submit the order
1982
+ * const result = await omni.submitGuestOrder();
1983
+ * console.log('Order created:', result.orderId);
1984
+ *
1985
+ * // Clear cart after successful order
1986
+ * omni.clearLocalCart();
1987
+ * ```
1988
+ */
1989
+ submitGuestOrder(options?: {
1990
+ clearCartOnSuccess?: boolean;
1991
+ }): Promise<GuestOrderResponse>;
1992
+ /**
1993
+ * Create order from custom data (not from local cart)
1994
+ * Use this if you manage cart state yourself
1995
+ *
1996
+ * @example
1997
+ * ```typescript
1998
+ * const result = await omni.createGuestOrder({
1999
+ * items: [{ productId: 'prod_123', quantity: 2 }],
2000
+ * customer: { email: 'john@example.com' },
2001
+ * shippingAddress: { firstName: 'John', ... },
2002
+ * });
2003
+ * ```
2004
+ */
2005
+ createGuestOrder(data: CreateGuestOrderDto): Promise<GuestOrderResponse>;
1703
2006
  /**
1704
2007
  * Get the current customer's profile (requires customerToken)
1705
2008
  * Only available in storefront mode
@@ -1756,6 +2059,92 @@ declare class OmniSyncClient {
1756
2059
  * Only available in storefront mode
1757
2060
  */
1758
2061
  getMyCart(): Promise<Cart>;
2062
+ /**
2063
+ * Get all Custom API integrations for a store
2064
+ * Requires Admin mode (apiKey)
2065
+ *
2066
+ * @example
2067
+ * ```typescript
2068
+ * const integrations = await omni.getCustomApiIntegrations();
2069
+ * integrations.forEach(api => {
2070
+ * console.log(`${api.name}: ${api.status}`);
2071
+ * });
2072
+ * ```
2073
+ */
2074
+ getCustomApiIntegrations(): Promise<CustomApiIntegration[]>;
2075
+ /**
2076
+ * Get a single Custom API integration by ID
2077
+ * Requires Admin mode (apiKey)
2078
+ *
2079
+ * @example
2080
+ * ```typescript
2081
+ * const api = await omni.getCustomApiIntegration('api_123');
2082
+ * console.log(`API: ${api.name}, URL: ${api.baseUrl}`);
2083
+ * ```
2084
+ */
2085
+ getCustomApiIntegration(integrationId: string): Promise<CustomApiIntegration>;
2086
+ /**
2087
+ * Create a new Custom API integration
2088
+ * Requires Admin mode (apiKey)
2089
+ *
2090
+ * @example
2091
+ * ```typescript
2092
+ * const api = await omni.createCustomApiIntegration({
2093
+ * name: 'My External API',
2094
+ * baseUrl: 'https://api.example.com',
2095
+ * authType: 'api_key',
2096
+ * credentials: {
2097
+ * apiKey: 'sk_123...',
2098
+ * headerName: 'X-API-Key',
2099
+ * },
2100
+ * syncDirection: 'bidirectional',
2101
+ * syncConfig: {
2102
+ * products: true,
2103
+ * orders: true,
2104
+ * inventory: true,
2105
+ * },
2106
+ * });
2107
+ * ```
2108
+ */
2109
+ createCustomApiIntegration(data: CreateCustomApiDto): Promise<CustomApiIntegration>;
2110
+ /**
2111
+ * Update a Custom API integration
2112
+ * Requires Admin mode (apiKey)
2113
+ *
2114
+ * @example
2115
+ * ```typescript
2116
+ * const api = await omni.updateCustomApiIntegration('api_123', {
2117
+ * enabled: false,
2118
+ * syncConfig: { products: true, orders: false, inventory: true },
2119
+ * });
2120
+ * ```
2121
+ */
2122
+ updateCustomApiIntegration(integrationId: string, data: UpdateCustomApiDto): Promise<CustomApiIntegration>;
2123
+ /**
2124
+ * Delete a Custom API integration
2125
+ * Requires Admin mode (apiKey)
2126
+ *
2127
+ * @example
2128
+ * ```typescript
2129
+ * await omni.deleteCustomApiIntegration('api_123');
2130
+ * ```
2131
+ */
2132
+ deleteCustomApiIntegration(integrationId: string): Promise<void>;
2133
+ /**
2134
+ * Test connection to a Custom API
2135
+ * Requires Admin mode (apiKey)
2136
+ *
2137
+ * @example
2138
+ * ```typescript
2139
+ * const result = await omni.testCustomApiConnection('api_123');
2140
+ * if (result.success) {
2141
+ * console.log(`Connection OK, latency: ${result.latency}ms`);
2142
+ * } else {
2143
+ * console.error(`Connection failed: ${result.error}`);
2144
+ * }
2145
+ * ```
2146
+ */
2147
+ testCustomApiConnection(integrationId: string): Promise<CustomApiTestResult>;
1759
2148
  }
1760
2149
  /**
1761
2150
  * Custom error class for Omni-Sync API errors
@@ -1823,4 +2212,4 @@ declare function isWebhookEventType(event: WebhookEvent, type: WebhookEventType)
1823
2212
  */
1824
2213
  declare function createWebhookHandler(handlers: Partial<Record<WebhookEventType, (event: WebhookEvent) => Promise<void>>>): (payload: unknown) => Promise<void>;
1825
2214
 
1826
- export { type AddToCartDto, type AppliedDiscount, type ApplyCouponDto, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type Cart, type CartItem, type CartStatus, type Checkout, type CheckoutAddress, type CheckoutLineItem, type CheckoutStatus, type CompleteCheckoutResponse, type CompleteDraftDto, type ConnectorPlatform, type Coupon, type CouponCreateResponse, type CouponQueryParams, type CouponStatus, type CouponType, type CouponValidationWarning, type CreateAddressDto, type CreateCheckoutDto, type CreateCouponDto, type CreateCustomerDto, type CreateOrderDto, type CreateProductDto, type CreateRefundDto, type CreateVariantDto, type Customer, type CustomerAddress, type CustomerAuthResponse, type CustomerProfile, type CustomerQueryParams, type DraftLineItem, type EditInventoryDto, type FulfillOrderDto, type InventoryInfo, type InventorySyncStatus, type MergeCartsDto, type OmniSyncApiError, OmniSyncClient, type OmniSyncClientOptions, OmniSyncError, type Order, type OrderAddress, type OrderCustomer, type OrderItem, type OrderQueryParams, type OrderStatus, type PaginatedResponse, type PlatformCouponCapabilities, type Product, type ProductAttributeInput, type ProductImage, type ProductQueryParams, type ProductVariant, type PublishProductResponse, type ReconcileInventoryResponse, type Refund, type RefundLineItem, type RefundLineItemResponse, type RefundType, type RegisterCustomerDto, type SelectShippingMethodDto, type SendInvoiceDto, type SetBillingAddressDto, type SetCheckoutCustomerDto, type SetShippingAddressDto, type SetShippingAddressResponse, type ShippingLine, type ShippingRate, type StoreInfo, type SyncJob, type UpdateAddressDto, type UpdateCartItemDto, type UpdateCouponDto, type UpdateCustomerDto, type UpdateDraftDto, type UpdateInventoryDto, type UpdateOrderDto, type UpdateOrderShippingDto, type UpdateProductDto, type UpdateVariantDto, type UpdateVariantInventoryDto, type VariantInventoryResponse, type VariantPlatformOverlay, type VariantStatus, type WebhookEvent, type WebhookEventType, createWebhookHandler, isCouponApplicableToProduct, isWebhookEventType, parseWebhookEvent, verifyWebhook };
2215
+ export { type AddToCartDto, type AppliedDiscount, type ApplyCouponDto, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type Cart, type CartItem, type CartStatus, type Checkout, type CheckoutAddress, type CheckoutLineItem, type CheckoutStatus, type CompleteCheckoutResponse, type CompleteDraftDto, type ConnectorPlatform, type Coupon, type CouponCreateResponse, type CouponQueryParams, type CouponStatus, type CouponType, type CouponValidationWarning, type CreateAddressDto, type CreateCheckoutDto, type CreateCouponDto, type CreateCustomApiDto, type CreateCustomerDto, type CreateGuestOrderDto, type CreateOrderDto, type CreateProductDto, type CreateRefundDto, type CreateVariantDto, type CustomApiAuthType, type CustomApiConnectionStatus, type CustomApiCredentials, type CustomApiIntegration, type CustomApiSyncConfig, type CustomApiSyncDirection, type CustomApiTestResult, type Customer, type CustomerAddress, type CustomerAuthResponse, type CustomerProfile, type CustomerQueryParams, type DraftLineItem, type EditInventoryDto, type FulfillOrderDto, type GuestOrderResponse, type InventoryInfo, type InventorySyncStatus, type LocalCart, type LocalCartItem, type MergeCartsDto, type OmniSyncApiError, OmniSyncClient, type OmniSyncClientOptions, OmniSyncError, type Order, type OrderAddress, type OrderCustomer, type OrderItem, type OrderQueryParams, type OrderStatus, type PaginatedResponse, type PlatformCouponCapabilities, type Product, type ProductAttributeInput, type ProductImage, type ProductQueryParams, type ProductVariant, type PublishProductResponse, type ReconcileInventoryResponse, type Refund, type RefundLineItem, type RefundLineItemResponse, type RefundType, type RegisterCustomerDto, type SelectShippingMethodDto, type SendInvoiceDto, type SetBillingAddressDto, type SetCheckoutCustomerDto, type SetShippingAddressDto, type SetShippingAddressResponse, type ShippingLine, type ShippingRate, type StoreInfo, type SyncJob, type UpdateAddressDto, type UpdateCartItemDto, type UpdateCouponDto, type UpdateCustomApiDto, type UpdateCustomerDto, type UpdateDraftDto, type UpdateInventoryDto, type UpdateOrderDto, type UpdateOrderShippingDto, type UpdateProductDto, type UpdateVariantDto, type UpdateVariantInventoryDto, type VariantInventoryResponse, type VariantPlatformOverlay, type VariantStatus, type WebhookEvent, type WebhookEventType, createWebhookHandler, isCouponApplicableToProduct, isWebhookEventType, parseWebhookEvent, verifyWebhook };