@cimplify/sdk 0.3.2 → 0.3.4
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 +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +78 -20
- package/dist/index.mjs +78 -21
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1972,6 +1972,11 @@ interface CheckoutResult {
|
|
|
1972
1972
|
public_key?: string;
|
|
1973
1973
|
}
|
|
1974
1974
|
|
|
1975
|
+
/**
|
|
1976
|
+
* Generate a cryptographically secure idempotency key.
|
|
1977
|
+
* Uses crypto.randomUUID if available, falls back to timestamp + random.
|
|
1978
|
+
*/
|
|
1979
|
+
declare function generateIdempotencyKey(): string;
|
|
1975
1980
|
/**
|
|
1976
1981
|
* Checkout service with explicit error handling via Result type.
|
|
1977
1982
|
*
|
|
@@ -1999,6 +2004,10 @@ declare class CheckoutService {
|
|
|
1999
2004
|
/**
|
|
2000
2005
|
* Process checkout with cart data.
|
|
2001
2006
|
*
|
|
2007
|
+
* Automatically generates an idempotency key if not provided to ensure
|
|
2008
|
+
* payment safety. The same key is used across retries, preventing
|
|
2009
|
+
* duplicate charges if a network error occurs after payment processing.
|
|
2010
|
+
*
|
|
2002
2011
|
* @example
|
|
2003
2012
|
* ```typescript
|
|
2004
2013
|
* const result = await client.checkout.process({
|
|
@@ -2840,6 +2849,8 @@ declare class CimplifyClient {
|
|
|
2840
2849
|
private timeout;
|
|
2841
2850
|
private maxRetries;
|
|
2842
2851
|
private retryDelay;
|
|
2852
|
+
/** In-flight request deduplication map */
|
|
2853
|
+
private inflightRequests;
|
|
2843
2854
|
private _catalogue?;
|
|
2844
2855
|
private _cart?;
|
|
2845
2856
|
private _checkout?;
|
|
@@ -2863,7 +2874,25 @@ declare class CimplifyClient {
|
|
|
2863
2874
|
* Uses exponential backoff: 1s, 2s, 4s between retries.
|
|
2864
2875
|
*/
|
|
2865
2876
|
private resilientFetch;
|
|
2877
|
+
/**
|
|
2878
|
+
* Generate a deduplication key for a request.
|
|
2879
|
+
* Same query + variables = same key = deduplicated.
|
|
2880
|
+
*/
|
|
2881
|
+
private getDedupeKey;
|
|
2882
|
+
/**
|
|
2883
|
+
* Execute a request with deduplication.
|
|
2884
|
+
* If an identical request is already in-flight, return the same promise.
|
|
2885
|
+
* This prevents redundant network calls when multiple components request the same data.
|
|
2886
|
+
*/
|
|
2887
|
+
private deduplicatedRequest;
|
|
2888
|
+
/**
|
|
2889
|
+
* Execute a query with deduplication.
|
|
2890
|
+
* Multiple identical queries made simultaneously will share a single network request.
|
|
2891
|
+
*/
|
|
2866
2892
|
query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
|
|
2893
|
+
/**
|
|
2894
|
+
* Execute a mutation. NOT deduplicated - mutations have side effects.
|
|
2895
|
+
*/
|
|
2867
2896
|
call<T = unknown>(method: string, args?: unknown): Promise<T>;
|
|
2868
2897
|
get<T = unknown>(path: string): Promise<T>;
|
|
2869
2898
|
post<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
@@ -3406,4 +3435,4 @@ interface ApiResponse<T> {
|
|
|
3406
3435
|
metadata?: ResponseMetadata;
|
|
3407
3436
|
}
|
|
3408
3437
|
|
|
3409
|
-
export { AUTHORIZATION_TYPE, AUTH_MUTATION, type AddOn, type AddOnDetails, type AddOnGroupDetails, type AddOnOption, type AddOnOptionDetails, type AddOnOptionPrice, type AddOnWithOptions, type AddToCartInput, type AddressData, type AdjustmentType, type AmountToPay, type ApiError, type ApiResponse, type AppliedDiscount, type AuthResponse, AuthService, type AuthStatus, type AuthorizationType, type AvailabilityCheck, type AvailabilityResult, type AvailableSlot, type BenefitType, type Booking, type BookingRequirementOverride, type BookingStatus, type BookingWithDetails, type BufferTimes, type Bundle, type BundleComponentData, type BundleComponentInfo, type BundlePriceType, type BundleProduct, type BundleSelectionData, type BundleSelectionInput, type BundleStoredSelection, type BundleSummary, type BundleWithDetails, type Business, type BusinessHours, type BusinessPreferences, BusinessService, type BusinessSettings, type BusinessType, type BusinessWithLocations, CHECKOUT_MODE, CHECKOUT_MUTATION, CHECKOUT_STEP, CURRENCY_SYMBOLS, type CancelBookingInput, type CancelOrderInput, type CancellationPolicy, type Cart, type CartAddOn, type CartChannel, type CartItem, type CartItemDetails, CartOperations, type CartStatus, type CartSummary, type CartTotals, CatalogueQueries, type Category, type CategoryInfo, type CategorySummary, type ChangePasswordInput, type CheckSlotAvailabilityInput, type CheckoutAddressInfo, type CheckoutCustomerInfo, type CheckoutFormData, type CheckoutInput, type CheckoutMode, CheckoutService as CheckoutOperations, type CheckoutOrderType, type CheckoutPaymentMethod, type CheckoutResult, CheckoutService, type CheckoutStep, type ChosenPrice, CimplifyClient, type CimplifyConfig, CimplifyError, type Collection, type CollectionProduct, type CollectionSummary, type ComponentGroup, type ComponentGroupWithComponents, type ComponentPriceBreakdown, type ComponentSelectionInput, type ComponentSourceType, type Composite, type CompositeComponent, type CompositePriceBreakdown, type CompositePriceResult, type CompositePricingMode, type CompositeSelectionData, type ComponentSelectionInput as CompositeSelectionInput, type CompositeStoredSelection, type CompositeWithDetails, type ContactType, type CreateAddressInput, type CreateMobileMoneyInput, type Currency, type Customer, type CustomerAddress, type CustomerLinkPreferences, type CustomerMobileMoney, type CustomerServicePreferences, DEFAULT_COUNTRY, DEFAULT_CURRENCY, type DayAvailability, type DepositResult, type DepositType, type DeviceType, type DigitalProductType, type DiscountBreakdown, type DiscountDetails, type DisplayAddOn, type DisplayAddOnOption, type DisplayCart, type DisplayCartItem, type EnrollAndLinkOrderInput, type EnrollAndLinkOrderResult, type EnrollmentData, type Err, ErrorCode, type ErrorCodeType, type FeeBearerType, type FormatCompactOptions, type FormatPriceOptions, type FulfillmentLink, type FulfillmentStatus, type FulfillmentType, type GetAvailableSlotsInput, type GetOrdersOptions, type GetProductsOptions, type GroupPricingBehavior, type InitializePaymentResult, InventoryService, type InventorySummary, type InventoryType, type KitchenOrderItem, type KitchenOrderResult, LINK_MUTATION, LINK_QUERY, type LineConfiguration, type LineItem, type LineType, type LinkData, type LinkEnrollResult, LinkService, type LinkSession, type LinkStatusResult, type LiteBootstrap, LiteService, type Location, type LocationAppointment, type LocationProductPrice, type LocationStock, type LocationTaxBehavior, type LocationTaxOverrides, type LocationTimeProfile, type LocationWithDetails, MOBILE_MONEY_PROVIDER, MOBILE_MONEY_PROVIDERS, type MobileMoneyData, type MobileMoneyDetails, type MobileMoneyProvider, type Money, type MutationRequest, ORDER_MUTATION, ORDER_TYPE, type Ok, type Order, type OrderChannel, type OrderFilter, type OrderFulfillmentSummary, type OrderGroup, type OrderGroupDetails, type OrderGroupPayment, type OrderGroupPaymentState, type OrderGroupPaymentSummary, type OrderHistory, type OrderLineState, type OrderLineStatus, type OrderPaymentEvent, OrderQueries, type OrderSplitDetail, type OrderStatus, type OtpResult, PAYMENT_METHOD, PAYMENT_MUTATION, PAYMENT_STATE, PICKUP_TIME_TYPE, type Pagination, type PaginationParams, type ParsedPrice, type Payment, type PaymentErrorDetails, type PaymentMethod, type PaymentMethodType, type PaymentProcessingState, type PaymentProvider, type PaymentResponse, type PaymentState, type PaymentStatus, type PaymentStatusResponse, type PickupTime, type PickupTimeType, type Price, type PriceAdjustment, type PriceDecisionPath, type PriceEntryType, type PriceInfo, type PricePathTaxInfo, type PriceSource, type PricingOverrides, type Product, type ProductAddOn, type ProductAvailability, type ProductStock, type ProductTimeProfile, type ProductType, type ProductVariant, type ProductVariantValue, type ProductWithDetails, type ProductWithPrice, QueryBuilder, type QueryRequest, type RefundOrderInput, type ReminderMethod, type ReminderSettings, type RequestOtpInput, type RescheduleBookingInput, type ResourceAssignment, type ResourceAvailabilityException, type ResourceAvailabilityRule, type ResourceType, type ResponseMetadata, type Result, type RevokeAllSessionsResult, type RevokeSessionResult, type Room, type SalesChannel, type SchedulingMetadata, type SchedulingResult, SchedulingService, type SearchOptions, type SelectedAddOnOption, type Service, type ServiceAvailabilityException, type ServiceAvailabilityParams, type ServiceAvailabilityResult, type ServiceAvailabilityRule, type ServiceCharge, type ServiceNotes, type ServiceScheduleRequest, type ServiceStaffRequirement, type ServiceStatus, type ServiceWithStaff, type Staff, type StaffAssignment, type StaffAvailabilityException, type StaffAvailabilityRule, type StaffBookingProfile, type StaffRole, type StaffScheduleItem, type Stock, type StockLevel, type StockOwnershipType, type StockStatus, type StorefrontBootstrap, type SubmitAuthorizationInput, type Table, type TableInfo, type TaxComponent, type TaxInfo, type TaxPathComponent, type TimeRange, type TimeRanges, type TimeSlot, type UICart, type UICartBusiness, type UICartCustomer, type UICartLocation, type UICartPricing, type UpdateAddressInput, type UpdateCartItemInput, type UpdateOrderStatusInput, type UpdateProfileInput, type VariantAxis, type VariantAxisSelection, type VariantAxisValue, type VariantAxisWithValues, type VariantDetails, type VariantDetailsDTO, type VariantDisplayAttribute, type VariantLocationAvailability, type VariantStock, type VariantStrategy, type VerifyOtpInput, categorizePaymentError, combine, combineObject, createCimplifyClient, detectMobileMoneyProvider, err, extractPriceInfo, flatMap, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, fromPromise, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getOrElse, getProductCurrency, isCimplifyError, isErr, isOk, isOnSale, isRetryableError, mapError, mapResult, normalizePaymentResponse, normalizeStatusResponse, ok, parsePrice, parsePricePath, parsedPriceToPriceInfo, query, toNullable, tryCatch, unwrap };
|
|
3438
|
+
export { AUTHORIZATION_TYPE, AUTH_MUTATION, type AddOn, type AddOnDetails, type AddOnGroupDetails, type AddOnOption, type AddOnOptionDetails, type AddOnOptionPrice, type AddOnWithOptions, type AddToCartInput, type AddressData, type AdjustmentType, type AmountToPay, type ApiError, type ApiResponse, type AppliedDiscount, type AuthResponse, AuthService, type AuthStatus, type AuthorizationType, type AvailabilityCheck, type AvailabilityResult, type AvailableSlot, type BenefitType, type Booking, type BookingRequirementOverride, type BookingStatus, type BookingWithDetails, type BufferTimes, type Bundle, type BundleComponentData, type BundleComponentInfo, type BundlePriceType, type BundleProduct, type BundleSelectionData, type BundleSelectionInput, type BundleStoredSelection, type BundleSummary, type BundleWithDetails, type Business, type BusinessHours, type BusinessPreferences, BusinessService, type BusinessSettings, type BusinessType, type BusinessWithLocations, CHECKOUT_MODE, CHECKOUT_MUTATION, CHECKOUT_STEP, CURRENCY_SYMBOLS, type CancelBookingInput, type CancelOrderInput, type CancellationPolicy, type Cart, type CartAddOn, type CartChannel, type CartItem, type CartItemDetails, CartOperations, type CartStatus, type CartSummary, type CartTotals, CatalogueQueries, type Category, type CategoryInfo, type CategorySummary, type ChangePasswordInput, type CheckSlotAvailabilityInput, type CheckoutAddressInfo, type CheckoutCustomerInfo, type CheckoutFormData, type CheckoutInput, type CheckoutMode, CheckoutService as CheckoutOperations, type CheckoutOrderType, type CheckoutPaymentMethod, type CheckoutResult, CheckoutService, type CheckoutStep, type ChosenPrice, CimplifyClient, type CimplifyConfig, CimplifyError, type Collection, type CollectionProduct, type CollectionSummary, type ComponentGroup, type ComponentGroupWithComponents, type ComponentPriceBreakdown, type ComponentSelectionInput, type ComponentSourceType, type Composite, type CompositeComponent, type CompositePriceBreakdown, type CompositePriceResult, type CompositePricingMode, type CompositeSelectionData, type ComponentSelectionInput as CompositeSelectionInput, type CompositeStoredSelection, type CompositeWithDetails, type ContactType, type CreateAddressInput, type CreateMobileMoneyInput, type Currency, type Customer, type CustomerAddress, type CustomerLinkPreferences, type CustomerMobileMoney, type CustomerServicePreferences, DEFAULT_COUNTRY, DEFAULT_CURRENCY, type DayAvailability, type DepositResult, type DepositType, type DeviceType, type DigitalProductType, type DiscountBreakdown, type DiscountDetails, type DisplayAddOn, type DisplayAddOnOption, type DisplayCart, type DisplayCartItem, type EnrollAndLinkOrderInput, type EnrollAndLinkOrderResult, type EnrollmentData, type Err, ErrorCode, type ErrorCodeType, type FeeBearerType, type FormatCompactOptions, type FormatPriceOptions, type FulfillmentLink, type FulfillmentStatus, type FulfillmentType, type GetAvailableSlotsInput, type GetOrdersOptions, type GetProductsOptions, type GroupPricingBehavior, type InitializePaymentResult, InventoryService, type InventorySummary, type InventoryType, type KitchenOrderItem, type KitchenOrderResult, LINK_MUTATION, LINK_QUERY, type LineConfiguration, type LineItem, type LineType, type LinkData, type LinkEnrollResult, LinkService, type LinkSession, type LinkStatusResult, type LiteBootstrap, LiteService, type Location, type LocationAppointment, type LocationProductPrice, type LocationStock, type LocationTaxBehavior, type LocationTaxOverrides, type LocationTimeProfile, type LocationWithDetails, MOBILE_MONEY_PROVIDER, MOBILE_MONEY_PROVIDERS, type MobileMoneyData, type MobileMoneyDetails, type MobileMoneyProvider, type Money, type MutationRequest, ORDER_MUTATION, ORDER_TYPE, type Ok, type Order, type OrderChannel, type OrderFilter, type OrderFulfillmentSummary, type OrderGroup, type OrderGroupDetails, type OrderGroupPayment, type OrderGroupPaymentState, type OrderGroupPaymentSummary, type OrderHistory, type OrderLineState, type OrderLineStatus, type OrderPaymentEvent, OrderQueries, type OrderSplitDetail, type OrderStatus, type OtpResult, PAYMENT_METHOD, PAYMENT_MUTATION, PAYMENT_STATE, PICKUP_TIME_TYPE, type Pagination, type PaginationParams, type ParsedPrice, type Payment, type PaymentErrorDetails, type PaymentMethod, type PaymentMethodType, type PaymentProcessingState, type PaymentProvider, type PaymentResponse, type PaymentState, type PaymentStatus, type PaymentStatusResponse, type PickupTime, type PickupTimeType, type Price, type PriceAdjustment, type PriceDecisionPath, type PriceEntryType, type PriceInfo, type PricePathTaxInfo, type PriceSource, type PricingOverrides, type Product, type ProductAddOn, type ProductAvailability, type ProductStock, type ProductTimeProfile, type ProductType, type ProductVariant, type ProductVariantValue, type ProductWithDetails, type ProductWithPrice, QueryBuilder, type QueryRequest, type RefundOrderInput, type ReminderMethod, type ReminderSettings, type RequestOtpInput, type RescheduleBookingInput, type ResourceAssignment, type ResourceAvailabilityException, type ResourceAvailabilityRule, type ResourceType, type ResponseMetadata, type Result, type RevokeAllSessionsResult, type RevokeSessionResult, type Room, type SalesChannel, type SchedulingMetadata, type SchedulingResult, SchedulingService, type SearchOptions, type SelectedAddOnOption, type Service, type ServiceAvailabilityException, type ServiceAvailabilityParams, type ServiceAvailabilityResult, type ServiceAvailabilityRule, type ServiceCharge, type ServiceNotes, type ServiceScheduleRequest, type ServiceStaffRequirement, type ServiceStatus, type ServiceWithStaff, type Staff, type StaffAssignment, type StaffAvailabilityException, type StaffAvailabilityRule, type StaffBookingProfile, type StaffRole, type StaffScheduleItem, type Stock, type StockLevel, type StockOwnershipType, type StockStatus, type StorefrontBootstrap, type SubmitAuthorizationInput, type Table, type TableInfo, type TaxComponent, type TaxInfo, type TaxPathComponent, type TimeRange, type TimeRanges, type TimeSlot, type UICart, type UICartBusiness, type UICartCustomer, type UICartLocation, type UICartPricing, type UpdateAddressInput, type UpdateCartItemInput, type UpdateOrderStatusInput, type UpdateProfileInput, type VariantAxis, type VariantAxisSelection, type VariantAxisValue, type VariantAxisWithValues, type VariantDetails, type VariantDetailsDTO, type VariantDisplayAttribute, type VariantLocationAvailability, type VariantStock, type VariantStrategy, type VerifyOtpInput, categorizePaymentError, combine, combineObject, createCimplifyClient, detectMobileMoneyProvider, err, extractPriceInfo, flatMap, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, fromPromise, generateIdempotencyKey, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getOrElse, getProductCurrency, isCimplifyError, isErr, isOk, isOnSale, isRetryableError, mapError, mapResult, normalizePaymentResponse, normalizeStatusResponse, ok, parsePrice, parsePricePath, parsedPriceToPriceInfo, query, toNullable, tryCatch, unwrap };
|
package/dist/index.d.ts
CHANGED
|
@@ -1972,6 +1972,11 @@ interface CheckoutResult {
|
|
|
1972
1972
|
public_key?: string;
|
|
1973
1973
|
}
|
|
1974
1974
|
|
|
1975
|
+
/**
|
|
1976
|
+
* Generate a cryptographically secure idempotency key.
|
|
1977
|
+
* Uses crypto.randomUUID if available, falls back to timestamp + random.
|
|
1978
|
+
*/
|
|
1979
|
+
declare function generateIdempotencyKey(): string;
|
|
1975
1980
|
/**
|
|
1976
1981
|
* Checkout service with explicit error handling via Result type.
|
|
1977
1982
|
*
|
|
@@ -1999,6 +2004,10 @@ declare class CheckoutService {
|
|
|
1999
2004
|
/**
|
|
2000
2005
|
* Process checkout with cart data.
|
|
2001
2006
|
*
|
|
2007
|
+
* Automatically generates an idempotency key if not provided to ensure
|
|
2008
|
+
* payment safety. The same key is used across retries, preventing
|
|
2009
|
+
* duplicate charges if a network error occurs after payment processing.
|
|
2010
|
+
*
|
|
2002
2011
|
* @example
|
|
2003
2012
|
* ```typescript
|
|
2004
2013
|
* const result = await client.checkout.process({
|
|
@@ -2840,6 +2849,8 @@ declare class CimplifyClient {
|
|
|
2840
2849
|
private timeout;
|
|
2841
2850
|
private maxRetries;
|
|
2842
2851
|
private retryDelay;
|
|
2852
|
+
/** In-flight request deduplication map */
|
|
2853
|
+
private inflightRequests;
|
|
2843
2854
|
private _catalogue?;
|
|
2844
2855
|
private _cart?;
|
|
2845
2856
|
private _checkout?;
|
|
@@ -2863,7 +2874,25 @@ declare class CimplifyClient {
|
|
|
2863
2874
|
* Uses exponential backoff: 1s, 2s, 4s between retries.
|
|
2864
2875
|
*/
|
|
2865
2876
|
private resilientFetch;
|
|
2877
|
+
/**
|
|
2878
|
+
* Generate a deduplication key for a request.
|
|
2879
|
+
* Same query + variables = same key = deduplicated.
|
|
2880
|
+
*/
|
|
2881
|
+
private getDedupeKey;
|
|
2882
|
+
/**
|
|
2883
|
+
* Execute a request with deduplication.
|
|
2884
|
+
* If an identical request is already in-flight, return the same promise.
|
|
2885
|
+
* This prevents redundant network calls when multiple components request the same data.
|
|
2886
|
+
*/
|
|
2887
|
+
private deduplicatedRequest;
|
|
2888
|
+
/**
|
|
2889
|
+
* Execute a query with deduplication.
|
|
2890
|
+
* Multiple identical queries made simultaneously will share a single network request.
|
|
2891
|
+
*/
|
|
2866
2892
|
query<T = unknown>(query: string, variables?: Record<string, unknown>): Promise<T>;
|
|
2893
|
+
/**
|
|
2894
|
+
* Execute a mutation. NOT deduplicated - mutations have side effects.
|
|
2895
|
+
*/
|
|
2867
2896
|
call<T = unknown>(method: string, args?: unknown): Promise<T>;
|
|
2868
2897
|
get<T = unknown>(path: string): Promise<T>;
|
|
2869
2898
|
post<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
@@ -3406,4 +3435,4 @@ interface ApiResponse<T> {
|
|
|
3406
3435
|
metadata?: ResponseMetadata;
|
|
3407
3436
|
}
|
|
3408
3437
|
|
|
3409
|
-
export { AUTHORIZATION_TYPE, AUTH_MUTATION, type AddOn, type AddOnDetails, type AddOnGroupDetails, type AddOnOption, type AddOnOptionDetails, type AddOnOptionPrice, type AddOnWithOptions, type AddToCartInput, type AddressData, type AdjustmentType, type AmountToPay, type ApiError, type ApiResponse, type AppliedDiscount, type AuthResponse, AuthService, type AuthStatus, type AuthorizationType, type AvailabilityCheck, type AvailabilityResult, type AvailableSlot, type BenefitType, type Booking, type BookingRequirementOverride, type BookingStatus, type BookingWithDetails, type BufferTimes, type Bundle, type BundleComponentData, type BundleComponentInfo, type BundlePriceType, type BundleProduct, type BundleSelectionData, type BundleSelectionInput, type BundleStoredSelection, type BundleSummary, type BundleWithDetails, type Business, type BusinessHours, type BusinessPreferences, BusinessService, type BusinessSettings, type BusinessType, type BusinessWithLocations, CHECKOUT_MODE, CHECKOUT_MUTATION, CHECKOUT_STEP, CURRENCY_SYMBOLS, type CancelBookingInput, type CancelOrderInput, type CancellationPolicy, type Cart, type CartAddOn, type CartChannel, type CartItem, type CartItemDetails, CartOperations, type CartStatus, type CartSummary, type CartTotals, CatalogueQueries, type Category, type CategoryInfo, type CategorySummary, type ChangePasswordInput, type CheckSlotAvailabilityInput, type CheckoutAddressInfo, type CheckoutCustomerInfo, type CheckoutFormData, type CheckoutInput, type CheckoutMode, CheckoutService as CheckoutOperations, type CheckoutOrderType, type CheckoutPaymentMethod, type CheckoutResult, CheckoutService, type CheckoutStep, type ChosenPrice, CimplifyClient, type CimplifyConfig, CimplifyError, type Collection, type CollectionProduct, type CollectionSummary, type ComponentGroup, type ComponentGroupWithComponents, type ComponentPriceBreakdown, type ComponentSelectionInput, type ComponentSourceType, type Composite, type CompositeComponent, type CompositePriceBreakdown, type CompositePriceResult, type CompositePricingMode, type CompositeSelectionData, type ComponentSelectionInput as CompositeSelectionInput, type CompositeStoredSelection, type CompositeWithDetails, type ContactType, type CreateAddressInput, type CreateMobileMoneyInput, type Currency, type Customer, type CustomerAddress, type CustomerLinkPreferences, type CustomerMobileMoney, type CustomerServicePreferences, DEFAULT_COUNTRY, DEFAULT_CURRENCY, type DayAvailability, type DepositResult, type DepositType, type DeviceType, type DigitalProductType, type DiscountBreakdown, type DiscountDetails, type DisplayAddOn, type DisplayAddOnOption, type DisplayCart, type DisplayCartItem, type EnrollAndLinkOrderInput, type EnrollAndLinkOrderResult, type EnrollmentData, type Err, ErrorCode, type ErrorCodeType, type FeeBearerType, type FormatCompactOptions, type FormatPriceOptions, type FulfillmentLink, type FulfillmentStatus, type FulfillmentType, type GetAvailableSlotsInput, type GetOrdersOptions, type GetProductsOptions, type GroupPricingBehavior, type InitializePaymentResult, InventoryService, type InventorySummary, type InventoryType, type KitchenOrderItem, type KitchenOrderResult, LINK_MUTATION, LINK_QUERY, type LineConfiguration, type LineItem, type LineType, type LinkData, type LinkEnrollResult, LinkService, type LinkSession, type LinkStatusResult, type LiteBootstrap, LiteService, type Location, type LocationAppointment, type LocationProductPrice, type LocationStock, type LocationTaxBehavior, type LocationTaxOverrides, type LocationTimeProfile, type LocationWithDetails, MOBILE_MONEY_PROVIDER, MOBILE_MONEY_PROVIDERS, type MobileMoneyData, type MobileMoneyDetails, type MobileMoneyProvider, type Money, type MutationRequest, ORDER_MUTATION, ORDER_TYPE, type Ok, type Order, type OrderChannel, type OrderFilter, type OrderFulfillmentSummary, type OrderGroup, type OrderGroupDetails, type OrderGroupPayment, type OrderGroupPaymentState, type OrderGroupPaymentSummary, type OrderHistory, type OrderLineState, type OrderLineStatus, type OrderPaymentEvent, OrderQueries, type OrderSplitDetail, type OrderStatus, type OtpResult, PAYMENT_METHOD, PAYMENT_MUTATION, PAYMENT_STATE, PICKUP_TIME_TYPE, type Pagination, type PaginationParams, type ParsedPrice, type Payment, type PaymentErrorDetails, type PaymentMethod, type PaymentMethodType, type PaymentProcessingState, type PaymentProvider, type PaymentResponse, type PaymentState, type PaymentStatus, type PaymentStatusResponse, type PickupTime, type PickupTimeType, type Price, type PriceAdjustment, type PriceDecisionPath, type PriceEntryType, type PriceInfo, type PricePathTaxInfo, type PriceSource, type PricingOverrides, type Product, type ProductAddOn, type ProductAvailability, type ProductStock, type ProductTimeProfile, type ProductType, type ProductVariant, type ProductVariantValue, type ProductWithDetails, type ProductWithPrice, QueryBuilder, type QueryRequest, type RefundOrderInput, type ReminderMethod, type ReminderSettings, type RequestOtpInput, type RescheduleBookingInput, type ResourceAssignment, type ResourceAvailabilityException, type ResourceAvailabilityRule, type ResourceType, type ResponseMetadata, type Result, type RevokeAllSessionsResult, type RevokeSessionResult, type Room, type SalesChannel, type SchedulingMetadata, type SchedulingResult, SchedulingService, type SearchOptions, type SelectedAddOnOption, type Service, type ServiceAvailabilityException, type ServiceAvailabilityParams, type ServiceAvailabilityResult, type ServiceAvailabilityRule, type ServiceCharge, type ServiceNotes, type ServiceScheduleRequest, type ServiceStaffRequirement, type ServiceStatus, type ServiceWithStaff, type Staff, type StaffAssignment, type StaffAvailabilityException, type StaffAvailabilityRule, type StaffBookingProfile, type StaffRole, type StaffScheduleItem, type Stock, type StockLevel, type StockOwnershipType, type StockStatus, type StorefrontBootstrap, type SubmitAuthorizationInput, type Table, type TableInfo, type TaxComponent, type TaxInfo, type TaxPathComponent, type TimeRange, type TimeRanges, type TimeSlot, type UICart, type UICartBusiness, type UICartCustomer, type UICartLocation, type UICartPricing, type UpdateAddressInput, type UpdateCartItemInput, type UpdateOrderStatusInput, type UpdateProfileInput, type VariantAxis, type VariantAxisSelection, type VariantAxisValue, type VariantAxisWithValues, type VariantDetails, type VariantDetailsDTO, type VariantDisplayAttribute, type VariantLocationAvailability, type VariantStock, type VariantStrategy, type VerifyOtpInput, categorizePaymentError, combine, combineObject, createCimplifyClient, detectMobileMoneyProvider, err, extractPriceInfo, flatMap, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, fromPromise, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getOrElse, getProductCurrency, isCimplifyError, isErr, isOk, isOnSale, isRetryableError, mapError, mapResult, normalizePaymentResponse, normalizeStatusResponse, ok, parsePrice, parsePricePath, parsedPriceToPriceInfo, query, toNullable, tryCatch, unwrap };
|
|
3438
|
+
export { AUTHORIZATION_TYPE, AUTH_MUTATION, type AddOn, type AddOnDetails, type AddOnGroupDetails, type AddOnOption, type AddOnOptionDetails, type AddOnOptionPrice, type AddOnWithOptions, type AddToCartInput, type AddressData, type AdjustmentType, type AmountToPay, type ApiError, type ApiResponse, type AppliedDiscount, type AuthResponse, AuthService, type AuthStatus, type AuthorizationType, type AvailabilityCheck, type AvailabilityResult, type AvailableSlot, type BenefitType, type Booking, type BookingRequirementOverride, type BookingStatus, type BookingWithDetails, type BufferTimes, type Bundle, type BundleComponentData, type BundleComponentInfo, type BundlePriceType, type BundleProduct, type BundleSelectionData, type BundleSelectionInput, type BundleStoredSelection, type BundleSummary, type BundleWithDetails, type Business, type BusinessHours, type BusinessPreferences, BusinessService, type BusinessSettings, type BusinessType, type BusinessWithLocations, CHECKOUT_MODE, CHECKOUT_MUTATION, CHECKOUT_STEP, CURRENCY_SYMBOLS, type CancelBookingInput, type CancelOrderInput, type CancellationPolicy, type Cart, type CartAddOn, type CartChannel, type CartItem, type CartItemDetails, CartOperations, type CartStatus, type CartSummary, type CartTotals, CatalogueQueries, type Category, type CategoryInfo, type CategorySummary, type ChangePasswordInput, type CheckSlotAvailabilityInput, type CheckoutAddressInfo, type CheckoutCustomerInfo, type CheckoutFormData, type CheckoutInput, type CheckoutMode, CheckoutService as CheckoutOperations, type CheckoutOrderType, type CheckoutPaymentMethod, type CheckoutResult, CheckoutService, type CheckoutStep, type ChosenPrice, CimplifyClient, type CimplifyConfig, CimplifyError, type Collection, type CollectionProduct, type CollectionSummary, type ComponentGroup, type ComponentGroupWithComponents, type ComponentPriceBreakdown, type ComponentSelectionInput, type ComponentSourceType, type Composite, type CompositeComponent, type CompositePriceBreakdown, type CompositePriceResult, type CompositePricingMode, type CompositeSelectionData, type ComponentSelectionInput as CompositeSelectionInput, type CompositeStoredSelection, type CompositeWithDetails, type ContactType, type CreateAddressInput, type CreateMobileMoneyInput, type Currency, type Customer, type CustomerAddress, type CustomerLinkPreferences, type CustomerMobileMoney, type CustomerServicePreferences, DEFAULT_COUNTRY, DEFAULT_CURRENCY, type DayAvailability, type DepositResult, type DepositType, type DeviceType, type DigitalProductType, type DiscountBreakdown, type DiscountDetails, type DisplayAddOn, type DisplayAddOnOption, type DisplayCart, type DisplayCartItem, type EnrollAndLinkOrderInput, type EnrollAndLinkOrderResult, type EnrollmentData, type Err, ErrorCode, type ErrorCodeType, type FeeBearerType, type FormatCompactOptions, type FormatPriceOptions, type FulfillmentLink, type FulfillmentStatus, type FulfillmentType, type GetAvailableSlotsInput, type GetOrdersOptions, type GetProductsOptions, type GroupPricingBehavior, type InitializePaymentResult, InventoryService, type InventorySummary, type InventoryType, type KitchenOrderItem, type KitchenOrderResult, LINK_MUTATION, LINK_QUERY, type LineConfiguration, type LineItem, type LineType, type LinkData, type LinkEnrollResult, LinkService, type LinkSession, type LinkStatusResult, type LiteBootstrap, LiteService, type Location, type LocationAppointment, type LocationProductPrice, type LocationStock, type LocationTaxBehavior, type LocationTaxOverrides, type LocationTimeProfile, type LocationWithDetails, MOBILE_MONEY_PROVIDER, MOBILE_MONEY_PROVIDERS, type MobileMoneyData, type MobileMoneyDetails, type MobileMoneyProvider, type Money, type MutationRequest, ORDER_MUTATION, ORDER_TYPE, type Ok, type Order, type OrderChannel, type OrderFilter, type OrderFulfillmentSummary, type OrderGroup, type OrderGroupDetails, type OrderGroupPayment, type OrderGroupPaymentState, type OrderGroupPaymentSummary, type OrderHistory, type OrderLineState, type OrderLineStatus, type OrderPaymentEvent, OrderQueries, type OrderSplitDetail, type OrderStatus, type OtpResult, PAYMENT_METHOD, PAYMENT_MUTATION, PAYMENT_STATE, PICKUP_TIME_TYPE, type Pagination, type PaginationParams, type ParsedPrice, type Payment, type PaymentErrorDetails, type PaymentMethod, type PaymentMethodType, type PaymentProcessingState, type PaymentProvider, type PaymentResponse, type PaymentState, type PaymentStatus, type PaymentStatusResponse, type PickupTime, type PickupTimeType, type Price, type PriceAdjustment, type PriceDecisionPath, type PriceEntryType, type PriceInfo, type PricePathTaxInfo, type PriceSource, type PricingOverrides, type Product, type ProductAddOn, type ProductAvailability, type ProductStock, type ProductTimeProfile, type ProductType, type ProductVariant, type ProductVariantValue, type ProductWithDetails, type ProductWithPrice, QueryBuilder, type QueryRequest, type RefundOrderInput, type ReminderMethod, type ReminderSettings, type RequestOtpInput, type RescheduleBookingInput, type ResourceAssignment, type ResourceAvailabilityException, type ResourceAvailabilityRule, type ResourceType, type ResponseMetadata, type Result, type RevokeAllSessionsResult, type RevokeSessionResult, type Room, type SalesChannel, type SchedulingMetadata, type SchedulingResult, SchedulingService, type SearchOptions, type SelectedAddOnOption, type Service, type ServiceAvailabilityException, type ServiceAvailabilityParams, type ServiceAvailabilityResult, type ServiceAvailabilityRule, type ServiceCharge, type ServiceNotes, type ServiceScheduleRequest, type ServiceStaffRequirement, type ServiceStatus, type ServiceWithStaff, type Staff, type StaffAssignment, type StaffAvailabilityException, type StaffAvailabilityRule, type StaffBookingProfile, type StaffRole, type StaffScheduleItem, type Stock, type StockLevel, type StockOwnershipType, type StockStatus, type StorefrontBootstrap, type SubmitAuthorizationInput, type Table, type TableInfo, type TaxComponent, type TaxInfo, type TaxPathComponent, type TimeRange, type TimeRanges, type TimeSlot, type UICart, type UICartBusiness, type UICartCustomer, type UICartLocation, type UICartPricing, type UpdateAddressInput, type UpdateCartItemInput, type UpdateOrderStatusInput, type UpdateProfileInput, type VariantAxis, type VariantAxisSelection, type VariantAxisValue, type VariantAxisWithValues, type VariantDetails, type VariantDetailsDTO, type VariantDisplayAttribute, type VariantLocationAvailability, type VariantStock, type VariantStrategy, type VerifyOtpInput, categorizePaymentError, combine, combineObject, createCimplifyClient, detectMobileMoneyProvider, err, extractPriceInfo, flatMap, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, fromPromise, generateIdempotencyKey, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getOrElse, getProductCurrency, isCimplifyError, isErr, isOk, isOnSale, isRetryableError, mapError, mapResult, normalizePaymentResponse, normalizeStatusResponse, ok, parsePrice, parsePricePath, parsedPriceToPriceInfo, query, toNullable, tryCatch, unwrap };
|
package/dist/index.js
CHANGED
|
@@ -645,6 +645,14 @@ async function safe3(promise) {
|
|
|
645
645
|
return err(toCimplifyError3(error));
|
|
646
646
|
}
|
|
647
647
|
}
|
|
648
|
+
function generateIdempotencyKey() {
|
|
649
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
650
|
+
return `idem_${crypto.randomUUID()}`;
|
|
651
|
+
}
|
|
652
|
+
const timestamp = Date.now().toString(36);
|
|
653
|
+
const random = Math.random().toString(36).substring(2, 15);
|
|
654
|
+
return `idem_${timestamp}_${random}`;
|
|
655
|
+
}
|
|
648
656
|
var CheckoutService = class {
|
|
649
657
|
constructor(client) {
|
|
650
658
|
this.client = client;
|
|
@@ -652,6 +660,10 @@ var CheckoutService = class {
|
|
|
652
660
|
/**
|
|
653
661
|
* Process checkout with cart data.
|
|
654
662
|
*
|
|
663
|
+
* Automatically generates an idempotency key if not provided to ensure
|
|
664
|
+
* payment safety. The same key is used across retries, preventing
|
|
665
|
+
* duplicate charges if a network error occurs after payment processing.
|
|
666
|
+
*
|
|
655
667
|
* @example
|
|
656
668
|
* ```typescript
|
|
657
669
|
* const result = await client.checkout.process({
|
|
@@ -675,9 +687,13 @@ var CheckoutService = class {
|
|
|
675
687
|
* ```
|
|
676
688
|
*/
|
|
677
689
|
async process(data) {
|
|
690
|
+
const checkoutData = {
|
|
691
|
+
...data,
|
|
692
|
+
idempotency_key: data.idempotency_key || generateIdempotencyKey()
|
|
693
|
+
};
|
|
678
694
|
return safe3(
|
|
679
695
|
this.client.call(CHECKOUT_MUTATION.PROCESS, {
|
|
680
|
-
checkout_data:
|
|
696
|
+
checkout_data: checkoutData
|
|
681
697
|
})
|
|
682
698
|
);
|
|
683
699
|
}
|
|
@@ -1453,6 +1469,8 @@ function deriveUrls() {
|
|
|
1453
1469
|
var CimplifyClient = class {
|
|
1454
1470
|
constructor(config = {}) {
|
|
1455
1471
|
this.sessionToken = null;
|
|
1472
|
+
/** In-flight request deduplication map */
|
|
1473
|
+
this.inflightRequests = /* @__PURE__ */ new Map();
|
|
1456
1474
|
this.publicKey = config.publicKey || "";
|
|
1457
1475
|
const urls = deriveUrls();
|
|
1458
1476
|
this.baseUrl = urls.baseUrl;
|
|
@@ -1541,20 +1559,53 @@ var CimplifyClient = class {
|
|
|
1541
1559
|
}
|
|
1542
1560
|
throw toNetworkError(lastError);
|
|
1543
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Generate a deduplication key for a request.
|
|
1564
|
+
* Same query + variables = same key = deduplicated.
|
|
1565
|
+
*/
|
|
1566
|
+
getDedupeKey(type, payload) {
|
|
1567
|
+
return `${type}:${JSON.stringify(payload)}`;
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* Execute a request with deduplication.
|
|
1571
|
+
* If an identical request is already in-flight, return the same promise.
|
|
1572
|
+
* This prevents redundant network calls when multiple components request the same data.
|
|
1573
|
+
*/
|
|
1574
|
+
async deduplicatedRequest(key, requestFn) {
|
|
1575
|
+
const existing = this.inflightRequests.get(key);
|
|
1576
|
+
if (existing) {
|
|
1577
|
+
return existing;
|
|
1578
|
+
}
|
|
1579
|
+
const request = requestFn().finally(() => {
|
|
1580
|
+
this.inflightRequests.delete(key);
|
|
1581
|
+
});
|
|
1582
|
+
this.inflightRequests.set(key, request);
|
|
1583
|
+
return request;
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Execute a query with deduplication.
|
|
1587
|
+
* Multiple identical queries made simultaneously will share a single network request.
|
|
1588
|
+
*/
|
|
1544
1589
|
async query(query2, variables) {
|
|
1545
1590
|
const body = { query: query2 };
|
|
1546
1591
|
if (variables) {
|
|
1547
1592
|
body.variables = variables;
|
|
1548
1593
|
}
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1594
|
+
const key = this.getDedupeKey("query", body);
|
|
1595
|
+
return this.deduplicatedRequest(key, async () => {
|
|
1596
|
+
const response = await this.resilientFetch(`${this.baseUrl}/api/q`, {
|
|
1597
|
+
method: "POST",
|
|
1598
|
+
credentials: this.credentials,
|
|
1599
|
+
headers: this.getHeaders(),
|
|
1600
|
+
body: JSON.stringify(body)
|
|
1601
|
+
});
|
|
1602
|
+
this.updateSessionFromResponse(response);
|
|
1603
|
+
return this.handleResponse(response);
|
|
1554
1604
|
});
|
|
1555
|
-
this.updateSessionFromResponse(response);
|
|
1556
|
-
return this.handleResponse(response);
|
|
1557
1605
|
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Execute a mutation. NOT deduplicated - mutations have side effects.
|
|
1608
|
+
*/
|
|
1558
1609
|
async call(method, args) {
|
|
1559
1610
|
const body = {
|
|
1560
1611
|
method,
|
|
@@ -1570,13 +1621,16 @@ var CimplifyClient = class {
|
|
|
1570
1621
|
return this.handleResponse(response);
|
|
1571
1622
|
}
|
|
1572
1623
|
async get(path) {
|
|
1573
|
-
const
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1624
|
+
const key = this.getDedupeKey("get", path);
|
|
1625
|
+
return this.deduplicatedRequest(key, async () => {
|
|
1626
|
+
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
1627
|
+
method: "GET",
|
|
1628
|
+
credentials: this.credentials,
|
|
1629
|
+
headers: this.getHeaders()
|
|
1630
|
+
});
|
|
1631
|
+
this.updateSessionFromResponse(response);
|
|
1632
|
+
return this.handleRestResponse(response);
|
|
1577
1633
|
});
|
|
1578
|
-
this.updateSessionFromResponse(response);
|
|
1579
|
-
return this.handleRestResponse(response);
|
|
1580
1634
|
}
|
|
1581
1635
|
async post(path, body) {
|
|
1582
1636
|
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
@@ -1598,13 +1652,16 @@ var CimplifyClient = class {
|
|
|
1598
1652
|
return this.handleRestResponse(response);
|
|
1599
1653
|
}
|
|
1600
1654
|
async linkGet(path) {
|
|
1601
|
-
const
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1655
|
+
const key = this.getDedupeKey("linkGet", path);
|
|
1656
|
+
return this.deduplicatedRequest(key, async () => {
|
|
1657
|
+
const response = await this.resilientFetch(`${this.linkApiUrl}${path}`, {
|
|
1658
|
+
method: "GET",
|
|
1659
|
+
credentials: this.credentials,
|
|
1660
|
+
headers: this.getHeaders()
|
|
1661
|
+
});
|
|
1662
|
+
this.updateSessionFromResponse(response);
|
|
1663
|
+
return this.handleRestResponse(response);
|
|
1605
1664
|
});
|
|
1606
|
-
this.updateSessionFromResponse(response);
|
|
1607
|
-
return this.handleRestResponse(response);
|
|
1608
1665
|
}
|
|
1609
1666
|
async linkPost(path, body) {
|
|
1610
1667
|
const response = await this.resilientFetch(`${this.linkApiUrl}${path}`, {
|
|
@@ -2311,6 +2368,7 @@ exports.formatPriceAdjustment = formatPriceAdjustment;
|
|
|
2311
2368
|
exports.formatPriceCompact = formatPriceCompact;
|
|
2312
2369
|
exports.formatProductPrice = formatProductPrice;
|
|
2313
2370
|
exports.fromPromise = fromPromise;
|
|
2371
|
+
exports.generateIdempotencyKey = generateIdempotencyKey;
|
|
2314
2372
|
exports.getBasePrice = getBasePrice;
|
|
2315
2373
|
exports.getCurrencySymbol = getCurrencySymbol;
|
|
2316
2374
|
exports.getDiscountPercentage = getDiscountPercentage;
|
package/dist/index.mjs
CHANGED
|
@@ -643,6 +643,14 @@ async function safe3(promise) {
|
|
|
643
643
|
return err(toCimplifyError3(error));
|
|
644
644
|
}
|
|
645
645
|
}
|
|
646
|
+
function generateIdempotencyKey() {
|
|
647
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
648
|
+
return `idem_${crypto.randomUUID()}`;
|
|
649
|
+
}
|
|
650
|
+
const timestamp = Date.now().toString(36);
|
|
651
|
+
const random = Math.random().toString(36).substring(2, 15);
|
|
652
|
+
return `idem_${timestamp}_${random}`;
|
|
653
|
+
}
|
|
646
654
|
var CheckoutService = class {
|
|
647
655
|
constructor(client) {
|
|
648
656
|
this.client = client;
|
|
@@ -650,6 +658,10 @@ var CheckoutService = class {
|
|
|
650
658
|
/**
|
|
651
659
|
* Process checkout with cart data.
|
|
652
660
|
*
|
|
661
|
+
* Automatically generates an idempotency key if not provided to ensure
|
|
662
|
+
* payment safety. The same key is used across retries, preventing
|
|
663
|
+
* duplicate charges if a network error occurs after payment processing.
|
|
664
|
+
*
|
|
653
665
|
* @example
|
|
654
666
|
* ```typescript
|
|
655
667
|
* const result = await client.checkout.process({
|
|
@@ -673,9 +685,13 @@ var CheckoutService = class {
|
|
|
673
685
|
* ```
|
|
674
686
|
*/
|
|
675
687
|
async process(data) {
|
|
688
|
+
const checkoutData = {
|
|
689
|
+
...data,
|
|
690
|
+
idempotency_key: data.idempotency_key || generateIdempotencyKey()
|
|
691
|
+
};
|
|
676
692
|
return safe3(
|
|
677
693
|
this.client.call(CHECKOUT_MUTATION.PROCESS, {
|
|
678
|
-
checkout_data:
|
|
694
|
+
checkout_data: checkoutData
|
|
679
695
|
})
|
|
680
696
|
);
|
|
681
697
|
}
|
|
@@ -1451,6 +1467,8 @@ function deriveUrls() {
|
|
|
1451
1467
|
var CimplifyClient = class {
|
|
1452
1468
|
constructor(config = {}) {
|
|
1453
1469
|
this.sessionToken = null;
|
|
1470
|
+
/** In-flight request deduplication map */
|
|
1471
|
+
this.inflightRequests = /* @__PURE__ */ new Map();
|
|
1454
1472
|
this.publicKey = config.publicKey || "";
|
|
1455
1473
|
const urls = deriveUrls();
|
|
1456
1474
|
this.baseUrl = urls.baseUrl;
|
|
@@ -1539,20 +1557,53 @@ var CimplifyClient = class {
|
|
|
1539
1557
|
}
|
|
1540
1558
|
throw toNetworkError(lastError);
|
|
1541
1559
|
}
|
|
1560
|
+
/**
|
|
1561
|
+
* Generate a deduplication key for a request.
|
|
1562
|
+
* Same query + variables = same key = deduplicated.
|
|
1563
|
+
*/
|
|
1564
|
+
getDedupeKey(type, payload) {
|
|
1565
|
+
return `${type}:${JSON.stringify(payload)}`;
|
|
1566
|
+
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Execute a request with deduplication.
|
|
1569
|
+
* If an identical request is already in-flight, return the same promise.
|
|
1570
|
+
* This prevents redundant network calls when multiple components request the same data.
|
|
1571
|
+
*/
|
|
1572
|
+
async deduplicatedRequest(key, requestFn) {
|
|
1573
|
+
const existing = this.inflightRequests.get(key);
|
|
1574
|
+
if (existing) {
|
|
1575
|
+
return existing;
|
|
1576
|
+
}
|
|
1577
|
+
const request = requestFn().finally(() => {
|
|
1578
|
+
this.inflightRequests.delete(key);
|
|
1579
|
+
});
|
|
1580
|
+
this.inflightRequests.set(key, request);
|
|
1581
|
+
return request;
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* Execute a query with deduplication.
|
|
1585
|
+
* Multiple identical queries made simultaneously will share a single network request.
|
|
1586
|
+
*/
|
|
1542
1587
|
async query(query2, variables) {
|
|
1543
1588
|
const body = { query: query2 };
|
|
1544
1589
|
if (variables) {
|
|
1545
1590
|
body.variables = variables;
|
|
1546
1591
|
}
|
|
1547
|
-
const
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1592
|
+
const key = this.getDedupeKey("query", body);
|
|
1593
|
+
return this.deduplicatedRequest(key, async () => {
|
|
1594
|
+
const response = await this.resilientFetch(`${this.baseUrl}/api/q`, {
|
|
1595
|
+
method: "POST",
|
|
1596
|
+
credentials: this.credentials,
|
|
1597
|
+
headers: this.getHeaders(),
|
|
1598
|
+
body: JSON.stringify(body)
|
|
1599
|
+
});
|
|
1600
|
+
this.updateSessionFromResponse(response);
|
|
1601
|
+
return this.handleResponse(response);
|
|
1552
1602
|
});
|
|
1553
|
-
this.updateSessionFromResponse(response);
|
|
1554
|
-
return this.handleResponse(response);
|
|
1555
1603
|
}
|
|
1604
|
+
/**
|
|
1605
|
+
* Execute a mutation. NOT deduplicated - mutations have side effects.
|
|
1606
|
+
*/
|
|
1556
1607
|
async call(method, args) {
|
|
1557
1608
|
const body = {
|
|
1558
1609
|
method,
|
|
@@ -1568,13 +1619,16 @@ var CimplifyClient = class {
|
|
|
1568
1619
|
return this.handleResponse(response);
|
|
1569
1620
|
}
|
|
1570
1621
|
async get(path) {
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1622
|
+
const key = this.getDedupeKey("get", path);
|
|
1623
|
+
return this.deduplicatedRequest(key, async () => {
|
|
1624
|
+
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
1625
|
+
method: "GET",
|
|
1626
|
+
credentials: this.credentials,
|
|
1627
|
+
headers: this.getHeaders()
|
|
1628
|
+
});
|
|
1629
|
+
this.updateSessionFromResponse(response);
|
|
1630
|
+
return this.handleRestResponse(response);
|
|
1575
1631
|
});
|
|
1576
|
-
this.updateSessionFromResponse(response);
|
|
1577
|
-
return this.handleRestResponse(response);
|
|
1578
1632
|
}
|
|
1579
1633
|
async post(path, body) {
|
|
1580
1634
|
const response = await this.resilientFetch(`${this.baseUrl}${path}`, {
|
|
@@ -1596,13 +1650,16 @@ var CimplifyClient = class {
|
|
|
1596
1650
|
return this.handleRestResponse(response);
|
|
1597
1651
|
}
|
|
1598
1652
|
async linkGet(path) {
|
|
1599
|
-
const
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1653
|
+
const key = this.getDedupeKey("linkGet", path);
|
|
1654
|
+
return this.deduplicatedRequest(key, async () => {
|
|
1655
|
+
const response = await this.resilientFetch(`${this.linkApiUrl}${path}`, {
|
|
1656
|
+
method: "GET",
|
|
1657
|
+
credentials: this.credentials,
|
|
1658
|
+
headers: this.getHeaders()
|
|
1659
|
+
});
|
|
1660
|
+
this.updateSessionFromResponse(response);
|
|
1661
|
+
return this.handleRestResponse(response);
|
|
1603
1662
|
});
|
|
1604
|
-
this.updateSessionFromResponse(response);
|
|
1605
|
-
return this.handleRestResponse(response);
|
|
1606
1663
|
}
|
|
1607
1664
|
async linkPost(path, body) {
|
|
1608
1665
|
const response = await this.resilientFetch(`${this.linkApiUrl}${path}`, {
|
|
@@ -2261,4 +2318,4 @@ function detectMobileMoneyProvider(phoneNumber) {
|
|
|
2261
2318
|
return null;
|
|
2262
2319
|
}
|
|
2263
2320
|
|
|
2264
|
-
export { AUTHORIZATION_TYPE, AUTH_MUTATION, AuthService, BusinessService, CHECKOUT_MODE, CHECKOUT_MUTATION, CHECKOUT_STEP, CURRENCY_SYMBOLS, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyClient, CimplifyError, DEFAULT_COUNTRY, DEFAULT_CURRENCY, ErrorCode, InventoryService, LINK_MUTATION, LINK_QUERY, LinkService, LiteService, MOBILE_MONEY_PROVIDER, MOBILE_MONEY_PROVIDERS, ORDER_MUTATION, ORDER_TYPE, OrderQueries, PAYMENT_METHOD, PAYMENT_MUTATION, PAYMENT_STATE, PICKUP_TIME_TYPE, QueryBuilder, SchedulingService, categorizePaymentError, combine, combineObject, createCimplifyClient, detectMobileMoneyProvider, err, extractPriceInfo, flatMap, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, fromPromise, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getOrElse, getProductCurrency, isCimplifyError, isErr, isOk, isOnSale, isRetryableError, mapError, mapResult, normalizePaymentResponse, normalizeStatusResponse, ok, parsePrice, parsePricePath, parsedPriceToPriceInfo, query, toNullable, tryCatch, unwrap };
|
|
2321
|
+
export { AUTHORIZATION_TYPE, AUTH_MUTATION, AuthService, BusinessService, CHECKOUT_MODE, CHECKOUT_MUTATION, CHECKOUT_STEP, CURRENCY_SYMBOLS, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyClient, CimplifyError, DEFAULT_COUNTRY, DEFAULT_CURRENCY, ErrorCode, InventoryService, LINK_MUTATION, LINK_QUERY, LinkService, LiteService, MOBILE_MONEY_PROVIDER, MOBILE_MONEY_PROVIDERS, ORDER_MUTATION, ORDER_TYPE, OrderQueries, PAYMENT_METHOD, PAYMENT_MUTATION, PAYMENT_STATE, PICKUP_TIME_TYPE, QueryBuilder, SchedulingService, categorizePaymentError, combine, combineObject, createCimplifyClient, detectMobileMoneyProvider, err, extractPriceInfo, flatMap, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, fromPromise, generateIdempotencyKey, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getOrElse, getProductCurrency, isCimplifyError, isErr, isOk, isOnSale, isRetryableError, mapError, mapResult, normalizePaymentResponse, normalizeStatusResponse, ok, parsePrice, parsePricePath, parsedPriceToPriceInfo, query, toNullable, tryCatch, unwrap };
|