brainerce 1.28.0 → 1.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3807,6 +3807,35 @@ interface PublicRegionPaymentProvider {
3807
3807
  interface PublicRegionDetail extends PublicRegion {
3808
3808
  paymentProviders: PublicRegionPaymentProvider[];
3809
3809
  }
3810
+ /**
3811
+ * Server-side region resolution for a buyer country (storefront seam).
3812
+ * `matched=true` → the country was explicitly listed by a region. `false` →
3813
+ * fell back to the default region (or `region=null` when no default exists).
3814
+ */
3815
+ interface AutoRegionResponse {
3816
+ region: PublicRegion | null;
3817
+ matched: boolean;
3818
+ /** Upper-cased ISO-3166-1 alpha-2. Empty string when caller omitted `country`. */
3819
+ country: string;
3820
+ }
3821
+ /**
3822
+ * Non-binding tax preview for PDP / PLP / cart. The authoritative calculation
3823
+ * still runs at checkout against the full shipping address (state / postal /
3824
+ * per-class). Render with an "Estimate" affordance.
3825
+ */
3826
+ interface TaxEstimateResponse {
3827
+ appliesTax: boolean;
3828
+ /** Percent — e.g. 18 for 18%. `null` when no matching rule. */
3829
+ rate: number | null;
3830
+ rateName: string | null;
3831
+ /** Tax portion of `subtotal` at the store's `pricesIncludeTax` mode. */
3832
+ estimatedTax: number;
3833
+ pricesIncludeTax: boolean;
3834
+ /** Store currency — the cart / order currency, unchanged by FX display overlay. */
3835
+ currency: string;
3836
+ /** Disclaimer copy — always present to surface the "preview, not binding" nature. */
3837
+ note: string;
3838
+ }
3810
3839
  interface CreateRegionDto {
3811
3840
  name: string;
3812
3841
  /** ISO 4217 */
@@ -8616,6 +8645,33 @@ declare class BrainerceClient {
8616
8645
  * `countries` includes `country`, else the default region, else null.
8617
8646
  */
8618
8647
  detectRegion(country: string, regions: Array<Region | PublicRegion>): Region | PublicRegion | null;
8648
+ /**
8649
+ * Server-side region resolution in one round trip (storefront seam). Pair
8650
+ * with the country your edge runtime extracts — Cloudflare `CF-IPCountry`,
8651
+ * Vercel `request.geo?.country`, Fastly `client-geo-country`, etc.
8652
+ *
8653
+ * Brainerce does NOT derive the country from the request IP server-side
8654
+ * because the storefront server is what reaches the backend (not the end-
8655
+ * customer). The storefront must extract + forward the country.
8656
+ *
8657
+ * Returns `{ region, matched, country }` — `matched=true` means the country
8658
+ * was explicitly listed by a region; `false` means we fell back to the
8659
+ * default region (or `region=null` if no default exists either).
8660
+ */
8661
+ getAutoRegion(country?: string): Promise<AutoRegionResponse>;
8662
+ /**
8663
+ * Non-binding tax preview for PDP / PLP / cart. Pass the buyer's country
8664
+ * (from your edge runtime — same source as `getAutoRegion`) and the current
8665
+ * items subtotal in the store currency. The authoritative tax still runs
8666
+ * at checkout — render with an "Estimate" affordance.
8667
+ *
8668
+ * Returns `appliesTax=false` when tax is disabled, the country is missing,
8669
+ * or no active rate covers it.
8670
+ */
8671
+ estimateTax(params: {
8672
+ country?: string;
8673
+ subtotal: number;
8674
+ }): Promise<TaxEstimateResponse>;
8619
8675
  /**
8620
8676
  * List the store's tax classes (public, no apiKey — storeId mode). Storefront-
8621
8677
  * safe fields only (id/name/slug/description/isDefault) for transparency UIs
@@ -9245,4 +9301,41 @@ declare function isAllowedPaymentUrl(url: string, options?: PaymentUrlOptions):
9245
9301
  */
9246
9302
  declare function safePaymentRedirect(url: string, options?: PaymentUrlOptions): void;
9247
9303
 
9248
- 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 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, formatPrice, 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 };
9304
+ interface FormatProductPriceOptions {
9305
+ /**
9306
+ * BCP-47 locale for `Intl.NumberFormat`. Controls number grouping and
9307
+ * currency-symbol placement. Defaults to the browser locale (client) or
9308
+ * `"en"` (SSR / Node).
9309
+ */
9310
+ locale?: string;
9311
+ /**
9312
+ * When the product has both a regular price and a sale price, which one to
9313
+ * format. Defaults to `"sale-if-available"` — i.e. prefer the discounted
9314
+ * price when set, fall back to the regular price. Pass `"base"` to always
9315
+ * format the regular price (useful for crossed-out display alongside sale).
9316
+ */
9317
+ prefer?: 'sale-if-available' | 'base';
9318
+ /**
9319
+ * Fallback ISO 4217 currency to use when a product has no
9320
+ * `displayCurrency` (i.e. the read wasn't region-scoped or the buyer is in
9321
+ * the default region). Usually the store's `currency` from `getStoreInfo()`.
9322
+ * If omitted, the helper returns just the numeric amount (no symbol).
9323
+ */
9324
+ storeCurrency?: string;
9325
+ }
9326
+ /**
9327
+ * Format a product's price for display. Picks the region-converted
9328
+ * `displayPrice` / `displayCurrency` when present (set by the backend when
9329
+ * the read was region-scoped); otherwise falls back to the canonical
9330
+ * `basePrice` / `salePrice` in the store currency.
9331
+ *
9332
+ * Returns a localized string like `"€97.76"` or `"₪399.00"`. Returns `null`
9333
+ * when no price is available (e.g. a draft product with no base price yet).
9334
+ */
9335
+ declare function formatProductPrice(product: Pick<Product, 'basePrice' | 'salePrice' | 'displayPrice' | 'displaySalePrice' | 'displayCurrency'>, options?: FormatProductPriceOptions): string | null;
9336
+ /** Same as `formatProductPrice` but for a `ProductVariant`. */
9337
+ declare function formatVariantPrice(variant: Pick<ProductVariant, 'price' | 'salePrice' | 'displayPrice' | 'displaySalePrice' | 'displayCurrency'>, options?: FormatProductPriceOptions): string | null;
9338
+ /** Format any numeric amount as currency. Useful for cart totals, fees, etc. */
9339
+ declare function formatMoney(amount: number, currency: string, locale?: string): string;
9340
+
9341
+ 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,
@@ -7051,6 +7054,44 @@ var BrainerceClient = class {
7051
7054
  const code = country.toUpperCase();
7052
7055
  return regions.find((r) => r.countries.includes(code)) ?? regions.find((r) => r.isDefault) ?? null;
7053
7056
  }
7057
+ /**
7058
+ * Server-side region resolution in one round trip (storefront seam). Pair
7059
+ * with the country your edge runtime extracts — Cloudflare `CF-IPCountry`,
7060
+ * Vercel `request.geo?.country`, Fastly `client-geo-country`, etc.
7061
+ *
7062
+ * Brainerce does NOT derive the country from the request IP server-side
7063
+ * because the storefront server is what reaches the backend (not the end-
7064
+ * customer). The storefront must extract + forward the country.
7065
+ *
7066
+ * Returns `{ region, matched, country }` — `matched=true` means the country
7067
+ * was explicitly listed by a region; `false` means we fell back to the
7068
+ * default region (or `region=null` if no default exists either).
7069
+ */
7070
+ async getAutoRegion(country) {
7071
+ return this.storefrontRequest(
7072
+ "GET",
7073
+ "/regions/auto",
7074
+ void 0,
7075
+ country ? { country } : void 0
7076
+ );
7077
+ }
7078
+ /**
7079
+ * Non-binding tax preview for PDP / PLP / cart. Pass the buyer's country
7080
+ * (from your edge runtime — same source as `getAutoRegion`) and the current
7081
+ * items subtotal in the store currency. The authoritative tax still runs
7082
+ * at checkout — render with an "Estimate" affordance.
7083
+ *
7084
+ * Returns `appliesTax=false` when tax is disabled, the country is missing,
7085
+ * or no active rate covers it.
7086
+ */
7087
+ async estimateTax(params) {
7088
+ return this.storefrontRequest(
7089
+ "GET",
7090
+ "/tax/estimate",
7091
+ void 0,
7092
+ params.country ? { country: params.country, subtotal: params.subtotal } : { subtotal: params.subtotal }
7093
+ );
7094
+ }
7054
7095
  // -------------------- Tax Classes (Storefront mode, public — no apiKey) --------------------
7055
7096
  /**
7056
7097
  * List the store's tax classes (public, no apiKey — storeId mode). Storefront-
@@ -8038,6 +8079,55 @@ function safePaymentRedirect(url, options) {
8038
8079
  }
8039
8080
  }
8040
8081
 
8082
+ // src/format-price.ts
8083
+ var DEFAULT_LOCALE = "en";
8084
+ function formatProductPrice(product, options = {}) {
8085
+ const { locale = DEFAULT_LOCALE, prefer = "sale-if-available", storeCurrency } = options;
8086
+ const usingDisplay = product.displayPrice != null;
8087
+ const currency = usingDisplay ? product.displayCurrency : storeCurrency;
8088
+ const baseAmount = usingDisplay ? product.displayPrice : product.basePrice;
8089
+ const saleAmount = usingDisplay ? product.displaySalePrice : product.salePrice;
8090
+ const amount = prefer === "sale-if-available" && saleAmount != null && saleAmount !== "" ? saleAmount : baseAmount;
8091
+ if (amount == null || amount === "") return null;
8092
+ const parsed = parseFloat(amount);
8093
+ if (Number.isNaN(parsed)) return null;
8094
+ return formatAmount(parsed, currency, locale);
8095
+ }
8096
+ function formatVariantPrice(variant, options = {}) {
8097
+ const { locale = DEFAULT_LOCALE, prefer = "sale-if-available", storeCurrency } = options;
8098
+ const usingDisplay = variant.displayPrice != null;
8099
+ const currency = usingDisplay ? variant.displayCurrency : storeCurrency;
8100
+ const baseAmount = usingDisplay ? variant.displayPrice : variant.price;
8101
+ const saleAmount = usingDisplay ? variant.displaySalePrice : variant.salePrice;
8102
+ const amount = prefer === "sale-if-available" && saleAmount != null && saleAmount !== "" ? saleAmount : baseAmount;
8103
+ if (amount == null || amount === "") return null;
8104
+ const parsed = parseFloat(amount);
8105
+ if (Number.isNaN(parsed)) return null;
8106
+ return formatAmount(parsed, currency, locale);
8107
+ }
8108
+ function formatMoney(amount, currency, locale = DEFAULT_LOCALE) {
8109
+ return formatAmount(amount, currency, locale);
8110
+ }
8111
+ function formatAmount(amount, currency, locale) {
8112
+ if (!currency) {
8113
+ return new Intl.NumberFormat(locale, {
8114
+ minimumFractionDigits: 2,
8115
+ maximumFractionDigits: 2
8116
+ }).format(amount);
8117
+ }
8118
+ try {
8119
+ return new Intl.NumberFormat(locale, {
8120
+ style: "currency",
8121
+ currency
8122
+ }).format(amount);
8123
+ } catch {
8124
+ return new Intl.NumberFormat(locale, {
8125
+ minimumFractionDigits: 2,
8126
+ maximumFractionDigits: 2
8127
+ }).format(amount);
8128
+ }
8129
+ }
8130
+
8041
8131
  // src/types.ts
8042
8132
  function isHtmlDescription(product) {
8043
8133
  if (product?.descriptionFormat === "html") return true;
@@ -8179,7 +8269,7 @@ function getCartTotals(cart, shippingPrice) {
8179
8269
  const subtotal = parseFloat(cart.subtotal) || 0;
8180
8270
  const discount = parseFloat(cart.discountAmount) || 0;
8181
8271
  const shipping = typeof shippingPrice === "string" ? parseFloat(shippingPrice) || 0 : shippingPrice || 0;
8182
- const total = subtotal - discount + shipping;
8272
+ const total = Math.max(0, subtotal - discount + shipping);
8183
8273
  return { subtotal, discount, shipping, total };
8184
8274
  }
8185
8275
  function getCartItemName(item) {
@@ -8287,7 +8377,10 @@ function isCouponApplicableToProduct(coupon, productId) {
8287
8377
  createWebhookHandler,
8288
8378
  deriveSeoDescription,
8289
8379
  enableDevGuards,
8380
+ formatMoney,
8290
8381
  formatPrice,
8382
+ formatProductPrice,
8383
+ formatVariantPrice,
8291
8384
  getCartItemImage,
8292
8385
  getCartItemName,
8293
8386
  getCartTotals,
package/dist/index.mjs CHANGED
@@ -6984,6 +6984,44 @@ var BrainerceClient = class {
6984
6984
  const code = country.toUpperCase();
6985
6985
  return regions.find((r) => r.countries.includes(code)) ?? regions.find((r) => r.isDefault) ?? null;
6986
6986
  }
6987
+ /**
6988
+ * Server-side region resolution in one round trip (storefront seam). Pair
6989
+ * with the country your edge runtime extracts — Cloudflare `CF-IPCountry`,
6990
+ * Vercel `request.geo?.country`, Fastly `client-geo-country`, etc.
6991
+ *
6992
+ * Brainerce does NOT derive the country from the request IP server-side
6993
+ * because the storefront server is what reaches the backend (not the end-
6994
+ * customer). The storefront must extract + forward the country.
6995
+ *
6996
+ * Returns `{ region, matched, country }` — `matched=true` means the country
6997
+ * was explicitly listed by a region; `false` means we fell back to the
6998
+ * default region (or `region=null` if no default exists either).
6999
+ */
7000
+ async getAutoRegion(country) {
7001
+ return this.storefrontRequest(
7002
+ "GET",
7003
+ "/regions/auto",
7004
+ void 0,
7005
+ country ? { country } : void 0
7006
+ );
7007
+ }
7008
+ /**
7009
+ * Non-binding tax preview for PDP / PLP / cart. Pass the buyer's country
7010
+ * (from your edge runtime — same source as `getAutoRegion`) and the current
7011
+ * items subtotal in the store currency. The authoritative tax still runs
7012
+ * at checkout — render with an "Estimate" affordance.
7013
+ *
7014
+ * Returns `appliesTax=false` when tax is disabled, the country is missing,
7015
+ * or no active rate covers it.
7016
+ */
7017
+ async estimateTax(params) {
7018
+ return this.storefrontRequest(
7019
+ "GET",
7020
+ "/tax/estimate",
7021
+ void 0,
7022
+ params.country ? { country: params.country, subtotal: params.subtotal } : { subtotal: params.subtotal }
7023
+ );
7024
+ }
6987
7025
  // -------------------- Tax Classes (Storefront mode, public — no apiKey) --------------------
6988
7026
  /**
6989
7027
  * List the store's tax classes (public, no apiKey — storeId mode). Storefront-
@@ -7971,6 +8009,55 @@ function safePaymentRedirect(url, options) {
7971
8009
  }
7972
8010
  }
7973
8011
 
8012
+ // src/format-price.ts
8013
+ var DEFAULT_LOCALE = "en";
8014
+ function formatProductPrice(product, options = {}) {
8015
+ const { locale = DEFAULT_LOCALE, prefer = "sale-if-available", storeCurrency } = options;
8016
+ const usingDisplay = product.displayPrice != null;
8017
+ const currency = usingDisplay ? product.displayCurrency : storeCurrency;
8018
+ const baseAmount = usingDisplay ? product.displayPrice : product.basePrice;
8019
+ const saleAmount = usingDisplay ? product.displaySalePrice : product.salePrice;
8020
+ const amount = prefer === "sale-if-available" && saleAmount != null && saleAmount !== "" ? saleAmount : baseAmount;
8021
+ if (amount == null || amount === "") return null;
8022
+ const parsed = parseFloat(amount);
8023
+ if (Number.isNaN(parsed)) return null;
8024
+ return formatAmount(parsed, currency, locale);
8025
+ }
8026
+ function formatVariantPrice(variant, options = {}) {
8027
+ const { locale = DEFAULT_LOCALE, prefer = "sale-if-available", storeCurrency } = options;
8028
+ const usingDisplay = variant.displayPrice != null;
8029
+ const currency = usingDisplay ? variant.displayCurrency : storeCurrency;
8030
+ const baseAmount = usingDisplay ? variant.displayPrice : variant.price;
8031
+ const saleAmount = usingDisplay ? variant.displaySalePrice : variant.salePrice;
8032
+ const amount = prefer === "sale-if-available" && saleAmount != null && saleAmount !== "" ? saleAmount : baseAmount;
8033
+ if (amount == null || amount === "") return null;
8034
+ const parsed = parseFloat(amount);
8035
+ if (Number.isNaN(parsed)) return null;
8036
+ return formatAmount(parsed, currency, locale);
8037
+ }
8038
+ function formatMoney(amount, currency, locale = DEFAULT_LOCALE) {
8039
+ return formatAmount(amount, currency, locale);
8040
+ }
8041
+ function formatAmount(amount, currency, locale) {
8042
+ if (!currency) {
8043
+ return new Intl.NumberFormat(locale, {
8044
+ minimumFractionDigits: 2,
8045
+ maximumFractionDigits: 2
8046
+ }).format(amount);
8047
+ }
8048
+ try {
8049
+ return new Intl.NumberFormat(locale, {
8050
+ style: "currency",
8051
+ currency
8052
+ }).format(amount);
8053
+ } catch {
8054
+ return new Intl.NumberFormat(locale, {
8055
+ minimumFractionDigits: 2,
8056
+ maximumFractionDigits: 2
8057
+ }).format(amount);
8058
+ }
8059
+ }
8060
+
7974
8061
  // src/types.ts
7975
8062
  function isHtmlDescription(product) {
7976
8063
  if (product?.descriptionFormat === "html") return true;
@@ -8112,7 +8199,7 @@ function getCartTotals(cart, shippingPrice) {
8112
8199
  const subtotal = parseFloat(cart.subtotal) || 0;
8113
8200
  const discount = parseFloat(cart.discountAmount) || 0;
8114
8201
  const shipping = typeof shippingPrice === "string" ? parseFloat(shippingPrice) || 0 : shippingPrice || 0;
8115
- const total = subtotal - discount + shipping;
8202
+ const total = Math.max(0, subtotal - discount + shipping);
8116
8203
  return { subtotal, discount, shipping, total };
8117
8204
  }
8118
8205
  function getCartItemName(item) {
@@ -8219,7 +8306,10 @@ export {
8219
8306
  createWebhookHandler,
8220
8307
  deriveSeoDescription,
8221
8308
  enableDevGuards,
8309
+ formatMoney,
8222
8310
  formatPrice,
8311
+ formatProductPrice,
8312
+ formatVariantPrice,
8223
8313
  getCartItemImage,
8224
8314
  getCartItemName,
8225
8315
  getCartTotals,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brainerce",
3
- "version": "1.28.0",
3
+ "version": "1.30.0",
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",
@@ -10,6 +10,11 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "require": "./dist/index.js",
12
12
  "import": "./dist/index.mjs"
13
+ },
14
+ "./bot": {
15
+ "types": "./dist/bot/index.d.ts",
16
+ "require": "./dist/bot/index.js",
17
+ "import": "./dist/bot/index.mjs"
13
18
  }
14
19
  },
15
20
  "files": [
@@ -17,7 +22,7 @@
17
22
  "README.md"
18
23
  ],
19
24
  "scripts": {
20
- "build": "tsup src/index.ts --format cjs,esm --dts",
25
+ "build": "tsup src/index.ts --format cjs,esm --dts && tsup src/bot/index.ts --format cjs,esm --dts --out-dir dist/bot && tsup src/bot/bootstrap.ts --format iife --minify --out-dir dist/bot",
21
26
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
22
27
  "lint": "eslint \"src/**/*.ts\"",
23
28
  "test": "vitest run",