omni-sync-sdk 0.8.2 → 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 +0 -0
- package/README.md +5 -4
- package/dist/index.d.mts +60 -1
- package/dist/index.d.ts +60 -1
- package/dist/index.js +41 -0
- package/dist/index.mjs +41 -0
- package/package.json +9 -10
package/LICENSE
ADDED
|
File without changes
|
package/README.md
CHANGED
|
@@ -38,10 +38,10 @@ const { data: products } = await omni.getProducts();
|
|
|
38
38
|
|
|
39
39
|
> **IMPORTANT:** There are TWO different checkout flows. You MUST use the correct one based on whether the customer is logged in or not.
|
|
40
40
|
|
|
41
|
-
| Customer Type | Cart Type
|
|
42
|
-
|
|
43
|
-
| **Guest**
|
|
44
|
-
| **Logged In** | Server Cart
|
|
41
|
+
| Customer Type | Cart Type | Checkout Method | Orders Linked to Account? |
|
|
42
|
+
| ------------- | ------------------------- | -------------------- | ------------------------- |
|
|
43
|
+
| **Guest** | Local Cart (localStorage) | `submitGuestOrder()` | No |
|
|
44
|
+
| **Logged In** | Server Cart | `completeCheckout()` | Yes |
|
|
45
45
|
|
|
46
46
|
### Decision Flow
|
|
47
47
|
|
|
@@ -2110,6 +2110,7 @@ export default function CheckoutPage() {
|
|
|
2110
2110
|
```
|
|
2111
2111
|
|
|
2112
2112
|
> **Key Points:**
|
|
2113
|
+
>
|
|
2113
2114
|
> - `isLoggedIn()` determines which flow to use
|
|
2114
2115
|
> - Logged-in customers use `createCart()` → `createCheckout()` → `completeCheckout()`
|
|
2115
2116
|
> - Guests use local cart + `submitGuestOrder()`
|
package/dist/index.d.mts
CHANGED
|
@@ -65,6 +65,12 @@ interface CustomerProfile {
|
|
|
65
65
|
createdAt: string;
|
|
66
66
|
updatedAt: string;
|
|
67
67
|
}
|
|
68
|
+
interface ProductMetafield {
|
|
69
|
+
key: string;
|
|
70
|
+
value: string;
|
|
71
|
+
name?: string;
|
|
72
|
+
type?: string;
|
|
73
|
+
}
|
|
68
74
|
interface Product {
|
|
69
75
|
id: string;
|
|
70
76
|
name: string;
|
|
@@ -82,6 +88,7 @@ interface Product {
|
|
|
82
88
|
variants?: ProductVariant[];
|
|
83
89
|
categories?: string[];
|
|
84
90
|
tags?: string[];
|
|
91
|
+
metafields?: ProductMetafield[];
|
|
85
92
|
channels?: Record<string, Record<string, unknown>>;
|
|
86
93
|
createdAt: string;
|
|
87
94
|
updatedAt: string;
|
|
@@ -993,6 +1000,37 @@ interface ReconcileInventoryResponse {
|
|
|
993
1000
|
reconciled?: number;
|
|
994
1001
|
discrepancies?: number;
|
|
995
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
|
+
}
|
|
996
1034
|
interface PublishProductResponse {
|
|
997
1035
|
productId: string;
|
|
998
1036
|
results: Record<string, {
|
|
@@ -1561,6 +1599,27 @@ declare class OmniSyncClient {
|
|
|
1561
1599
|
productId?: string;
|
|
1562
1600
|
autoFix?: boolean;
|
|
1563
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>;
|
|
1564
1623
|
/**
|
|
1565
1624
|
* Trigger a sync to a specific platform or all platforms
|
|
1566
1625
|
*/
|
|
@@ -2549,4 +2608,4 @@ declare function isWebhookEventType(event: WebhookEvent, type: WebhookEventType)
|
|
|
2549
2608
|
*/
|
|
2550
2609
|
declare function createWebhookHandler(handlers: Partial<Record<WebhookEventType, (event: WebhookEvent) => Promise<void>>>): (payload: unknown) => Promise<void>;
|
|
2551
2610
|
|
|
2552
|
-
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
|
@@ -65,6 +65,12 @@ interface CustomerProfile {
|
|
|
65
65
|
createdAt: string;
|
|
66
66
|
updatedAt: string;
|
|
67
67
|
}
|
|
68
|
+
interface ProductMetafield {
|
|
69
|
+
key: string;
|
|
70
|
+
value: string;
|
|
71
|
+
name?: string;
|
|
72
|
+
type?: string;
|
|
73
|
+
}
|
|
68
74
|
interface Product {
|
|
69
75
|
id: string;
|
|
70
76
|
name: string;
|
|
@@ -82,6 +88,7 @@ interface Product {
|
|
|
82
88
|
variants?: ProductVariant[];
|
|
83
89
|
categories?: string[];
|
|
84
90
|
tags?: string[];
|
|
91
|
+
metafields?: ProductMetafield[];
|
|
85
92
|
channels?: Record<string, Record<string, unknown>>;
|
|
86
93
|
createdAt: string;
|
|
87
94
|
updatedAt: string;
|
|
@@ -993,6 +1000,37 @@ interface ReconcileInventoryResponse {
|
|
|
993
1000
|
reconciled?: number;
|
|
994
1001
|
discrepancies?: number;
|
|
995
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
|
+
}
|
|
996
1034
|
interface PublishProductResponse {
|
|
997
1035
|
productId: string;
|
|
998
1036
|
results: Record<string, {
|
|
@@ -1561,6 +1599,27 @@ declare class OmniSyncClient {
|
|
|
1561
1599
|
productId?: string;
|
|
1562
1600
|
autoFix?: boolean;
|
|
1563
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>;
|
|
1564
1623
|
/**
|
|
1565
1624
|
* Trigger a sync to a specific platform or all platforms
|
|
1566
1625
|
*/
|
|
@@ -2549,4 +2608,4 @@ declare function isWebhookEventType(event: WebhookEvent, type: WebhookEventType)
|
|
|
2549
2608
|
*/
|
|
2550
2609
|
declare function createWebhookHandler(handlers: Partial<Record<WebhookEventType, (event: WebhookEvent) => Promise<void>>>): (payload: unknown) => Promise<void>;
|
|
2551
2610
|
|
|
2552
|
-
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.
|
|
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
|
+
}
|