omni-sync-sdk 0.2.0 → 0.3.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.d.ts CHANGED
@@ -1,8 +1,41 @@
1
1
  interface OmniSyncClientOptions {
2
2
  /**
3
- * API Key for authentication (starts with "omni_")
3
+ * Connection ID for vibe-coded sites (starts with "vc_").
4
+ * This is the simplest way to connect - just use your Connection ID!
5
+ * Safe to use in frontend applications.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Vibe-coded site usage - simplest option!
10
+ * const omni = new OmniSyncClient({
11
+ * connectionId: 'vc_abc123xyz...',
12
+ * });
13
+ * const products = await omni.getProducts();
14
+ * ```
4
15
  */
5
- apiKey: string;
16
+ connectionId?: string;
17
+ /**
18
+ * Store ID for public storefront access (no API key needed).
19
+ * Use this for frontend/browser applications.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Frontend usage - safe to expose
24
+ * const omni = new OmniSyncClient({ storeId: 'store_abc123' });
25
+ * ```
26
+ */
27
+ storeId?: string;
28
+ /**
29
+ * API Key for admin/backend access (starts with "omni_").
30
+ * Keep this secret - never expose in frontend code!
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Backend usage - keep secret
35
+ * const omni = new OmniSyncClient({ apiKey: process.env.OMNI_API_KEY });
36
+ * ```
37
+ */
38
+ apiKey?: string;
6
39
  /**
7
40
  * Base URL of the Omni-Sync API
8
41
  * @default "https://api.omni-sync.com"
@@ -14,6 +47,24 @@ interface OmniSyncClientOptions {
14
47
  */
15
48
  timeout?: number;
16
49
  }
