brainerce 1.28.0 → 1.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +38 -1
- package/dist/index.d.ts +38 -1
- package/dist/index.js +56 -1
- package/dist/index.mjs +53 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -9245,4 +9245,41 @@ declare function isAllowedPaymentUrl(url: string, options?: PaymentUrlOptions):
|
|
|
9245
9245
|
*/
|
|
9246
9246
|
declare function safePaymentRedirect(url: string, options?: PaymentUrlOptions): void;
|
|
9247
9247
|
|
|
9248
|
-
|
|
9248
|
+
interface FormatProductPriceOptions {
|
|
9249
|
+
/**
|
|
9250
|
+
* BCP-47 locale for `Intl.NumberFormat`. Controls number grouping and
|
|
9251
|
+
* currency-symbol placement. Defaults to the browser locale (client) or
|
|
9252
|
+
* `"en"` (SSR / Node).
|
|
9253
|
+
*/
|
|
9254
|
+
locale?: string;
|
|
9255
|
+
/**
|
|
9256
|
+
* When the product has both a regular price and a sale price, which one to
|
|
9257
|
+
* format. Defaults to `"sale-if-available"` — i.e. prefer the discounted
|
|
9258
|
+
* price when set, fall back to the regular price. Pass `"base"` to always
|
|
9259
|
+
* format the regular price (useful for crossed-out display alongside sale).
|
|
9260
|
+
*/
|
|
9261
|
+
prefer?: 'sale-if-available' | 'base';
|
|
9262
|
+
/**
|
|
9263
|
+
* Fallback ISO 4217 currency to use when a product has no
|
|
9264
|
+
* `displayCurrency` (i.e. the read wasn't region-scoped or the buyer is in
|
|
9265
|
+
* the default region). Usually the store's `currency` from `getStoreInfo()`.
|
|
9266
|
+
* If omitted, the helper returns just the numeric amount (no symbol).
|
|
9267
|
+
*/
|
|
9268
|
+
storeCurrency?: string;
|
|
9269
|
+
}
|
|
9270
|
+
/**
|
|
9271
|
+
* Format a product's price for display. Picks the region-converted
|
|
9272
|
+
* `displayPrice` / `displayCurrency` when present (set by the backend when
|
|
9273
|
+
* the read was region-scoped); otherwise falls back to the canonical
|
|
9274
|
+
* `basePrice` / `salePrice` in the store currency.
|
|
9275
|
+
*
|
|
9276
|
+
* Returns a localized string like `"€97.76"` or `"₪399.00"`. Returns `null`
|
|
9277
|
+
* when no price is available (e.g. a draft product with no base price yet).
|
|
9278
|
+
*/
|
|
9279
|
+
declare function formatProductPrice(product: Pick<Product, 'basePrice' | 'salePrice' | 'displayPrice' | 'displaySalePrice' | 'displayCurrency'>, options?: FormatProductPriceOptions): string | null;
|
|
9280
|
+
/** Same as `formatProductPrice` but for a `ProductVariant`. */
|
|
9281
|
+
declare function formatVariantPrice(variant: Pick<ProductVariant, 'price' | 'salePrice' | 'displayPrice' | 'displaySalePrice' | 'displayCurrency'>, options?: FormatProductPriceOptions): string | null;
|
|
9282
|
+
/** Format any numeric amount as currency. Useful for cart totals, fees, etc. */
|
|
9283
|
+
declare function formatMoney(amount: number, currency: string, locale?: string): string;
|
|
9284
|
+
|
|
9285
|
+
export { type AddToCartDto, type AnnouncementContent, type AnnouncementSeverity, type AppliedDiscount, type ApplyCouponDto, type AttachModifierGroupInput, type Attribute, type AttributeOption, type AttributeSource, type BrainerceApiError, BrainerceClient, type BrainerceClientOptions, BrainerceError, type Brand, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type Cart, type CartAppliedDiscount, type CartBundleOffer, type CartBundlesResponse, type CartIncludeOption, type CartIncludeOptions, type CartItem, type CartItemModifierLine, type CartNudge, type CartRecommendationsResponse, type CartStatus, type CartUpgradeSuggestion, type CartUpgradesResponse, type CartWithIncludes, type Category, type CategoryNode, type CategorySuggestion, type Checkout, type CheckoutAddress, type CheckoutBumpsResponse, type CheckoutCustomFieldDefinition, type CheckoutFieldPricing, type CheckoutFieldVisibility, type CheckoutLineItem, type CheckoutPrefillData, type CheckoutStatus, type CompleteCheckoutResponse, type CompleteDraftDto, type ConfigureOAuthProviderDto as ConfigureOAuthProviderInput, type ConflictStatus, type ConnectorPlatform, type ContactFormFieldType, type ContactFormFieldValidation, type ContactFormPublic, type ContactFormPublicField, type ContactFormSummary, type Content, type ContentDataMap, type ContentStatus, type ContentSummary, type ContentType, type Coupon, type CouponCreateResponse, type CouponQueryParams, type CouponStatus, type CouponType, type CouponValidationWarning, type CreateAddressDto, type CreateAttributeDto as CreateAttributeInput, type CreateAttributeOptionDto as CreateAttributeOptionInput, type CreateBrandDto as CreateBrandInput, type CreateCategoryDto as CreateCategoryInput, type CreateCheckoutDto, type CreateContentInput, type CreateCouponDto, type CreateCustomApiDto, type CreateCustomerDto, type CreateEmailTemplateDto as CreateEmailTemplateInput, type CreateGuestOrderDto, type CreateInquiryInput, type CreateInquiryResponse, type CreateMetafieldDefinitionDto as CreateMetafieldDefinitionInput, type CreateModifierGroupInput, type CreateModifierInput, type CreateOrderDto, type CreateProductDto, type CreateRefundDto, type CreateShippingRateDto as CreateShippingRateInput, type CreateShippingZoneDto as CreateShippingZoneInput, type CreateTagDto as CreateTagInput, type CreateTaxRateDto as CreateTaxRateInput, 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 DeleteProductResponse, type DiscountBanner, type DiscountRuleType, type DownloadFile, type DraftLineItem, type EditInventoryDto, type EmailDomain, type EmailEventSettings, type EmailEventType, type EmailSettings, type EmailTemplate, type EmailTemplatePreview, type EmailTemplatesResponse, type EmailVerificationResponse, type ExtendReservationResponse, type FaqContent, type FaqItem, type FooterColumn, type FooterContent, type FooterLink, type FooterSocialLink, type FormatPriceOptions, type FormatProductPriceOptions, type FreeAllocationPolicy, type FulfillOrderDto, type GuestCheckoutStartResponse, type GuestOrderResponse, type HeaderContent, type HeaderCta, type HeaderLogo, type HeaderNavItem, type InsufficientStockError, type InventoryInfo, type InventoryReservationStrategy, type InventorySyncStatus, type InventoryTrackingMode, type InvitationStatus, type InviteMemberDto as InviteMemberInput, type InviteStoreMemberDto as InviteStoreMemberInput, type ListModifierGroupsParams, type LocalCart, type LocalCartItem, type LockedVariant, type MergeCartsDto, type MetafieldConflict, type MetafieldConflictResolution, type MetafieldDefinition, type MetafieldType, type Modifier, type ModifierGroup, type ModifierSelection, type ModifierSelectionType, type ModifierValidationCode, type ModifierValidationError, type OAuthAuthorizeResponse, type OAuthCallbackResponse, type OAuthConnection, type OAuthConnectionsResponse, type OAuthProviderConfig, type OAuthProviderType, type OAuthProvidersResponse, type Order, type OrderAddress, type OrderBump, type OrderCustomer, type OrderDownloadLink, type OrderItem, type OrderQueryParams, type OrderStatus, type OrderStatusChange, type PageContent, type PageSeo, type PaginatedResponse, type PaymentClientSdk, type PaymentConfig, type PaymentIntent, type PaymentProvider, type PaymentProviderConfig, type PaymentProvidersConfig, type PaymentStatus, type PaymentUrlOptions, type PickupLocation, type PlatformCouponCapabilities, type PlatformMetafieldMetadata, type PreviewEmailTemplateDto as PreviewEmailTemplateInput, type Product, type ProductAttributeInput, type ProductAvailability, type ProductCustomizationField, type ProductDiscount, type ProductDiscountBadge, type ProductImage, type ProductMetafield, type ProductMetafieldValue, type ProductModifierGroupAttachment, type ProductQueryParams, type ProductRecommendation, type ProductRecommendationsResponse, type ProductRelationType, type ProductSuggestion, type ProductVariant, type PublicMetafieldDefinition, type PublishProductResponse, RTL_LOCALES, type RecommendationVariant, type ReconcileInventoryResponse, type Refund, type RefundLineItem, type RefundLineItemResponse, type RefundType, type RegisterCustomerDto, type ReservationInfo, type ResolveMetafieldConflictDto as ResolveMetafieldConflictInput, type ResolveSyncConflictDto as ResolveSyncConflictInput, type RichTextContent, SDK_VERSION, type SearchSuggestions, type SelectPickupLocationDto, type SelectShippingMethodDto, type SendInvoiceDto, type SessionCartRef, type SetBillingAddressDto, type SetCheckoutCustomFieldsDto, type SetCheckoutCustomerDto, type SetDefinitionProductsDto as SetDefinitionProductsInput, type SetMetafieldPlatformsDto as SetMetafieldPlatformsInput, type SetShippingAddressDto, type SetShippingAddressResponse, type ShippingDestinations, type ShippingLine, type ShippingRate, type ShippingRateConfig, type ShippingRateType, type ShippingZone, type ShippingZoneQueryParams, type StockAvailabilityRequest, type StockAvailabilityResponse, type StockAvailabilityResult, type StoreInfo, type StoreInvitation, type StoreInvitationDetails, type StoreMember, type StorePermission, type StoreRole, type StoreTeamResponse, type SupportedLocaleObject, type SyncConflict, type SyncConflictResolution, type SyncJob, type Tag, type TaxBreakdown, type TaxBreakdownItem, type TaxRate, type TaxonomyQueryParams, type TeamInvitation, type TeamInvitationsResponse, type TeamMember, type TeamMembersResponse, type TeamRole, type UpdateAddressDto, type UpdateAttachmentInput, type UpdateAttributeDto as UpdateAttributeInput, type UpdateAttributeOptionDto as UpdateAttributeOptionInput, type UpdateBrandDto as UpdateBrandInput, type UpdateCartItemDto, type UpdateCategoryDto as UpdateCategoryInput, type UpdateContentInput, type UpdateCouponDto, type UpdateCustomApiDto, type UpdateCustomerDto, type UpdateDraftDto, type UpdateEmailSettingsDto as UpdateEmailSettingsInput, type UpdateEmailTemplateDto as UpdateEmailTemplateInput, type UpdateInventoryDto, type UpdateMemberRoleDto as UpdateMemberRoleInput, type UpdateMetafieldDefinitionDto as UpdateMetafieldDefinitionInput, type UpdateModifierGroupInput, type UpdateModifierInput, type UpdateOAuthProviderDto as UpdateOAuthProviderInput, type UpdateOrderDto, type UpdateOrderShippingDto, type UpdateProductDto, type UpdateShippingRateDto as UpdateShippingRateInput, type UpdateShippingZoneDto as UpdateShippingZoneInput, type UpdateStoreMemberDto as UpdateStoreMemberInput, type UpdateTagDto as UpdateTagInput, type UpdateTaxRateDto as UpdateTaxRateInput, type UpdateVariantDto, type UpdateVariantInventoryDto, type UpsertProductMetafieldDto as UpsertProductMetafieldInput, type UserStore, type UserStorePermissions, type VariantInventoryResponse, type VariantPlatformOverlay, type VariantStatus, type WaitForOrderOptions, type WaitForOrderResult, type WebhookEvent, type WebhookEventType, createWebhookHandler, deriveSeoDescription, enableDevGuards, formatMoney, formatPrice, formatProductPrice, formatVariantPrice, getCartItemImage, getCartItemName, getCartTotals, getDescriptionContent, getDirectionForLocale, formatPrice as getPriceDisplay, getProductCustomizationFields, getProductMetafield, getProductMetafieldValue, getProductMetafieldsByType, getProductPrice, getProductPriceInfo, getProductSwatches, getStockStatus, getVariantOptions, getVariantPrice, isAllowedPaymentUrl, isCouponApplicableToProduct, isHtmlDescription, isWebhookEventType, parseWebhookEvent, safePaymentRedirect, stripHtml, verifyWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -9245,4 +9245,41 @@ declare function isAllowedPaymentUrl(url: string, options?: PaymentUrlOptions):
|
|
|
9245
9245
|
*/
|
|
9246
9246
|
declare function safePaymentRedirect(url: string, options?: PaymentUrlOptions): void;
|
|
9247
9247
|
|
|
9248
|
-
|
|
9248
|
+
interface FormatProductPriceOptions {
|
|
9249
|
+
/**
|
|
9250
|
+
* BCP-47 locale for `Intl.NumberFormat`. Controls number grouping and
|
|
9251
|
+
* currency-symbol placement. Defaults to the browser locale (client) or
|
|
9252
|
+
* `"en"` (SSR / Node).
|
|
9253
|
+
*/
|
|
9254
|
+
locale?: string;
|
|
9255
|
+
/**
|
|
9256
|
+
* When the product has both a regular price and a sale price, which one to
|
|
9257
|
+
* format. Defaults to `"sale-if-available"` — i.e. prefer the discounted
|
|
9258
|
+
* price when set, fall back to the regular price. Pass `"base"` to always
|
|
9259
|
+
* format the regular price (useful for crossed-out display alongside sale).
|
|
9260
|
+
*/
|
|
9261
|
+
prefer?: 'sale-if-available' | 'base';
|
|
9262
|
+
/**
|
|
9263
|
+
* Fallback ISO 4217 currency to use when a product has no
|
|
9264
|
+
* `displayCurrency` (i.e. the read wasn't region-scoped or the buyer is in
|
|
9265
|
+
* the default region). Usually the store's `currency` from `getStoreInfo()`.
|
|
9266
|
+
* If omitted, the helper returns just the numeric amount (no symbol).
|
|
9267
|
+
*/
|
|
9268
|
+
storeCurrency?: string;
|
|
9269
|
+
}
|
|
9270
|
+
/**
|
|
9271
|
+
* Format a product's price for display. Picks the region-converted
|
|
9272
|
+
* `displayPrice` / `displayCurrency` when present (set by the backend when
|
|
9273
|
+
* the read was region-scoped); otherwise falls back to the canonical
|
|
9274
|
+
* `basePrice` / `salePrice` in the store currency.
|
|
9275
|
+
*
|
|
9276
|
+
* Returns a localized string like `"€97.76"` or `"₪399.00"`. Returns `null`
|
|
9277
|
+
* when no price is available (e.g. a draft product with no base price yet).
|
|
9278
|
+
*/
|
|
9279
|
+
declare function formatProductPrice(product: Pick<Product, 'basePrice' | 'salePrice' | 'displayPrice' | 'displaySalePrice' | 'displayCurrency'>, options?: FormatProductPriceOptions): string | null;
|
|
9280
|
+
/** Same as `formatProductPrice` but for a `ProductVariant`. */
|
|
9281
|
+
declare function formatVariantPrice(variant: Pick<ProductVariant, 'price' | 'salePrice' | 'displayPrice' | 'displaySalePrice' | 'displayCurrency'>, options?: FormatProductPriceOptions): string | null;
|
|
9282
|
+
/** Format any numeric amount as currency. Useful for cart totals, fees, etc. */
|
|
9283
|
+
declare function formatMoney(amount: number, currency: string, locale?: string): string;
|
|
9284
|
+
|
|
9285
|
+
export { type AddToCartDto, type AnnouncementContent, type AnnouncementSeverity, type AppliedDiscount, type ApplyCouponDto, type AttachModifierGroupInput, type Attribute, type AttributeOption, type AttributeSource, type BrainerceApiError, BrainerceClient, type BrainerceClientOptions, BrainerceError, type Brand, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type Cart, type CartAppliedDiscount, type CartBundleOffer, type CartBundlesResponse, type CartIncludeOption, type CartIncludeOptions, type CartItem, type CartItemModifierLine, type CartNudge, type CartRecommendationsResponse, type CartStatus, type CartUpgradeSuggestion, type CartUpgradesResponse, type CartWithIncludes, type Category, type CategoryNode, type CategorySuggestion, type Checkout, type CheckoutAddress, type CheckoutBumpsResponse, type CheckoutCustomFieldDefinition, type CheckoutFieldPricing, type CheckoutFieldVisibility, type CheckoutLineItem, type CheckoutPrefillData, type CheckoutStatus, type CompleteCheckoutResponse, type CompleteDraftDto, type ConfigureOAuthProviderDto as ConfigureOAuthProviderInput, type ConflictStatus, type ConnectorPlatform, type ContactFormFieldType, type ContactFormFieldValidation, type ContactFormPublic, type ContactFormPublicField, type ContactFormSummary, type Content, type ContentDataMap, type ContentStatus, type ContentSummary, type ContentType, type Coupon, type CouponCreateResponse, type CouponQueryParams, type CouponStatus, type CouponType, type CouponValidationWarning, type CreateAddressDto, type CreateAttributeDto as CreateAttributeInput, type CreateAttributeOptionDto as CreateAttributeOptionInput, type CreateBrandDto as CreateBrandInput, type CreateCategoryDto as CreateCategoryInput, type CreateCheckoutDto, type CreateContentInput, type CreateCouponDto, type CreateCustomApiDto, type CreateCustomerDto, type CreateEmailTemplateDto as CreateEmailTemplateInput, type CreateGuestOrderDto, type CreateInquiryInput, type CreateInquiryResponse, type CreateMetafieldDefinitionDto as CreateMetafieldDefinitionInput, type CreateModifierGroupInput, type CreateModifierInput, type CreateOrderDto, type CreateProductDto, type CreateRefundDto, type CreateShippingRateDto as CreateShippingRateInput, type CreateShippingZoneDto as CreateShippingZoneInput, type CreateTagDto as CreateTagInput, type CreateTaxRateDto as CreateTaxRateInput, 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 DeleteProductResponse, type DiscountBanner, type DiscountRuleType, type DownloadFile, type DraftLineItem, type EditInventoryDto, type EmailDomain, type EmailEventSettings, type EmailEventType, type EmailSettings, type EmailTemplate, type EmailTemplatePreview, type EmailTemplatesResponse, type EmailVerificationResponse, type ExtendReservationResponse, type FaqContent, type FaqItem, type FooterColumn, type FooterContent, type FooterLink, type FooterSocialLink, type FormatPriceOptions, type FormatProductPriceOptions, type FreeAllocationPolicy, type FulfillOrderDto, type GuestCheckoutStartResponse, type GuestOrderResponse, type HeaderContent, type HeaderCta, type HeaderLogo, type HeaderNavItem, type InsufficientStockError, type InventoryInfo, type InventoryReservationStrategy, type InventorySyncStatus, type InventoryTrackingMode, type InvitationStatus, type InviteMemberDto as InviteMemberInput, type InviteStoreMemberDto as InviteStoreMemberInput, type ListModifierGroupsParams, type LocalCart, type LocalCartItem, type LockedVariant, type MergeCartsDto, type MetafieldConflict, type MetafieldConflictResolution, type MetafieldDefinition, type MetafieldType, type Modifier, type ModifierGroup, type ModifierSelection, type ModifierSelectionType, type ModifierValidationCode, type ModifierValidationError, type OAuthAuthorizeResponse, type OAuthCallbackResponse, type OAuthConnection, type OAuthConnectionsResponse, type OAuthProviderConfig, type OAuthProviderType, type OAuthProvidersResponse, type Order, type OrderAddress, type OrderBump, type OrderCustomer, type OrderDownloadLink, type OrderItem, type OrderQueryParams, type OrderStatus, type OrderStatusChange, type PageContent, type PageSeo, type PaginatedResponse, type PaymentClientSdk, type PaymentConfig, type PaymentIntent, type PaymentProvider, type PaymentProviderConfig, type PaymentProvidersConfig, type PaymentStatus, type PaymentUrlOptions, type PickupLocation, type PlatformCouponCapabilities, type PlatformMetafieldMetadata, type PreviewEmailTemplateDto as PreviewEmailTemplateInput, type Product, type ProductAttributeInput, type ProductAvailability, type ProductCustomizationField, type ProductDiscount, type ProductDiscountBadge, type ProductImage, type ProductMetafield, type ProductMetafieldValue, type ProductModifierGroupAttachment, type ProductQueryParams, type ProductRecommendation, type ProductRecommendationsResponse, type ProductRelationType, type ProductSuggestion, type ProductVariant, type PublicMetafieldDefinition, type PublishProductResponse, RTL_LOCALES, type RecommendationVariant, type ReconcileInventoryResponse, type Refund, type RefundLineItem, type RefundLineItemResponse, type RefundType, type RegisterCustomerDto, type ReservationInfo, type ResolveMetafieldConflictDto as ResolveMetafieldConflictInput, type ResolveSyncConflictDto as ResolveSyncConflictInput, type RichTextContent, SDK_VERSION, type SearchSuggestions, type SelectPickupLocationDto, type SelectShippingMethodDto, type SendInvoiceDto, type SessionCartRef, type SetBillingAddressDto, type SetCheckoutCustomFieldsDto, type SetCheckoutCustomerDto, type SetDefinitionProductsDto as SetDefinitionProductsInput, type SetMetafieldPlatformsDto as SetMetafieldPlatformsInput, type SetShippingAddressDto, type SetShippingAddressResponse, type ShippingDestinations, type ShippingLine, type ShippingRate, type ShippingRateConfig, type ShippingRateType, type ShippingZone, type ShippingZoneQueryParams, type StockAvailabilityRequest, type StockAvailabilityResponse, type StockAvailabilityResult, type StoreInfo, type StoreInvitation, type StoreInvitationDetails, type StoreMember, type StorePermission, type StoreRole, type StoreTeamResponse, type SupportedLocaleObject, type SyncConflict, type SyncConflictResolution, type SyncJob, type Tag, type TaxBreakdown, type TaxBreakdownItem, type TaxRate, type TaxonomyQueryParams, type TeamInvitation, type TeamInvitationsResponse, type TeamMember, type TeamMembersResponse, type TeamRole, type UpdateAddressDto, type UpdateAttachmentInput, type UpdateAttributeDto as UpdateAttributeInput, type UpdateAttributeOptionDto as UpdateAttributeOptionInput, type UpdateBrandDto as UpdateBrandInput, type UpdateCartItemDto, type UpdateCategoryDto as UpdateCategoryInput, type UpdateContentInput, type UpdateCouponDto, type UpdateCustomApiDto, type UpdateCustomerDto, type UpdateDraftDto, type UpdateEmailSettingsDto as UpdateEmailSettingsInput, type UpdateEmailTemplateDto as UpdateEmailTemplateInput, type UpdateInventoryDto, type UpdateMemberRoleDto as UpdateMemberRoleInput, type UpdateMetafieldDefinitionDto as UpdateMetafieldDefinitionInput, type UpdateModifierGroupInput, type UpdateModifierInput, type UpdateOAuthProviderDto as UpdateOAuthProviderInput, type UpdateOrderDto, type UpdateOrderShippingDto, type UpdateProductDto, type UpdateShippingRateDto as UpdateShippingRateInput, type UpdateShippingZoneDto as UpdateShippingZoneInput, type UpdateStoreMemberDto as UpdateStoreMemberInput, type UpdateTagDto as UpdateTagInput, type UpdateTaxRateDto as UpdateTaxRateInput, type UpdateVariantDto, type UpdateVariantInventoryDto, type UpsertProductMetafieldDto as UpsertProductMetafieldInput, type UserStore, type UserStorePermissions, type VariantInventoryResponse, type VariantPlatformOverlay, type VariantStatus, type WaitForOrderOptions, type WaitForOrderResult, type WebhookEvent, type WebhookEventType, createWebhookHandler, deriveSeoDescription, enableDevGuards, formatMoney, formatPrice, formatProductPrice, formatVariantPrice, getCartItemImage, getCartItemName, getCartTotals, getDescriptionContent, getDirectionForLocale, formatPrice as getPriceDisplay, getProductCustomizationFields, getProductMetafield, getProductMetafieldValue, getProductMetafieldsByType, getProductPrice, getProductPriceInfo, getProductSwatches, getStockStatus, getVariantOptions, getVariantPrice, isAllowedPaymentUrl, isCouponApplicableToProduct, isHtmlDescription, isWebhookEventType, parseWebhookEvent, safePaymentRedirect, stripHtml, verifyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,10 @@ __export(index_exports, {
|
|
|
37
37
|
createWebhookHandler: () => createWebhookHandler,
|
|
38
38
|
deriveSeoDescription: () => deriveSeoDescription,
|
|
39
39
|
enableDevGuards: () => enableDevGuards,
|
|
40
|
+
formatMoney: () => formatMoney,
|
|
40
41
|
formatPrice: () => formatPrice,
|
|
42
|
+
formatProductPrice: () => formatProductPrice,
|
|
43
|
+
formatVariantPrice: () => formatVariantPrice,
|
|
41
44
|
getCartItemImage: () => getCartItemImage,
|
|
42
45
|
getCartItemName: () => getCartItemName,
|
|
43
46
|
getCartTotals: () => getCartTotals,
|
|
@@ -8038,6 +8041,55 @@ function safePaymentRedirect(url, options) {
|
|
|
8038
8041
|
}
|
|
8039
8042
|
}
|
|
8040
8043
|
|
|
8044
|
+
// src/format-price.ts
|
|
8045
|
+
var DEFAULT_LOCALE = "en";
|
|
8046
|
+
function formatProductPrice(product, options = {}) {
|
|
8047
|
+
const { locale = DEFAULT_LOCALE, prefer = "sale-if-available", storeCurrency } = options;
|
|
8048
|
+
const usingDisplay = product.displayPrice != null;
|
|
8049
|
+
const currency = usingDisplay ? product.displayCurrency : storeCurrency;
|
|
8050
|
+
const baseAmount = usingDisplay ? product.displayPrice : product.basePrice;
|
|
8051
|
+
const saleAmount = usingDisplay ? product.displaySalePrice : product.salePrice;
|
|
8052
|
+
const amount = prefer === "sale-if-available" && saleAmount != null && saleAmount !== "" ? saleAmount : baseAmount;
|
|
8053
|
+
if (amount == null || amount === "") return null;
|
|
8054
|
+
const parsed = parseFloat(amount);
|
|
8055
|
+
if (Number.isNaN(parsed)) return null;
|
|
8056
|
+
return formatAmount(parsed, currency, locale);
|
|
8057
|
+
}
|
|
8058
|
+
function formatVariantPrice(variant, options = {}) {
|
|
8059
|
+
const { locale = DEFAULT_LOCALE, prefer = "sale-if-available", storeCurrency } = options;
|
|
8060
|
+
const usingDisplay = variant.displayPrice != null;
|
|
8061
|
+
const currency = usingDisplay ? variant.displayCurrency : storeCurrency;
|
|
8062
|
+
const baseAmount = usingDisplay ? variant.displayPrice : variant.price;
|
|
8063
|
+
const saleAmount = usingDisplay ? variant.displaySalePrice : variant.salePrice;
|
|
8064
|
+
const amount = prefer === "sale-if-available" && saleAmount != null && saleAmount !== "" ? saleAmount : baseAmount;
|
|
8065
|
+
if (amount == null || amount === "") return null;
|
|
8066
|
+
const parsed = parseFloat(amount);
|
|
8067
|
+
if (Number.isNaN(parsed)) return null;
|
|
8068
|
+
return formatAmount(parsed, currency, locale);
|
|
8069
|
+
}
|
|
8070
|
+
function formatMoney(amount, currency, locale = DEFAULT_LOCALE) {
|
|
8071
|
+
return formatAmount(amount, currency, locale);
|
|
8072
|
+
}
|
|
8073
|
+
function formatAmount(amount, currency, locale) {
|
|
8074
|
+
if (!currency) {
|
|
8075
|
+
return new Intl.NumberFormat(locale, {
|
|
8076
|
+
minimumFractionDigits: 2,
|
|
8077
|
+
maximumFractionDigits: 2
|
|
8078
|
+
}).format(amount);
|
|
8079
|
+
}
|
|
8080
|
+
try {
|
|
8081
|
+
return new Intl.NumberFormat(locale, {
|
|
8082
|
+
style: "currency",
|
|
8083
|
+
currency
|
|
8084
|
+
}).format(amount);
|
|
8085
|
+
} catch {
|
|
8086
|
+
return new Intl.NumberFormat(locale, {
|
|
8087
|
+
minimumFractionDigits: 2,
|
|
8088
|
+
maximumFractionDigits: 2
|
|
8089
|
+
}).format(amount);
|
|
8090
|
+
}
|
|
8091
|
+
}
|
|
8092
|
+
|
|
8041
8093
|
// src/types.ts
|
|
8042
8094
|
function isHtmlDescription(product) {
|
|
8043
8095
|
if (product?.descriptionFormat === "html") return true;
|
|
@@ -8179,7 +8231,7 @@ function getCartTotals(cart, shippingPrice) {
|
|
|
8179
8231
|
const subtotal = parseFloat(cart.subtotal) || 0;
|
|
8180
8232
|
const discount = parseFloat(cart.discountAmount) || 0;
|
|
8181
8233
|
const shipping = typeof shippingPrice === "string" ? parseFloat(shippingPrice) || 0 : shippingPrice || 0;
|
|
8182
|
-
const total = subtotal - discount + shipping;
|
|
8234
|
+
const total = Math.max(0, subtotal - discount + shipping);
|
|
8183
8235
|
return { subtotal, discount, shipping, total };
|
|
8184
8236
|
}
|
|
8185
8237
|
function getCartItemName(item) {
|
|
@@ -8287,7 +8339,10 @@ function isCouponApplicableToProduct(coupon, productId) {
|
|
|
8287
8339
|
createWebhookHandler,
|
|
8288
8340
|
deriveSeoDescription,
|
|
8289
8341
|
enableDevGuards,
|
|
8342
|
+
formatMoney,
|
|
8290
8343
|
formatPrice,
|
|
8344
|
+
formatProductPrice,
|
|
8345
|
+
formatVariantPrice,
|
|
8291
8346
|
getCartItemImage,
|
|
8292
8347
|
getCartItemName,
|
|
8293
8348
|
getCartTotals,
|
package/dist/index.mjs
CHANGED
|
@@ -7971,6 +7971,55 @@ function safePaymentRedirect(url, options) {
|
|
|
7971
7971
|
}
|
|
7972
7972
|
}
|
|
7973
7973
|
|
|
7974
|
+
// src/format-price.ts
|
|
7975
|
+
var DEFAULT_LOCALE = "en";
|
|
7976
|
+
function formatProductPrice(product, options = {}) {
|
|
7977
|
+
const { locale = DEFAULT_LOCALE, prefer = "sale-if-available", storeCurrency } = options;
|
|
7978
|
+
const usingDisplay = product.displayPrice != null;
|
|
7979
|
+
const currency = usingDisplay ? product.displayCurrency : storeCurrency;
|
|
7980
|
+
const baseAmount = usingDisplay ? product.displayPrice : product.basePrice;
|
|
7981
|
+
const saleAmount = usingDisplay ? product.displaySalePrice : product.salePrice;
|
|
7982
|
+
const amount = prefer === "sale-if-available" && saleAmount != null && saleAmount !== "" ? saleAmount : baseAmount;
|
|
7983
|
+
if (amount == null || amount === "") return null;
|
|
7984
|
+
const parsed = parseFloat(amount);
|
|
7985
|
+
if (Number.isNaN(parsed)) return null;
|
|
7986
|
+
return formatAmount(parsed, currency, locale);
|
|
7987
|
+
}
|
|
7988
|
+
function formatVariantPrice(variant, options = {}) {
|
|
7989
|
+
const { locale = DEFAULT_LOCALE, prefer = "sale-if-available", storeCurrency } = options;
|
|
7990
|
+
const usingDisplay = variant.displayPrice != null;
|
|
7991
|
+
const currency = usingDisplay ? variant.displayCurrency : storeCurrency;
|
|
7992
|
+
const baseAmount = usingDisplay ? variant.displayPrice : variant.price;
|
|
7993
|
+
const saleAmount = usingDisplay ? variant.displaySalePrice : variant.salePrice;
|
|
7994
|
+
const amount = prefer === "sale-if-available" && saleAmount != null && saleAmount !== "" ? saleAmount : baseAmount;
|
|
7995
|
+
if (amount == null || amount === "") return null;
|
|
7996
|
+
const parsed = parseFloat(amount);
|
|
7997
|
+
if (Number.isNaN(parsed)) return null;
|
|
7998
|
+
return formatAmount(parsed, currency, locale);
|
|
7999
|
+
}
|
|
8000
|
+
function formatMoney(amount, currency, locale = DEFAULT_LOCALE) {
|
|
8001
|
+
return formatAmount(amount, currency, locale);
|
|
8002
|
+
}
|
|
8003
|
+
function formatAmount(amount, currency, locale) {
|
|
8004
|
+
if (!currency) {
|
|
8005
|
+
return new Intl.NumberFormat(locale, {
|
|
8006
|
+
minimumFractionDigits: 2,
|
|
8007
|
+
maximumFractionDigits: 2
|
|
8008
|
+
}).format(amount);
|
|
8009
|
+
}
|
|
8010
|
+
try {
|
|
8011
|
+
return new Intl.NumberFormat(locale, {
|
|
8012
|
+
style: "currency",
|
|
8013
|
+
currency
|
|
8014
|
+
}).format(amount);
|
|
8015
|
+
} catch {
|
|
8016
|
+
return new Intl.NumberFormat(locale, {
|
|
8017
|
+
minimumFractionDigits: 2,
|
|
8018
|
+
maximumFractionDigits: 2
|
|
8019
|
+
}).format(amount);
|
|
8020
|
+
}
|
|
8021
|
+
}
|
|
8022
|
+
|
|
7974
8023
|
// src/types.ts
|
|
7975
8024
|
function isHtmlDescription(product) {
|
|
7976
8025
|
if (product?.descriptionFormat === "html") return true;
|
|
@@ -8112,7 +8161,7 @@ function getCartTotals(cart, shippingPrice) {
|
|
|
8112
8161
|
const subtotal = parseFloat(cart.subtotal) || 0;
|
|
8113
8162
|
const discount = parseFloat(cart.discountAmount) || 0;
|
|
8114
8163
|
const shipping = typeof shippingPrice === "string" ? parseFloat(shippingPrice) || 0 : shippingPrice || 0;
|
|
8115
|
-
const total = subtotal - discount + shipping;
|
|
8164
|
+
const total = Math.max(0, subtotal - discount + shipping);
|
|
8116
8165
|
return { subtotal, discount, shipping, total };
|
|
8117
8166
|
}
|
|
8118
8167
|
function getCartItemName(item) {
|
|
@@ -8219,7 +8268,10 @@ export {
|
|
|
8219
8268
|
createWebhookHandler,
|
|
8220
8269
|
deriveSeoDescription,
|
|
8221
8270
|
enableDevGuards,
|
|
8271
|
+
formatMoney,
|
|
8222
8272
|
formatPrice,
|
|
8273
|
+
formatProductPrice,
|
|
8274
|
+
formatVariantPrice,
|
|
8223
8275
|
getCartItemImage,
|
|
8224
8276
|
getCartItemName,
|
|
8225
8277
|
getCartTotals,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainerce",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.1",
|
|
4
4
|
"description": "Official SDK for building e-commerce storefronts with Brainerce 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",
|