omni-sync-sdk 0.8.3 → 0.9.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/LICENSE ADDED
File without changes
package/dist/index.d.mts CHANGED
@@ -1000,6 +1000,37 @@ interface ReconcileInventoryResponse {
1000
1000
  reconciled?: number;
1001
1001
  discrepancies?: number;
1002
1002
  }
1003
+ interface StockAvailabilityRequest {
1004
+ productId: string;
1005
+ variantId?: string;
1006
+ quantity: number;
1007
+ }
1008
+ interface StockAvailabilityResult {
1009
+ productId: string;
1010
+ variantId?: string | null;
1011
+ isAvailable: boolean;
1012
+ available: number;
1013
+ requested: number;
1014
+ shortfall: number;
1015
+ }
1016
+ interface StockAvailabilityResponse {
1017
+ allAvailable: boolean;
1018
+ results: StockAvailabilityResult[];
1019
+ }
1020
+ interface InsufficientStockError {
1021
+ code: 'INSUFFICIENT_STOCK';
1022
+ message: string;
1023
+ available: number;
1024
+ requested: number;
1025
+ productId?: string;
1026
+ variantId?: string;
1027
+ items?: Array<{
1028
+ productId: string;
1029
+ variantId?: string;
1030
+ available: number;
1031
+ requested: number;
1032
+ }>;
1033
+ }
1003
1034
  interface PublishProductResponse {
1004
1035
  productId: string;
1005
1036
  results: Record<string, {
@@ -1568,6 +1599,27 @@ declare class OmniSyncClient {
1568
1599
  productId?: string;
1569
1600
  autoFix?: boolean;
1570
1601
  }): Promise<ReconcileInventoryResponse>;
1602
+ /**
1603
+ * Check stock availability for one or more items before adding to cart or checkout
1604
+ * Use this to validate stock before operations that might fail due to insufficient inventory
1605
+ *
1606
+ * @example
1607
+ * ```typescript
1608
+ * // Check if items are available before adding to cart
1609
+ * const result = await omni.checkStockAvailability([
1610
+ * { productId: 'prod_123', quantity: 2 },
1611
+ * { productId: 'prod_456', variantId: 'var_789', quantity: 1 }
1612
+ * ]);
1613
+ *
1614
+ * if (!result.allAvailable) {
1615
+ * const unavailable = result.results.filter(r => !r.isAvailable);
1616
+ * unavailable.forEach(item => {
1617
+ * console.log(`Only ${item.available} available for product ${item.productId}`);
1618
+ * });
1619
+ * }
1620
+ * ```
1621
+ */
1622
+ checkStockAvailability(items: StockAvailabilityRequest[]): Promise<StockAvailabilityResponse>;
1571
1623
  /**
1572
1624
  * Trigger a sync to a specific platform or all platforms
1573
1625
  */
@@ -2556,4 +2608,4 @@ declare function isWebhookEventType(event: WebhookEvent, type: WebhookEventType)
2556
2608
  */
2557
2609
  declare function createWebhookHandler(handlers: Partial<Record<WebhookEventType, (event: WebhookEvent) => Promise<void>>>): (payload: unknown) => Promise<void>;
2558
2610
 
2559
- export { type AddToCartDto, type AppliedDiscount, type ApplyCouponDto, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type Cart, type CartItem, type CartStatus, type CategorySuggestion, 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 CustomerOAuthProvider, type CustomerProfile, type CustomerQueryParams, type DraftLineItem, type EditInventoryDto, type EmailVerificationResponse, type FulfillOrderDto, type GuestCheckoutStartResponse, type GuestOrderResponse, type InventoryInfo, type InventorySyncStatus, type LocalCart, type LocalCartItem, type MergeCartsDto, type OAuthAuthorizeResponse, type OAuthCallbackResponse, type OAuthConnection, type OAuthConnectionsResponse, type OAuthProvidersResponse, 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 ProductSuggestion, type ProductVariant, type PublishProductResponse, type ReconcileInventoryResponse, type Refund, type RefundLineItem, type RefundLineItemResponse, type RefundType, type RegisterCustomerDto, type SearchSuggestions, 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 };
2611
+ export { type AddToCartDto, type AppliedDiscount, type ApplyCouponDto, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type Cart, type CartItem, type CartStatus, type CategorySuggestion, 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 CustomerOAuthProvider, type CustomerProfile, type CustomerQueryParams, type DraftLineItem, type EditInventoryDto, type EmailVerificationResponse, type FulfillOrderDto, type GuestCheckoutStartResponse, type GuestOrderResponse, type InsufficientStockError, type InventoryInfo, type InventorySyncStatus, type LocalCart, type LocalCartItem, type MergeCartsDto, type OAuthAuthorizeResponse, type OAuthCallbackResponse, type OAuthConnection, type OAuthConnectionsResponse, type OAuthProvidersResponse, 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 ProductSuggestion, type ProductVariant, type PublishProductResponse, type ReconcileInventoryResponse, type Refund, type RefundLineItem, type RefundLineItemResponse, type RefundType, type RegisterCustomerDto, type SearchSuggestions, type SelectShippingMethodDto, type SendInvoiceDto, type SetBillingAddressDto, type SetCheckoutCustomerDto, type SetShippingAddressDto, type SetShippingAddressResponse, type ShippingLine, type ShippingRate, type StockAvailabilityRequest, type StockAvailabilityResponse, type StockAvailabilityResult, 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 };
package/dist/index.d.ts CHANGED
@@ -1000,6 +1000,37 @@ interface ReconcileInventoryResponse {
1000
1000
  reconciled?: number;
1001
1001
  discrepancies?: number;
1002
1002
  }
1003
+ interface StockAvailabilityRequest {
1004
+ productId: string;
1005
+ variantId?: string;
1006
+ quantity: number;
1007
+ }
1008
+ interface StockAvailabilityResult {
1009
+ productId: string;
1010
+ variantId?: string | null;
1011
+ isAvailable: boolean;
1012
+ available: number;
1013
+ requested: number;
1014
+ shortfall: number;
1015
+ }
1016
+ interface StockAvailabilityResponse {
1017
+ allAvailable: boolean;
1018
+ results: StockAvailabilityResult[];
1019
+ }
1020
+ interface InsufficientStockError {
1021
+ code: 'INSUFFICIENT_STOCK';
1022
+ message: string;
1023
+ available: number;
1024
+ requested: number;
1025
+ productId?: string;
1026
+ variantId?: string;
1027
+ items?: Array<{
1028
+ productId: string;
1029
+ variantId?: string;
1030
+ available: number;
1031
+ requested: number;
1032
+ }>;
1033
+ }
1003
1034
  interface PublishProductResponse {
1004
1035
  productId: string;
1005
1036
  results: Record<string, {
@@ -1568,6 +1599,27 @@ declare class OmniSyncClient {
1568
1599
  productId?: string;
1569
1600
  autoFix?: boolean;
1570
1601
  }): Promise<ReconcileInventoryResponse>;
1602
+ /**
1603
+ * Check stock availability for one or more items before adding to cart or checkout
1604
+ * Use this to validate stock before operations that might fail due to insufficient inventory
1605
+ *
1606
+ * @example
1607
+ * ```typescript
1608
+ * // Check if items are available before adding to cart
1609
+ * const result = await omni.checkStockAvailability([
1610
+ * { productId: 'prod_123', quantity: 2 },
1611
+ * { productId: 'prod_456', variantId: 'var_789', quantity: 1 }
1612
+ * ]);
1613
+ *
1614
+ * if (!result.allAvailable) {
1615
+ * const unavailable = result.results.filter(r => !r.isAvailable);
1616
+ * unavailable.forEach(item => {
1617
+ * console.log(`Only ${item.available} available for product ${item.productId}`);
1618
+ * });
1619
+ * }
1620
+ * ```
1621
+ */
1622
+ checkStockAvailability(items: StockAvailabilityRequest[]): Promise<StockAvailabilityResponse>;
1571
1623
  /**
1572
1624
  * Trigger a sync to a specific platform or all platforms
1573
1625
  */
@@ -2556,4 +2608,4 @@ declare function isWebhookEventType(event: WebhookEvent, type: WebhookEventType)
2556
2608
  */
2557
2609
  declare function createWebhookHandler(handlers: Partial<Record<WebhookEventType, (event: WebhookEvent) => Promise<void>>>): (payload: unknown) => Promise<void>;
2558
2610
 
2559
- export { type AddToCartDto, type AppliedDiscount, type ApplyCouponDto, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type Cart, type CartItem, type CartStatus, type CategorySuggestion, 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 CustomerOAuthProvider, type CustomerProfile, type CustomerQueryParams, type DraftLineItem, type EditInventoryDto, type EmailVerificationResponse, type FulfillOrderDto, type GuestCheckoutStartResponse, type GuestOrderResponse, type InventoryInfo, type InventorySyncStatus, type LocalCart, type LocalCartItem, type MergeCartsDto, type OAuthAuthorizeResponse, type OAuthCallbackResponse, type OAuthConnection, type OAuthConnectionsResponse, type OAuthProvidersResponse, 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 ProductSuggestion, type ProductVariant, type PublishProductResponse, type ReconcileInventoryResponse, type Refund, type RefundLineItem, type RefundLineItemResponse, type RefundType, type RegisterCustomerDto, type SearchSuggestions, 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 };
2611
+ export { type AddToCartDto, type AppliedDiscount, type ApplyCouponDto, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type Cart, type CartItem, type CartStatus, type CategorySuggestion, 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 CustomerOAuthProvider, type CustomerProfile, type CustomerQueryParams, type DraftLineItem, type EditInventoryDto, type EmailVerificationResponse, type FulfillOrderDto, type GuestCheckoutStartResponse, type GuestOrderResponse, type InsufficientStockError, type InventoryInfo, type InventorySyncStatus, type LocalCart, type LocalCartItem, type MergeCartsDto, type OAuthAuthorizeResponse, type OAuthCallbackResponse, type OAuthConnection, type OAuthConnectionsResponse, type OAuthProvidersResponse, 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 ProductSuggestion, type ProductVariant, type PublishProductResponse, type ReconcileInventoryResponse, type Refund, type RefundLineItem, type RefundLineItemResponse, type RefundType, type RegisterCustomerDto, type SearchSuggestions, type SelectShippingMethodDto, type SendInvoiceDto, type SetBillingAddressDto, type SetCheckoutCustomerDto, type SetShippingAddressDto, type SetShippingAddressResponse, type ShippingLine, type ShippingRate, type StockAvailabilityRequest, type StockAvailabilityResponse, type StockAvailabilityResult, 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 };
package/dist/index.js CHANGED
@@ -880,6 +880,47 @@ var OmniSyncClient = class {
880
880
  queryParams
881
881
  );
882
882
  }
883
+ /**
884
+ * Check stock availability for one or more items before adding to cart or checkout
885
+ * Use this to validate stock before operations that might fail due to insufficient inventory
886
+ *
887
+ * @example
888
+ * ```typescript
889
+ * // Check if items are available before adding to cart
890
+ * const result = await omni.checkStockAvailability([
891
+ * { productId: 'prod_123', quantity: 2 },
892
+ * { productId: 'prod_456', variantId: 'var_789', quantity: 1 }
893
+ * ]);
894
+ *
895
+ * if (!result.allAvailable) {
896
+ * const unavailable = result.results.filter(r => !r.isAvailable);
897
+ * unavailable.forEach(item => {
898
+ * console.log(`Only ${item.available} available for product ${item.productId}`);
899
+ * });
900
+ * }
901
+ * ```
902
+ */
903
+ async checkStockAvailability(items) {
904
+ if (this.isVibeCodedMode()) {
905
+ return this.vibeCodedRequest(
906
+ "POST",
907
+ "/inventory/check-availability",
908
+ { items }
909
+ );
910
+ }
911
+ if (this.storeId && !this.apiKey) {
912
+ return this.storefrontRequest(
913
+ "POST",
914
+ "/inventory/check-availability",
915
+ { items }
916
+ );
917
+ }
918
+ return this.request(
919
+ "POST",
920
+ "/api/v1/inventory/check-availability",
921
+ { items }
922
+ );
923
+ }
883
924
  // -------------------- Sync --------------------
884
925
  /**
885
926
  * Trigger a sync to a specific platform or all platforms
package/dist/index.mjs CHANGED
@@ -855,6 +855,47 @@ var OmniSyncClient = class {
855
855
  queryParams
856
856
  );
857
857
  }
858
+ /**
859
+ * Check stock availability for one or more items before adding to cart or checkout
860
+ * Use this to validate stock before operations that might fail due to insufficient inventory
861
+ *
862
+ * @example
863
+ * ```typescript
864
+ * // Check if items are available before adding to cart
865
+ * const result = await omni.checkStockAvailability([
866
+ * { productId: 'prod_123', quantity: 2 },
867
+ * { productId: 'prod_456', variantId: 'var_789', quantity: 1 }
868
+ * ]);
869
+ *
870
+ * if (!result.allAvailable) {
871
+ * const unavailable = result.results.filter(r => !r.isAvailable);
872
+ * unavailable.forEach(item => {
873
+ * console.log(`Only ${item.available} available for product ${item.productId}`);
874
+ * });
875
+ * }
876
+ * ```
877
+ */
878
+ async checkStockAvailability(items) {
879
+ if (this.isVibeCodedMode()) {
880
+ return this.vibeCodedRequest(
881
+ "POST",
882
+ "/inventory/check-availability",
883
+ { items }
884
+ );
885
+ }
886
+ if (this.storeId && !this.apiKey) {
887
+ return this.storefrontRequest(
888
+ "POST",
889
+ "/inventory/check-availability",
890
+ { items }
891
+ );
892
+ }
893
+ return this.request(
894
+ "POST",
895
+ "/api/v1/inventory/check-availability",
896
+ { items }
897
+ );
898
+ }
858
899
  // -------------------- Sync --------------------
859
900
  /**
860
901
  * Trigger a sync to a specific platform or all platforms
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-sync-sdk",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
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
+ }