50
+ interface StoreInfo {
51
+ id: string;
52
+ name: string;
53
+ currency: string;
54
+ language: string;
55
+ }
56
+ interface CustomerProfile {
57
+ id: string;
58
+ email: string;
59
+ firstName?: string;
60
+ lastName?: string;
61
+ phone?: string;
62
+ emailVerified: boolean;
63
+ acceptsMarketing: boolean;
64
+ addresses: CustomerAddress[];
65
+ createdAt: string;
66
+ updatedAt: string;
67
+ }
17
68
  interface Product {
18
69
  id: string;
19
70
  name: string;
@@ -780,37 +831,99 @@ interface OmniSyncApiError {
780
831
  }
781
832
 
782
833
  /**
783
- * OmniSyncClient - SDK for integrating vibe coding stores with Omni-Sync Platform
834
+ * OmniSyncClient - SDK for integrating stores with Omni-Sync Platform
784
835
  *
785
- * @example
836
+ * Three modes of operation:
837
+ *
838
+ * **Vibe-Coded Mode (Simplest)** - Use connectionId for vibe-coded sites:
786
839
  * ```typescript
787
- * const omni = new OmniSyncClient({
788
- * apiKey: process.env.OMNI_SYNC_API_KEY!,
789
- * });
840
+ * const omni = new OmniSyncClient({ connectionId: 'vc_abc123...' });
841
+ * const products = await omni.getProducts();
842
+ * ```
790
843
  *
791
- * // Get products
844
+ * **Storefront Mode (Frontend)** - Use storeId for public access:
845
+ * ```typescript
846
+ * const omni = new OmniSyncClient({ storeId: 'store_abc123' });
792
847
  * const products = await omni.getProducts();
848
+ * ```
793
849
  *
794
- * // Create an order
795
- * const order = await omni.createOrder({
796
- * items: [{ productId: 'prod_123', quantity: 2, price: 99.99 }],
797
- * customer: { email: 'customer@example.com', name: 'John Doe' },
798
- * totalAmount: 199.98,
799
- * });
850
+ * **Admin Mode (Backend)** - Use apiKey for full access:
851
+ * ```typescript
852
+ * const omni = new OmniSyncClient({ apiKey: process.env.OMNI_API_KEY });
853
+ * const orders = await omni.getOrders();
800
854
  * ```
801
855
  */
802
856
  declare class OmniSyncClient {
803
- private readonly apiKey;
857
+ private readonly apiKey?;
858
+ private readonly storeId?;
859
+ private readonly connectionId?;
804
860
  private readonly baseUrl;
805
861
  private readonly timeout;
862
+ private customerToken;
806
863
  constructor(options: OmniSyncClientOptions);
864
+ /**
865
+ * Check if client is in vibe-coded mode (using connectionId)
866
+ */
867
+ isVibeCodedMode(): boolean;
868
+ /**
869
+ * Check if client is in storefront mode (using storeId)
870
+ */
871
+ isStorefrontMode(): boolean;
872
+ /**
873
+ * Check if client is in admin mode (using apiKey)
874
+ */
875
+ isAdminMode(): boolean;
876
+ /**
877
+ * Set the customer authentication token (obtained from login/register).
878
+ * Required for accessing customer-specific data in storefront mode.
879
+ *
880
+ * @example
881
+ * ```typescript
882
+ * const auth = await omni.loginCustomer('user@example.com', 'password');
883
+ * omni.setCustomerToken(auth.token);
884
+ *
885
+ * // Now can access customer data
886
+ * const profile = await omni.getMyProfile();
887
+ * ```
888
+ */
889
+ setCustomerToken(token: string | null): void;
890
+ /**
891
+ * Get the current customer token
892
+ */
893
+ getCustomerToken(): string | null;
894
+ /**
895
+ * Clear the customer token (logout)
896
+ */
897
+ clearCustomerToken(): void;
898
+ /**
899
+ * Make a request to the Admin API (requires apiKey)
900
+ */
901
+ private adminRequest;
902
+ /**
903
+ * Make a request to the Vibe-Coded API (public, uses connectionId)
904
+ */
905
+ private vibeCodedRequest;
906
+ /**
907
+ * Make a request to the Storefront API (public, uses storeId)
908
+ */
909
+ private storefrontRequest;
910
+ /**
911
+ * Smart request - uses storefront or admin API based on client mode
912
+ */
807
913
  private request;
914
+ /**
915
+ * Get store information
916
+ * Works in vibe-coded, storefront, and admin mode
917
+ */
918
+ getStoreInfo(): Promise<StoreInfo>;
808
919
  /**
809
920
  * Get a list of products with pagination
921
+ * Works in vibe-coded, storefront (public), and admin mode
810
922
  */
811
923
  getProducts(params?: ProductQueryParams): Promise<PaginatedResponse<Product>>;
812
924
  /**
813
925
  * Get a single product by ID
926
+ * Works in vibe-coded, storefront (public), and admin mode
814
927
  */
815
928
  getProduct(productId: string): Promise<Product>;
816
929
  /**
@@ -1201,16 +1314,6 @@ declare class OmniSyncClient {
1201
1314
  * Get the status of a sync job
1202
1315
  */
1203
1316
  getSyncStatus(jobId: string): Promise<SyncJob>;
1204
- /**
1205
- * Get information about the connected store
1206
- */
1207
- getStoreInfo(): Promise<{
1208
- id: string;
1209
- name: string;
1210
- currency: string;
1211
- language: string;
1212
- connectedPlatforms: ConnectorPlatform[];
1213
- }>;
1214
1317
  /**
1215
1318
  * Get a list of coupons with pagination
1216
1319
  */
@@ -1597,6 +1700,62 @@ declare class OmniSyncClient {
1597
1700
  * ```
1598
1701
  */
1599
1702
  completeCheckout(checkoutId: string): Promise<CompleteCheckoutResponse>;
1703
+ /**
1704
+ * Get the current customer's profile (requires customerToken)
1705
+ * Only available in storefront mode
1706
+ *
1707
+ * @example
1708
+ * ```typescript
1709
+ * const auth = await omni.loginCustomer('user@example.com', 'password');
1710
+ * omni.setCustomerToken(auth.token);
1711
+ * const profile = await omni.getMyProfile();
1712
+ * ```
1713
+ */
1714
+ getMyProfile(): Promise<CustomerProfile>;
1715
+ /**
1716
+ * Update the current customer's profile (requires customerToken)
1717
+ * Only available in storefront mode
1718
+ */
1719
+ updateMyProfile(data: {
1720
+ firstName?: string;
1721
+ lastName?: string;
1722
+ phone?: string;
1723
+ acceptsMarketing?: boolean;
1724
+ }): Promise<CustomerProfile>;
1725
+ /**
1726
+ * Get the current customer's orders (requires customerToken)
1727
+ * Only available in storefront mode
1728
+ */
1729
+ getMyOrders(params?: {
1730
+ page?: number;
1731
+ limit?: number;
1732
+ }): Promise<PaginatedResponse<Order>>;
1733
+ /**
1734
+ * Get the current customer's addresses (requires customerToken)
1735
+ * Only available in storefront mode
1736
+ */
1737
+ getMyAddresses(): Promise<CustomerAddress[]>;
1738
+ /**
1739
+ * Add an address to the current customer (requires customerToken)
1740
+ * Only available in storefront mode
1741
+ */
1742
+ addMyAddress(address: CreateAddressDto): Promise<CustomerAddress>;
1743
+ /**
1744
+ * Update a customer address (requires customerToken)
1745
+ * Only available in storefront mode
1746
+ */
1747
+ updateMyAddress(addressId: string, data: UpdateAddressDto): Promise<CustomerAddress>;
1748
+ /**
1749
+ * Delete a customer address (requires customerToken)
1750
+ * Only available in storefront mode
1751
+ */
1752
+ deleteMyAddress(addressId: string): Promise<void>;
1753
+ /**
1754
+ * Get the current customer's cart (requires customerToken)
1755
+ * Creates a new cart if none exists
1756
+ * Only available in storefront mode
1757
+ */
1758
+ getMyCart(): Promise<Cart>;
1600
1759
  }
1601
1760
  /**
1602
1761
  * Custom error class for Omni-Sync API errors
@@ -1617,7 +1776,7 @@ declare class OmniSyncError extends Error {
1617
1776
  *
1618
1777
  * @example
1619
1778
  * ```typescript
1620
- * import { verifyWebhook } from '@omni-sync/sdk';
1779
+ * import { verifyWebhook } from 'omni-sync-sdk';
1621
1780
  *
1622
1781
  * app.post('/webhooks/omni-sync', async (req, res) => {
1623
1782
  * const signature = req.headers['x-omni-signature'];
@@ -1664,4 +1823,4 @@ declare function isWebhookEventType(event: WebhookEvent, type: WebhookEventType)
1664
1823
  */
1665
1824
  declare function createWebhookHandler(handlers: Partial<Record<WebhookEventType, (event: WebhookEvent) => Promise<void>>>): (payload: unknown) => Promise<void>;
1666
1825
 
1667
- 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 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 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 };
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 };