brainerce 1.56.0 → 1.58.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/README.md +16 -0
- package/dist/index.d.mts +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.js +107 -6
- package/dist/index.mjs +106 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -290,6 +290,7 @@ The SDK exports these utility functions for common UI tasks:
|
|
|
290
290
|
| `buildArticleJsonLd(post, opts)` | schema.org Article JSON-LD for blog posts | See SEO section |
|
|
291
291
|
| `buildOrganizationJsonLd(store, opts)` | schema.org Organization for the homepage | See SEO section |
|
|
292
292
|
| `buildBreadcrumbJsonLd(items)` | schema.org BreadcrumbList | See SEO section |
|
|
293
|
+
| `buildProductFaqJsonLd(product)` | schema.org FAQPage from `product.faq` (null when empty) — render the same pairs as visible text | `const faq = buildProductFaqJsonLd(product)` |
|
|
293
294
|
| `jsonLdScriptProps(data)` | XSS-safe `<script type="application/ld+json">` props | `<script {...jsonLdScriptProps(data)} />` |
|
|
294
295
|
| `getBlogSitemapEntries(client, opts)` | Paginate published posts into sitemap entries | See SEO section |
|
|
295
296
|
| `getProductSitemapEntries(client, opts)` | ALL published products into sitemap entries (no 100-item clamp) | See SEO section |
|
|
@@ -495,6 +496,8 @@ import {
|
|
|
495
496
|
buildOrganizationJsonLd, // homepage
|
|
496
497
|
buildCollectionPageJsonLd, // category landing pages
|
|
497
498
|
buildBreadcrumbJsonLd,
|
|
499
|
+
buildProductFaqJsonLd, // FAQPage from product.faq (returns null when empty);
|
|
500
|
+
// ALWAYS render the same Q&A as visible text on the page
|
|
498
501
|
jsonLdScriptProps, // XSS-safe <script> props
|
|
499
502
|
} from 'brainerce';
|
|
500
503
|
|
|
@@ -2457,6 +2460,10 @@ const checkout = await client.setCheckoutCustomer(checkoutId, {
|
|
|
2457
2460
|
notes: 'Please leave the package at the door', // Optional order note (max 2000 chars)
|
|
2458
2461
|
// analyticsClientId / analyticsSessionId: auto-attached if you called
|
|
2459
2462
|
// loadGoogleAnalytics() — no need to pass these yourself.
|
|
2463
|
+
// trafficReferrerHost / trafficUtm*: auto-attached from the SDK's own
|
|
2464
|
+
// traffic-attribution capture (external referrer + utm, 30-day window) so
|
|
2465
|
+
// the dashboard can report "orders from ChatGPT / Google / …". Nothing to
|
|
2466
|
+
// wire up; pass explicitly only to override.
|
|
2460
2467
|
});
|
|
2461
2468
|
```
|
|
2462
2469
|
|
|
@@ -4094,6 +4101,15 @@ const cart = await client.createCart();
|
|
|
4094
4101
|
await client.addToCart(cart.id, { productId: 'prod_abc', quantity: 1 });
|
|
4095
4102
|
```
|
|
4096
4103
|
|
|
4104
|
+
### Traffic attribution (automatic, zero-config)
|
|
4105
|
+
|
|
4106
|
+
The SDK also records where each visit came from — the external referrer host
|
|
4107
|
+
and any `utm_source`/`utm_medium`/`utm_campaign` — as a **last non-direct
|
|
4108
|
+
touch** (`brainerce_attr` in localStorage, 30-day window). The captured values
|
|
4109
|
+
are auto-attached to `setCheckoutCustomer()` / `setShippingAddress()` and end
|
|
4110
|
+
up on the order, powering the dashboard's "orders from ChatGPT / Google / …"
|
|
4111
|
+
reporting. Nothing to configure; a value you pass explicitly always wins.
|
|
4112
|
+
|
|
4097
4113
|
What this does:
|
|
4098
4114
|
|
|
4099
4115
|
- Idempotently injects `gtag.js` and initializes `dataLayer` (skips injection if you're already loading `gtag.js` yourself — safe to call either way).
|
package/dist/index.d.mts
CHANGED
|
@@ -626,6 +626,16 @@ interface Product {
|
|
|
626
626
|
gtin?: string | null;
|
|
627
627
|
/** Manufacturer Part Number. Emitted in Product JSON-LD. */
|
|
628
628
|
mpn?: string | null;
|
|
629
|
+
/**
|
|
630
|
+
* Product Q&A pairs (AI-generated from real product data or merchant-
|
|
631
|
+
* edited). Render as a visible FAQ section on the product page and emit
|
|
632
|
+
* `buildProductFaqJsonLd(product)` — the extractable question/answer format
|
|
633
|
+
* AI answer engines cite.
|
|
634
|
+
*/
|
|
635
|
+
faq?: Array<{
|
|
636
|
+
q: string;
|
|
637
|
+
a: string;
|
|
638
|
+
}> | null;
|
|
629
639
|
/**
|
|
630
640
|
* Base price as string (e.g., "29.99"). Use parseFloat() for calculations.
|
|
631
641
|
*
|
|
@@ -3294,6 +3304,16 @@ interface SetCheckoutCustomerDto {
|
|
|
3294
3304
|
*/
|
|
3295
3305
|
analyticsClientId?: string;
|
|
3296
3306
|
analyticsSessionId?: string;
|
|
3307
|
+
/**
|
|
3308
|
+
* Traffic attribution (last non-direct touch) — auto-attached by the SDK
|
|
3309
|
+
* from its `brainerce_attr` capture (external referrer host + utm params,
|
|
3310
|
+
* 30-day window). Lets the dashboard report "orders from ChatGPT/Google/…".
|
|
3311
|
+
* Pass explicitly to override; omit to use the captured values.
|
|
3312
|
+
*/
|
|
3313
|
+
trafficReferrerHost?: string;
|
|
3314
|
+
trafficUtmSource?: string;
|
|
3315
|
+
trafficUtmMedium?: string;
|
|
3316
|
+
trafficUtmCampaign?: string;
|
|
3297
3317
|
}
|
|
3298
3318
|
/**
|
|
3299
3319
|
* Shipping address with customer email (required for checkout).
|
|
@@ -3327,6 +3347,16 @@ interface SetShippingAddressDto {
|
|
|
3327
3347
|
*/
|
|
3328
3348
|
analyticsClientId?: string;
|
|
3329
3349
|
analyticsSessionId?: string;
|
|
3350
|
+
/**
|
|
3351
|
+
* Traffic attribution (last non-direct touch) — auto-attached by the SDK
|
|
3352
|
+
* from its `brainerce_attr` capture (external referrer host + utm params,
|
|
3353
|
+
* 30-day window). Lets the dashboard report "orders from ChatGPT/Google/…".
|
|
3354
|
+
* Pass explicitly to override; omit to use the captured values.
|
|
3355
|
+
*/
|
|
3356
|
+
trafficReferrerHost?: string;
|
|
3357
|
+
trafficUtmSource?: string;
|
|
3358
|
+
trafficUtmMedium?: string;
|
|
3359
|
+
trafficUtmCampaign?: string;
|
|
3330
3360
|
/**
|
|
3331
3361
|
* The `placeId` of the autocomplete suggestion the shopper picked (from
|
|
3332
3362
|
* `addressAutocomplete()`). Send it whenever the address came from the
|
|
@@ -6847,6 +6877,26 @@ declare class BrainerceClient {
|
|
|
6847
6877
|
* No-op (returns `dto` unchanged) if `loadGoogleAnalytics()` was never
|
|
6848
6878
|
* called, or if it hasn't resolved any ids by the time this is awaited.
|
|
6849
6879
|
*/
|
|
6880
|
+
/** localStorage key holding the last non-direct-touch attribution blob. */
|
|
6881
|
+
private readonly TRAFFIC_ATTR_KEY;
|
|
6882
|
+
/** Attribution older than this is stale and never forwarded (classic 30-day window). */
|
|
6883
|
+
private static readonly TRAFFIC_ATTR_MAX_AGE_MS;
|
|
6884
|
+
/**
|
|
6885
|
+
* Record the visit's traffic origin — LAST NON-DIRECT TOUCH semantics: an
|
|
6886
|
+
* external referrer or any utm_source overwrites the stored blob; a direct
|
|
6887
|
+
* or internal navigation keeps the previous touch. Runs once per client
|
|
6888
|
+
* construction (i.e. per page load in browser storefronts) and must never
|
|
6889
|
+
* throw — attribution is telemetry, the storefront always wins.
|
|
6890
|
+
*/
|
|
6891
|
+
private captureTrafficAttribution;
|
|
6892
|
+
/** The stored attribution as request-body fields, or null when absent/stale. */
|
|
6893
|
+
private getTrafficAttribution;
|
|
6894
|
+
/**
|
|
6895
|
+
* Merge the stored traffic attribution onto a request body — only for
|
|
6896
|
+
* fields the caller didn't set explicitly (explicit values always win),
|
|
6897
|
+
* mirroring `withAnalyticsStitchIds`. No-op outside the browser.
|
|
6898
|
+
*/
|
|
6899
|
+
private withTrafficAttribution;
|
|
6850
6900
|
private withAnalyticsStitchIds;
|
|
6851
6901
|
/**
|
|
6852
6902
|
* Drop the fields `getAddressDetails()` returns that no address endpoint
|
|
@@ -11799,6 +11849,18 @@ declare function buildWebsiteJsonLd(store: StoreInfo, opts: JsonLdOptions & {
|
|
|
11799
11849
|
* {@link buildBreadcrumbJsonLd} built from `category.breadcrumb`.
|
|
11800
11850
|
*/
|
|
11801
11851
|
declare function buildCollectionPageJsonLd(category: Pick<CategoryDetail, 'name' | 'description' | 'metaDescription' | 'image'>, opts: JsonLdOptions): JsonLd;
|
|
11852
|
+
/**
|
|
11853
|
+
* schema.org/FAQPage from a product's Q&A pairs. Returns null when the
|
|
11854
|
+
* product carries no Q&A, so callers can conditionally render the script tag.
|
|
11855
|
+
* Keep the SAME pairs visible as text on the page — engines extract from
|
|
11856
|
+
* rendered HTML; the schema is corroboration, not a substitute.
|
|
11857
|
+
*/
|
|
11858
|
+
declare function buildProductFaqJsonLd(product: {
|
|
11859
|
+
faq?: Array<{
|
|
11860
|
+
q: string;
|
|
11861
|
+
a: string;
|
|
11862
|
+
}> | null;
|
|
11863
|
+
}): JsonLd | null;
|
|
11802
11864
|
/** schema.org/BreadcrumbList. Items in order from root to current page. */
|
|
11803
11865
|
declare function buildBreadcrumbJsonLd(items: Array<{
|
|
11804
11866
|
name: string;
|
|
@@ -11901,4 +11963,4 @@ interface CategorySitemapOptions {
|
|
|
11901
11963
|
*/
|
|
11902
11964
|
declare function getCategorySitemapEntries(client: BrainerceClient, opts: CategorySitemapOptions): Promise<SitemapEntry[]>;
|
|
11903
11965
|
|
|
11904
|
-
export { type AddToCartDto, type AddressDetailsResult, type AddressSuggestion, type AnnouncementContent, type AnnouncementSeverity, type AppliedDiscount, type ApplyCouponDto, type AttachModifierGroupInput, type Attribute, type AttributeOption, type AttributeSource, type BlogPost, type BlogPostListParams, type BlogPostListResponse, type BlogSitemapOptions, type BrainerceApiError, BrainerceClient, type BrainerceClientOptions, BrainerceError, type Brand, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type BusinessHoursWindow, 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 CategoryDetail, type CategoryNode, type CategorySitemapOptions, 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 DateAvailabilityConstraints, type DateFieldParseResult, 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 JsonLdOptions, type ListModifierGroupsParams, type LocalCart, type LocalCartItem, type LockedVariant, type LoyaltyNextTierSummary, type LoyaltyReward, type LoyaltyStatus, type LoyaltyTierSummary, type MergeCartsDto, type MetafieldConflict, type MetafieldConflictResolution, type MetafieldDefinition, type MetafieldFilter, type MetafieldFilterValue, type MetafieldFiltersResponse, type MetafieldType, type Modifier, type ModifierGroup, type ModifierSelection, type ModifierSelectionType, type ModifierValidationCode, type ModifierValidationError, type MyProductReview, 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 ParsedDateFieldValue, 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 ProductReview, type ProductReviewAdmin, type ProductSitemapOptions, type ProductSuggestion, type ProductVariant, type PublicMetafieldDefinition, type PublishProductResponse, RTL_LOCALES, type RecommendationVariant, type ReconcileInventoryResponse, type RedeemRewardResult, type ReferralInfo, 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 ShippingSummaryEntry, type ShippingZone, type ShippingZoneQueryParams, type SitemapEntry, type StockAvailabilityRequest, type StockAvailabilityResponse, type StockAvailabilityResult, type StoreInfo, type StoreInvitation, type StoreInvitationDetails, type StoreMember, type StorePermission, type StoreRole, type StoreTeamResponse, type StoreTracking, type SubmitProductReviewInput, 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 TrackingEventItem, type TrackingEventName, type TrackingEventPayload, 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, type WriteProductReviewInput, buildArticleJsonLd, buildBreadcrumbJsonLd, buildCollectionPageJsonLd, buildOrganizationJsonLd, buildProductJsonLd, buildWebsiteJsonLd, computeAvailableSlots, createWebhookHandler, deriveSeoDescription, enableDevGuards, formatMoney, formatPrice, formatProductPrice, formatVariantPrice, getBlogSitemapEntries, getBusinessHoursForDate, getCartItemImage, getCartItemName, getCartTotals, getCategorySitemapEntries, getDescriptionContent, getDirectionForLocale, formatPrice as getPriceDisplay, getProductCustomizationFields, getProductMetafield, getProductMetafieldValue, getProductMetafieldsByType, getProductPrice, getProductPriceInfo, getProductSitemapEntries, getProductSwatches, getStockStatus, getVariantOptions, getVariantPrice, isAllowedPaymentUrl, isCalendarDateAllowed, isCouponApplicableToProduct, isDateValueAllowed, isHtmlDescription, isWebhookEventType, jsonLdScriptProps, parseDateFieldValue, parseWebhookEvent, resolveStoreLocalParts, safePaymentRedirect, stripHtml, validateDateAvailabilityConfig, verifyWebhook };
|
|
11966
|
+
export { type AddToCartDto, type AddressDetailsResult, type AddressSuggestion, type AnnouncementContent, type AnnouncementSeverity, type AppliedDiscount, type ApplyCouponDto, type AttachModifierGroupInput, type Attribute, type AttributeOption, type AttributeSource, type BlogPost, type BlogPostListParams, type BlogPostListResponse, type BlogSitemapOptions, type BrainerceApiError, BrainerceClient, type BrainerceClientOptions, BrainerceError, type Brand, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type BusinessHoursWindow, 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 CategoryDetail, type CategoryNode, type CategorySitemapOptions, 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 DateAvailabilityConstraints, type DateFieldParseResult, 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 JsonLdOptions, type ListModifierGroupsParams, type LocalCart, type LocalCartItem, type LockedVariant, type LoyaltyNextTierSummary, type LoyaltyReward, type LoyaltyStatus, type LoyaltyTierSummary, type MergeCartsDto, type MetafieldConflict, type MetafieldConflictResolution, type MetafieldDefinition, type MetafieldFilter, type MetafieldFilterValue, type MetafieldFiltersResponse, type MetafieldType, type Modifier, type ModifierGroup, type ModifierSelection, type ModifierSelectionType, type ModifierValidationCode, type ModifierValidationError, type MyProductReview, 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 ParsedDateFieldValue, 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 ProductReview, type ProductReviewAdmin, type ProductSitemapOptions, type ProductSuggestion, type ProductVariant, type PublicMetafieldDefinition, type PublishProductResponse, RTL_LOCALES, type RecommendationVariant, type ReconcileInventoryResponse, type RedeemRewardResult, type ReferralInfo, 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 ShippingSummaryEntry, type ShippingZone, type ShippingZoneQueryParams, type SitemapEntry, type StockAvailabilityRequest, type StockAvailabilityResponse, type StockAvailabilityResult, type StoreInfo, type StoreInvitation, type StoreInvitationDetails, type StoreMember, type StorePermission, type StoreRole, type StoreTeamResponse, type StoreTracking, type SubmitProductReviewInput, 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 TrackingEventItem, type TrackingEventName, type TrackingEventPayload, 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, type WriteProductReviewInput, buildArticleJsonLd, buildBreadcrumbJsonLd, buildCollectionPageJsonLd, buildOrganizationJsonLd, buildProductFaqJsonLd, buildProductJsonLd, buildWebsiteJsonLd, computeAvailableSlots, createWebhookHandler, deriveSeoDescription, enableDevGuards, formatMoney, formatPrice, formatProductPrice, formatVariantPrice, getBlogSitemapEntries, getBusinessHoursForDate, getCartItemImage, getCartItemName, getCartTotals, getCategorySitemapEntries, getDescriptionContent, getDirectionForLocale, formatPrice as getPriceDisplay, getProductCustomizationFields, getProductMetafield, getProductMetafieldValue, getProductMetafieldsByType, getProductPrice, getProductPriceInfo, getProductSitemapEntries, getProductSwatches, getStockStatus, getVariantOptions, getVariantPrice, isAllowedPaymentUrl, isCalendarDateAllowed, isCouponApplicableToProduct, isDateValueAllowed, isHtmlDescription, isWebhookEventType, jsonLdScriptProps, parseDateFieldValue, parseWebhookEvent, resolveStoreLocalParts, safePaymentRedirect, stripHtml, validateDateAvailabilityConfig, verifyWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -626,6 +626,16 @@ interface Product {
|
|
|
626
626
|
gtin?: string | null;
|
|
627
627
|
/** Manufacturer Part Number. Emitted in Product JSON-LD. */
|
|
628
628
|
mpn?: string | null;
|
|
629
|
+
/**
|
|
630
|
+
* Product Q&A pairs (AI-generated from real product data or merchant-
|
|
631
|
+
* edited). Render as a visible FAQ section on the product page and emit
|
|
632
|
+
* `buildProductFaqJsonLd(product)` — the extractable question/answer format
|
|
633
|
+
* AI answer engines cite.
|
|
634
|
+
*/
|
|
635
|
+
faq?: Array<{
|
|
636
|
+
q: string;
|
|
637
|
+
a: string;
|
|
638
|
+
}> | null;
|
|
629
639
|
/**
|
|
630
640
|
* Base price as string (e.g., "29.99"). Use parseFloat() for calculations.
|
|
631
641
|
*
|
|
@@ -3294,6 +3304,16 @@ interface SetCheckoutCustomerDto {
|
|
|
3294
3304
|
*/
|
|
3295
3305
|
analyticsClientId?: string;
|
|
3296
3306
|
analyticsSessionId?: string;
|
|
3307
|
+
/**
|
|
3308
|
+
* Traffic attribution (last non-direct touch) — auto-attached by the SDK
|
|
3309
|
+
* from its `brainerce_attr` capture (external referrer host + utm params,
|
|
3310
|
+
* 30-day window). Lets the dashboard report "orders from ChatGPT/Google/…".
|
|
3311
|
+
* Pass explicitly to override; omit to use the captured values.
|
|
3312
|
+
*/
|
|
3313
|
+
trafficReferrerHost?: string;
|
|
3314
|
+
trafficUtmSource?: string;
|
|
3315
|
+
trafficUtmMedium?: string;
|
|
3316
|
+
trafficUtmCampaign?: string;
|
|
3297
3317
|
}
|
|
3298
3318
|
/**
|
|
3299
3319
|
* Shipping address with customer email (required for checkout).
|
|
@@ -3327,6 +3347,16 @@ interface SetShippingAddressDto {
|
|
|
3327
3347
|
*/
|
|
3328
3348
|
analyticsClientId?: string;
|
|
3329
3349
|
analyticsSessionId?: string;
|
|
3350
|
+
/**
|
|
3351
|
+
* Traffic attribution (last non-direct touch) — auto-attached by the SDK
|
|
3352
|
+
* from its `brainerce_attr` capture (external referrer host + utm params,
|
|
3353
|
+
* 30-day window). Lets the dashboard report "orders from ChatGPT/Google/…".
|
|
3354
|
+
* Pass explicitly to override; omit to use the captured values.
|
|
3355
|
+
*/
|
|
3356
|
+
trafficReferrerHost?: string;
|
|
3357
|
+
trafficUtmSource?: string;
|
|
3358
|
+
trafficUtmMedium?: string;
|
|
3359
|
+
trafficUtmCampaign?: string;
|
|
3330
3360
|
/**
|
|
3331
3361
|
* The `placeId` of the autocomplete suggestion the shopper picked (from
|
|
3332
3362
|
* `addressAutocomplete()`). Send it whenever the address came from the
|
|
@@ -6847,6 +6877,26 @@ declare class BrainerceClient {
|
|
|
6847
6877
|
* No-op (returns `dto` unchanged) if `loadGoogleAnalytics()` was never
|
|
6848
6878
|
* called, or if it hasn't resolved any ids by the time this is awaited.
|
|
6849
6879
|
*/
|
|
6880
|
+
/** localStorage key holding the last non-direct-touch attribution blob. */
|
|
6881
|
+
private readonly TRAFFIC_ATTR_KEY;
|
|
6882
|
+
/** Attribution older than this is stale and never forwarded (classic 30-day window). */
|
|
6883
|
+
private static readonly TRAFFIC_ATTR_MAX_AGE_MS;
|
|
6884
|
+
/**
|
|
6885
|
+
* Record the visit's traffic origin — LAST NON-DIRECT TOUCH semantics: an
|
|
6886
|
+
* external referrer or any utm_source overwrites the stored blob; a direct
|
|
6887
|
+
* or internal navigation keeps the previous touch. Runs once per client
|
|
6888
|
+
* construction (i.e. per page load in browser storefronts) and must never
|
|
6889
|
+
* throw — attribution is telemetry, the storefront always wins.
|
|
6890
|
+
*/
|
|
6891
|
+
private captureTrafficAttribution;
|
|
6892
|
+
/** The stored attribution as request-body fields, or null when absent/stale. */
|
|
6893
|
+
private getTrafficAttribution;
|
|
6894
|
+
/**
|
|
6895
|
+
* Merge the stored traffic attribution onto a request body — only for
|
|
6896
|
+
* fields the caller didn't set explicitly (explicit values always win),
|
|
6897
|
+
* mirroring `withAnalyticsStitchIds`. No-op outside the browser.
|
|
6898
|
+
*/
|
|
6899
|
+
private withTrafficAttribution;
|
|
6850
6900
|
private withAnalyticsStitchIds;
|
|
6851
6901
|
/**
|
|
6852
6902
|
* Drop the fields `getAddressDetails()` returns that no address endpoint
|
|
@@ -11799,6 +11849,18 @@ declare function buildWebsiteJsonLd(store: StoreInfo, opts: JsonLdOptions & {
|
|
|
11799
11849
|
* {@link buildBreadcrumbJsonLd} built from `category.breadcrumb`.
|
|
11800
11850
|
*/
|
|
11801
11851
|
declare function buildCollectionPageJsonLd(category: Pick<CategoryDetail, 'name' | 'description' | 'metaDescription' | 'image'>, opts: JsonLdOptions): JsonLd;
|
|
11852
|
+
/**
|
|
11853
|
+
* schema.org/FAQPage from a product's Q&A pairs. Returns null when the
|
|
11854
|
+
* product carries no Q&A, so callers can conditionally render the script tag.
|
|
11855
|
+
* Keep the SAME pairs visible as text on the page — engines extract from
|
|
11856
|
+
* rendered HTML; the schema is corroboration, not a substitute.
|
|
11857
|
+
*/
|
|
11858
|
+
declare function buildProductFaqJsonLd(product: {
|
|
11859
|
+
faq?: Array<{
|
|
11860
|
+
q: string;
|
|
11861
|
+
a: string;
|
|
11862
|
+
}> | null;
|
|
11863
|
+
}): JsonLd | null;
|
|
11802
11864
|
/** schema.org/BreadcrumbList. Items in order from root to current page. */
|
|
11803
11865
|
declare function buildBreadcrumbJsonLd(items: Array<{
|
|
11804
11866
|
name: string;
|
|
@@ -11901,4 +11963,4 @@ interface CategorySitemapOptions {
|
|
|
11901
11963
|
*/
|
|
11902
11964
|
declare function getCategorySitemapEntries(client: BrainerceClient, opts: CategorySitemapOptions): Promise<SitemapEntry[]>;
|
|
11903
11965
|
|
|
11904
|
-
export { type AddToCartDto, type AddressDetailsResult, type AddressSuggestion, type AnnouncementContent, type AnnouncementSeverity, type AppliedDiscount, type ApplyCouponDto, type AttachModifierGroupInput, type Attribute, type AttributeOption, type AttributeSource, type BlogPost, type BlogPostListParams, type BlogPostListResponse, type BlogSitemapOptions, type BrainerceApiError, BrainerceClient, type BrainerceClientOptions, BrainerceError, type Brand, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type BusinessHoursWindow, 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 CategoryDetail, type CategoryNode, type CategorySitemapOptions, 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 DateAvailabilityConstraints, type DateFieldParseResult, 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 JsonLdOptions, type ListModifierGroupsParams, type LocalCart, type LocalCartItem, type LockedVariant, type LoyaltyNextTierSummary, type LoyaltyReward, type LoyaltyStatus, type LoyaltyTierSummary, type MergeCartsDto, type MetafieldConflict, type MetafieldConflictResolution, type MetafieldDefinition, type MetafieldFilter, type MetafieldFilterValue, type MetafieldFiltersResponse, type MetafieldType, type Modifier, type ModifierGroup, type ModifierSelection, type ModifierSelectionType, type ModifierValidationCode, type ModifierValidationError, type MyProductReview, 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 ParsedDateFieldValue, 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 ProductReview, type ProductReviewAdmin, type ProductSitemapOptions, type ProductSuggestion, type ProductVariant, type PublicMetafieldDefinition, type PublishProductResponse, RTL_LOCALES, type RecommendationVariant, type ReconcileInventoryResponse, type RedeemRewardResult, type ReferralInfo, 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 ShippingSummaryEntry, type ShippingZone, type ShippingZoneQueryParams, type SitemapEntry, type StockAvailabilityRequest, type StockAvailabilityResponse, type StockAvailabilityResult, type StoreInfo, type StoreInvitation, type StoreInvitationDetails, type StoreMember, type StorePermission, type StoreRole, type StoreTeamResponse, type StoreTracking, type SubmitProductReviewInput, 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 TrackingEventItem, type TrackingEventName, type TrackingEventPayload, 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, type WriteProductReviewInput, buildArticleJsonLd, buildBreadcrumbJsonLd, buildCollectionPageJsonLd, buildOrganizationJsonLd, buildProductJsonLd, buildWebsiteJsonLd, computeAvailableSlots, createWebhookHandler, deriveSeoDescription, enableDevGuards, formatMoney, formatPrice, formatProductPrice, formatVariantPrice, getBlogSitemapEntries, getBusinessHoursForDate, getCartItemImage, getCartItemName, getCartTotals, getCategorySitemapEntries, getDescriptionContent, getDirectionForLocale, formatPrice as getPriceDisplay, getProductCustomizationFields, getProductMetafield, getProductMetafieldValue, getProductMetafieldsByType, getProductPrice, getProductPriceInfo, getProductSitemapEntries, getProductSwatches, getStockStatus, getVariantOptions, getVariantPrice, isAllowedPaymentUrl, isCalendarDateAllowed, isCouponApplicableToProduct, isDateValueAllowed, isHtmlDescription, isWebhookEventType, jsonLdScriptProps, parseDateFieldValue, parseWebhookEvent, resolveStoreLocalParts, safePaymentRedirect, stripHtml, validateDateAvailabilityConfig, verifyWebhook };
|
|
11966
|
+
export { type AddToCartDto, type AddressDetailsResult, type AddressSuggestion, type AnnouncementContent, type AnnouncementSeverity, type AppliedDiscount, type ApplyCouponDto, type AttachModifierGroupInput, type Attribute, type AttributeOption, type AttributeSource, type BlogPost, type BlogPostListParams, type BlogPostListResponse, type BlogSitemapOptions, type BrainerceApiError, BrainerceClient, type BrainerceClientOptions, BrainerceError, type Brand, type BulkInventoryResponse, type BulkSaveVariantsDto, type BulkSaveVariantsResponse, type BulkVariantInput, type BusinessHoursWindow, 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 CategoryDetail, type CategoryNode, type CategorySitemapOptions, 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 DateAvailabilityConstraints, type DateFieldParseResult, 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 JsonLdOptions, type ListModifierGroupsParams, type LocalCart, type LocalCartItem, type LockedVariant, type LoyaltyNextTierSummary, type LoyaltyReward, type LoyaltyStatus, type LoyaltyTierSummary, type MergeCartsDto, type MetafieldConflict, type MetafieldConflictResolution, type MetafieldDefinition, type MetafieldFilter, type MetafieldFilterValue, type MetafieldFiltersResponse, type MetafieldType, type Modifier, type ModifierGroup, type ModifierSelection, type ModifierSelectionType, type ModifierValidationCode, type ModifierValidationError, type MyProductReview, 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 ParsedDateFieldValue, 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 ProductReview, type ProductReviewAdmin, type ProductSitemapOptions, type ProductSuggestion, type ProductVariant, type PublicMetafieldDefinition, type PublishProductResponse, RTL_LOCALES, type RecommendationVariant, type ReconcileInventoryResponse, type RedeemRewardResult, type ReferralInfo, 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 ShippingSummaryEntry, type ShippingZone, type ShippingZoneQueryParams, type SitemapEntry, type StockAvailabilityRequest, type StockAvailabilityResponse, type StockAvailabilityResult, type StoreInfo, type StoreInvitation, type StoreInvitationDetails, type StoreMember, type StorePermission, type StoreRole, type StoreTeamResponse, type StoreTracking, type SubmitProductReviewInput, 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 TrackingEventItem, type TrackingEventName, type TrackingEventPayload, 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, type WriteProductReviewInput, buildArticleJsonLd, buildBreadcrumbJsonLd, buildCollectionPageJsonLd, buildOrganizationJsonLd, buildProductFaqJsonLd, buildProductJsonLd, buildWebsiteJsonLd, computeAvailableSlots, createWebhookHandler, deriveSeoDescription, enableDevGuards, formatMoney, formatPrice, formatProductPrice, formatVariantPrice, getBlogSitemapEntries, getBusinessHoursForDate, getCartItemImage, getCartItemName, getCartTotals, getCategorySitemapEntries, getDescriptionContent, getDirectionForLocale, formatPrice as getPriceDisplay, getProductCustomizationFields, getProductMetafield, getProductMetafieldValue, getProductMetafieldsByType, getProductPrice, getProductPriceInfo, getProductSitemapEntries, getProductSwatches, getStockStatus, getVariantOptions, getVariantPrice, isAllowedPaymentUrl, isCalendarDateAllowed, isCouponApplicableToProduct, isDateValueAllowed, isHtmlDescription, isWebhookEventType, jsonLdScriptProps, parseDateFieldValue, parseWebhookEvent, resolveStoreLocalParts, safePaymentRedirect, stripHtml, validateDateAvailabilityConfig, verifyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
buildBreadcrumbJsonLd: () => buildBreadcrumbJsonLd,
|
|
39
39
|
buildCollectionPageJsonLd: () => buildCollectionPageJsonLd,
|
|
40
40
|
buildOrganizationJsonLd: () => buildOrganizationJsonLd,
|
|
41
|
+
buildProductFaqJsonLd: () => buildProductFaqJsonLd,
|
|
41
42
|
buildProductJsonLd: () => buildProductJsonLd,
|
|
42
43
|
buildWebsiteJsonLd: () => buildWebsiteJsonLd,
|
|
43
44
|
computeAvailableSlots: () => computeAvailableSlots,
|
|
@@ -299,6 +300,14 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
299
300
|
* This is needed because Stripe redirects lose in-memory state.
|
|
300
301
|
*/
|
|
301
302
|
this.ACTIVE_CHECKOUT_KEY = "brainerce_active_checkout";
|
|
303
|
+
/**
|
|
304
|
+
* Merge the resolved GA4 stitch ids onto a request body — only for fields
|
|
305
|
+
* the caller didn't already set explicitly (explicit values always win).
|
|
306
|
+
* No-op (returns `dto` unchanged) if `loadGoogleAnalytics()` was never
|
|
307
|
+
* called, or if it hasn't resolved any ids by the time this is awaited.
|
|
308
|
+
*/
|
|
309
|
+
/** localStorage key holding the last non-direct-touch attribution blob. */
|
|
310
|
+
this.TRAFFIC_ATTR_KEY = "brainerce_attr";
|
|
302
311
|
// -------------------- Contact Forms (schema) --------------------
|
|
303
312
|
/**
|
|
304
313
|
* List active contact forms configured for the store.
|
|
@@ -704,6 +713,7 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
704
713
|
this.onCartReset = options.onCartReset;
|
|
705
714
|
this.hydrateSessionCart();
|
|
706
715
|
this.detectRecoverCartFromUrl();
|
|
716
|
+
this.captureTrafficAttribution();
|
|
707
717
|
}
|
|
708
718
|
// -------------------- Locale --------------------
|
|
709
719
|
/**
|
|
@@ -1526,11 +1536,82 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
1526
1536
|
}
|
|
1527
1537
|
}
|
|
1528
1538
|
/**
|
|
1529
|
-
*
|
|
1530
|
-
*
|
|
1531
|
-
*
|
|
1532
|
-
*
|
|
1539
|
+
* Record the visit's traffic origin — LAST NON-DIRECT TOUCH semantics: an
|
|
1540
|
+
* external referrer or any utm_source overwrites the stored blob; a direct
|
|
1541
|
+
* or internal navigation keeps the previous touch. Runs once per client
|
|
1542
|
+
* construction (i.e. per page load in browser storefronts) and must never
|
|
1543
|
+
* throw — attribution is telemetry, the storefront always wins.
|
|
1544
|
+
*/
|
|
1545
|
+
captureTrafficAttribution() {
|
|
1546
|
+
try {
|
|
1547
|
+
if (typeof window === "undefined" || !window.localStorage) return;
|
|
1548
|
+
const params = new URLSearchParams(window.location.search);
|
|
1549
|
+
const utmSource = params.get("utm_source") || void 0;
|
|
1550
|
+
const utmMedium = params.get("utm_medium") || void 0;
|
|
1551
|
+
const utmCampaign = params.get("utm_campaign") || void 0;
|
|
1552
|
+
let referrerHost;
|
|
1553
|
+
if (document.referrer) {
|
|
1554
|
+
try {
|
|
1555
|
+
const ref = new URL(document.referrer);
|
|
1556
|
+
if (ref.hostname && ref.hostname !== window.location.hostname) {
|
|
1557
|
+
referrerHost = ref.hostname.toLowerCase().replace(/^www\./, "");
|
|
1558
|
+
}
|
|
1559
|
+
} catch {
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
if (!referrerHost && !utmSource) return;
|
|
1563
|
+
window.localStorage.setItem(
|
|
1564
|
+
this.TRAFFIC_ATTR_KEY,
|
|
1565
|
+
JSON.stringify({ referrerHost, utmSource, utmMedium, utmCampaign, at: Date.now() })
|
|
1566
|
+
);
|
|
1567
|
+
} catch {
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
/** The stored attribution as request-body fields, or null when absent/stale. */
|
|
1571
|
+
getTrafficAttribution() {
|
|
1572
|
+
try {
|
|
1573
|
+
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
1574
|
+
const raw = window.localStorage.getItem(this.TRAFFIC_ATTR_KEY);
|
|
1575
|
+
if (!raw) return null;
|
|
1576
|
+
const blob = JSON.parse(raw);
|
|
1577
|
+
if (!blob || typeof blob !== "object") return null;
|
|
1578
|
+
if (typeof blob.at !== "number" || Date.now() - blob.at > _BrainerceClient.TRAFFIC_ATTR_MAX_AGE_MS) {
|
|
1579
|
+
return null;
|
|
1580
|
+
}
|
|
1581
|
+
const out = {};
|
|
1582
|
+
if (typeof blob.referrerHost === "string" && blob.referrerHost) {
|
|
1583
|
+
out.trafficReferrerHost = blob.referrerHost.slice(0, 253);
|
|
1584
|
+
}
|
|
1585
|
+
if (typeof blob.utmSource === "string" && blob.utmSource) {
|
|
1586
|
+
out.trafficUtmSource = blob.utmSource.slice(0, 150);
|
|
1587
|
+
}
|
|
1588
|
+
if (typeof blob.utmMedium === "string" && blob.utmMedium) {
|
|
1589
|
+
out.trafficUtmMedium = blob.utmMedium.slice(0, 150);
|
|
1590
|
+
}
|
|
1591
|
+
if (typeof blob.utmCampaign === "string" && blob.utmCampaign) {
|
|
1592
|
+
out.trafficUtmCampaign = blob.utmCampaign.slice(0, 150);
|
|
1593
|
+
}
|
|
1594
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
1595
|
+
} catch {
|
|
1596
|
+
return null;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
/**
|
|
1600
|
+
* Merge the stored traffic attribution onto a request body — only for
|
|
1601
|
+
* fields the caller didn't set explicitly (explicit values always win),
|
|
1602
|
+
* mirroring `withAnalyticsStitchIds`. No-op outside the browser.
|
|
1533
1603
|
*/
|
|
1604
|
+
withTrafficAttribution(dto) {
|
|
1605
|
+
const attr = this.getTrafficAttribution();
|
|
1606
|
+
if (!attr) return dto;
|
|
1607
|
+
return {
|
|
1608
|
+
...dto ?? {},
|
|
1609
|
+
trafficReferrerHost: dto?.trafficReferrerHost ?? attr.trafficReferrerHost,
|
|
1610
|
+
trafficUtmSource: dto?.trafficUtmSource ?? attr.trafficUtmSource,
|
|
1611
|
+
trafficUtmMedium: dto?.trafficUtmMedium ?? attr.trafficUtmMedium,
|
|
1612
|
+
trafficUtmCampaign: dto?.trafficUtmCampaign ?? attr.trafficUtmCampaign
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1534
1615
|
async withAnalyticsStitchIds(dto) {
|
|
1535
1616
|
if (!this._ga4StitchPromise) return dto;
|
|
1536
1617
|
try {
|
|
@@ -5387,7 +5468,7 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
5387
5468
|
* ```
|
|
5388
5469
|
*/
|
|
5389
5470
|
async setCheckoutCustomer(checkoutId, data) {
|
|
5390
|
-
const body = await this.withAnalyticsStitchIds(data);
|
|
5471
|
+
const body = this.withTrafficAttribution(await this.withAnalyticsStitchIds(data));
|
|
5391
5472
|
if (this.isVibeCodedMode()) {
|
|
5392
5473
|
return this.vibeCodedRequest(
|
|
5393
5474
|
"PATCH",
|
|
@@ -5489,7 +5570,9 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
5489
5570
|
* ```
|
|
5490
5571
|
*/
|
|
5491
5572
|
async setShippingAddress(checkoutId, address) {
|
|
5492
|
-
const body =
|
|
5573
|
+
const body = this.withTrafficAttribution(
|
|
5574
|
+
await this.withAnalyticsStitchIds(this.stripResolvedOnlyAddressFields(address))
|
|
5575
|
+
);
|
|
5493
5576
|
if (this.isVibeCodedMode()) {
|
|
5494
5577
|
return this.vibeCodedRequest(
|
|
5495
5578
|
"PATCH",
|
|
@@ -9716,6 +9799,8 @@ _BrainerceClient.RESOLVED_ONLY_ADDRESS_FIELDS = [
|
|
|
9716
9799
|
"lng",
|
|
9717
9800
|
"formattedAddress"
|
|
9718
9801
|
];
|
|
9802
|
+
/** Attribution older than this is stale and never forwarded (classic 30-day window). */
|
|
9803
|
+
_BrainerceClient.TRAFFIC_ATTR_MAX_AGE_MS = 30 * 24 * 3600 * 1e3;
|
|
9719
9804
|
var BrainerceClient = _BrainerceClient;
|
|
9720
9805
|
var BrainerceError = class extends Error {
|
|
9721
9806
|
constructor(message, statusCode, details) {
|
|
@@ -10340,6 +10425,21 @@ function buildCollectionPageJsonLd(category, opts) {
|
|
|
10340
10425
|
...category.image ? { image: [category.image] } : {}
|
|
10341
10426
|
};
|
|
10342
10427
|
}
|
|
10428
|
+
function buildProductFaqJsonLd(product) {
|
|
10429
|
+
const pairs = (product.faq ?? []).filter(
|
|
10430
|
+
(i) => typeof i?.q === "string" && typeof i?.a === "string" && i.q && i.a
|
|
10431
|
+
);
|
|
10432
|
+
if (pairs.length === 0) return null;
|
|
10433
|
+
return {
|
|
10434
|
+
"@context": "https://schema.org",
|
|
10435
|
+
"@type": "FAQPage",
|
|
10436
|
+
mainEntity: pairs.map((i) => ({
|
|
10437
|
+
"@type": "Question",
|
|
10438
|
+
name: i.q,
|
|
10439
|
+
acceptedAnswer: { "@type": "Answer", text: i.a }
|
|
10440
|
+
}))
|
|
10441
|
+
};
|
|
10442
|
+
}
|
|
10343
10443
|
function buildBreadcrumbJsonLd(items) {
|
|
10344
10444
|
return {
|
|
10345
10445
|
"@context": "https://schema.org",
|
|
@@ -10730,6 +10830,7 @@ function isCouponApplicableToProduct(coupon, productId) {
|
|
|
10730
10830
|
buildBreadcrumbJsonLd,
|
|
10731
10831
|
buildCollectionPageJsonLd,
|
|
10732
10832
|
buildOrganizationJsonLd,
|
|
10833
|
+
buildProductFaqJsonLd,
|
|
10733
10834
|
buildProductJsonLd,
|
|
10734
10835
|
buildWebsiteJsonLd,
|
|
10735
10836
|
computeAvailableSlots,
|
package/dist/index.mjs
CHANGED
|
@@ -212,6 +212,14 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
212
212
|
* This is needed because Stripe redirects lose in-memory state.
|
|
213
213
|
*/
|
|
214
214
|
this.ACTIVE_CHECKOUT_KEY = "brainerce_active_checkout";
|
|
215
|
+
/**
|
|
216
|
+
* Merge the resolved GA4 stitch ids onto a request body — only for fields
|
|
217
|
+
* the caller didn't already set explicitly (explicit values always win).
|
|
218
|
+
* No-op (returns `dto` unchanged) if `loadGoogleAnalytics()` was never
|
|
219
|
+
* called, or if it hasn't resolved any ids by the time this is awaited.
|
|
220
|
+
*/
|
|
221
|
+
/** localStorage key holding the last non-direct-touch attribution blob. */
|
|
222
|
+
this.TRAFFIC_ATTR_KEY = "brainerce_attr";
|
|
215
223
|
// -------------------- Contact Forms (schema) --------------------
|
|
216
224
|
/**
|
|
217
225
|
* List active contact forms configured for the store.
|
|
@@ -617,6 +625,7 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
617
625
|
this.onCartReset = options.onCartReset;
|
|
618
626
|
this.hydrateSessionCart();
|
|
619
627
|
this.detectRecoverCartFromUrl();
|
|
628
|
+
this.captureTrafficAttribution();
|
|
620
629
|
}
|
|
621
630
|
// -------------------- Locale --------------------
|
|
622
631
|
/**
|
|
@@ -1439,11 +1448,82 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
1439
1448
|
}
|
|
1440
1449
|
}
|
|
1441
1450
|
/**
|
|
1442
|
-
*
|
|
1443
|
-
*
|
|
1444
|
-
*
|
|
1445
|
-
*
|
|
1451
|
+
* Record the visit's traffic origin — LAST NON-DIRECT TOUCH semantics: an
|
|
1452
|
+
* external referrer or any utm_source overwrites the stored blob; a direct
|
|
1453
|
+
* or internal navigation keeps the previous touch. Runs once per client
|
|
1454
|
+
* construction (i.e. per page load in browser storefronts) and must never
|
|
1455
|
+
* throw — attribution is telemetry, the storefront always wins.
|
|
1456
|
+
*/
|
|
1457
|
+
captureTrafficAttribution() {
|
|
1458
|
+
try {
|
|
1459
|
+
if (typeof window === "undefined" || !window.localStorage) return;
|
|
1460
|
+
const params = new URLSearchParams(window.location.search);
|
|
1461
|
+
const utmSource = params.get("utm_source") || void 0;
|
|
1462
|
+
const utmMedium = params.get("utm_medium") || void 0;
|
|
1463
|
+
const utmCampaign = params.get("utm_campaign") || void 0;
|
|
1464
|
+
let referrerHost;
|
|
1465
|
+
if (document.referrer) {
|
|
1466
|
+
try {
|
|
1467
|
+
const ref = new URL(document.referrer);
|
|
1468
|
+
if (ref.hostname && ref.hostname !== window.location.hostname) {
|
|
1469
|
+
referrerHost = ref.hostname.toLowerCase().replace(/^www\./, "");
|
|
1470
|
+
}
|
|
1471
|
+
} catch {
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
if (!referrerHost && !utmSource) return;
|
|
1475
|
+
window.localStorage.setItem(
|
|
1476
|
+
this.TRAFFIC_ATTR_KEY,
|
|
1477
|
+
JSON.stringify({ referrerHost, utmSource, utmMedium, utmCampaign, at: Date.now() })
|
|
1478
|
+
);
|
|
1479
|
+
} catch {
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
/** The stored attribution as request-body fields, or null when absent/stale. */
|
|
1483
|
+
getTrafficAttribution() {
|
|
1484
|
+
try {
|
|
1485
|
+
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
1486
|
+
const raw = window.localStorage.getItem(this.TRAFFIC_ATTR_KEY);
|
|
1487
|
+
if (!raw) return null;
|
|
1488
|
+
const blob = JSON.parse(raw);
|
|
1489
|
+
if (!blob || typeof blob !== "object") return null;
|
|
1490
|
+
if (typeof blob.at !== "number" || Date.now() - blob.at > _BrainerceClient.TRAFFIC_ATTR_MAX_AGE_MS) {
|
|
1491
|
+
return null;
|
|
1492
|
+
}
|
|
1493
|
+
const out = {};
|
|
1494
|
+
if (typeof blob.referrerHost === "string" && blob.referrerHost) {
|
|
1495
|
+
out.trafficReferrerHost = blob.referrerHost.slice(0, 253);
|
|
1496
|
+
}
|
|
1497
|
+
if (typeof blob.utmSource === "string" && blob.utmSource) {
|
|
1498
|
+
out.trafficUtmSource = blob.utmSource.slice(0, 150);
|
|
1499
|
+
}
|
|
1500
|
+
if (typeof blob.utmMedium === "string" && blob.utmMedium) {
|
|
1501
|
+
out.trafficUtmMedium = blob.utmMedium.slice(0, 150);
|
|
1502
|
+
}
|
|
1503
|
+
if (typeof blob.utmCampaign === "string" && blob.utmCampaign) {
|
|
1504
|
+
out.trafficUtmCampaign = blob.utmCampaign.slice(0, 150);
|
|
1505
|
+
}
|
|
1506
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
1507
|
+
} catch {
|
|
1508
|
+
return null;
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* Merge the stored traffic attribution onto a request body — only for
|
|
1513
|
+
* fields the caller didn't set explicitly (explicit values always win),
|
|
1514
|
+
* mirroring `withAnalyticsStitchIds`. No-op outside the browser.
|
|
1446
1515
|
*/
|
|
1516
|
+
withTrafficAttribution(dto) {
|
|
1517
|
+
const attr = this.getTrafficAttribution();
|
|
1518
|
+
if (!attr) return dto;
|
|
1519
|
+
return {
|
|
1520
|
+
...dto ?? {},
|
|
1521
|
+
trafficReferrerHost: dto?.trafficReferrerHost ?? attr.trafficReferrerHost,
|
|
1522
|
+
trafficUtmSource: dto?.trafficUtmSource ?? attr.trafficUtmSource,
|
|
1523
|
+
trafficUtmMedium: dto?.trafficUtmMedium ?? attr.trafficUtmMedium,
|
|
1524
|
+
trafficUtmCampaign: dto?.trafficUtmCampaign ?? attr.trafficUtmCampaign
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1447
1527
|
async withAnalyticsStitchIds(dto) {
|
|
1448
1528
|
if (!this._ga4StitchPromise) return dto;
|
|
1449
1529
|
try {
|
|
@@ -5300,7 +5380,7 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
5300
5380
|
* ```
|
|
5301
5381
|
*/
|
|
5302
5382
|
async setCheckoutCustomer(checkoutId, data) {
|
|
5303
|
-
const body = await this.withAnalyticsStitchIds(data);
|
|
5383
|
+
const body = this.withTrafficAttribution(await this.withAnalyticsStitchIds(data));
|
|
5304
5384
|
if (this.isVibeCodedMode()) {
|
|
5305
5385
|
return this.vibeCodedRequest(
|
|
5306
5386
|
"PATCH",
|
|
@@ -5402,7 +5482,9 @@ var _BrainerceClient = class _BrainerceClient {
|
|
|
5402
5482
|
* ```
|
|
5403
5483
|
*/
|
|
5404
5484
|
async setShippingAddress(checkoutId, address) {
|
|
5405
|
-
const body =
|
|
5485
|
+
const body = this.withTrafficAttribution(
|
|
5486
|
+
await this.withAnalyticsStitchIds(this.stripResolvedOnlyAddressFields(address))
|
|
5487
|
+
);
|
|
5406
5488
|
if (this.isVibeCodedMode()) {
|
|
5407
5489
|
return this.vibeCodedRequest(
|
|
5408
5490
|
"PATCH",
|
|
@@ -9629,6 +9711,8 @@ _BrainerceClient.RESOLVED_ONLY_ADDRESS_FIELDS = [
|
|
|
9629
9711
|
"lng",
|
|
9630
9712
|
"formattedAddress"
|
|
9631
9713
|
];
|
|
9714
|
+
/** Attribution older than this is stale and never forwarded (classic 30-day window). */
|
|
9715
|
+
_BrainerceClient.TRAFFIC_ATTR_MAX_AGE_MS = 30 * 24 * 3600 * 1e3;
|
|
9632
9716
|
var BrainerceClient = _BrainerceClient;
|
|
9633
9717
|
var BrainerceError = class extends Error {
|
|
9634
9718
|
constructor(message, statusCode, details) {
|
|
@@ -10253,6 +10337,21 @@ function buildCollectionPageJsonLd(category, opts) {
|
|
|
10253
10337
|
...category.image ? { image: [category.image] } : {}
|
|
10254
10338
|
};
|
|
10255
10339
|
}
|
|
10340
|
+
function buildProductFaqJsonLd(product) {
|
|
10341
|
+
const pairs = (product.faq ?? []).filter(
|
|
10342
|
+
(i) => typeof i?.q === "string" && typeof i?.a === "string" && i.q && i.a
|
|
10343
|
+
);
|
|
10344
|
+
if (pairs.length === 0) return null;
|
|
10345
|
+
return {
|
|
10346
|
+
"@context": "https://schema.org",
|
|
10347
|
+
"@type": "FAQPage",
|
|
10348
|
+
mainEntity: pairs.map((i) => ({
|
|
10349
|
+
"@type": "Question",
|
|
10350
|
+
name: i.q,
|
|
10351
|
+
acceptedAnswer: { "@type": "Answer", text: i.a }
|
|
10352
|
+
}))
|
|
10353
|
+
};
|
|
10354
|
+
}
|
|
10256
10355
|
function buildBreadcrumbJsonLd(items) {
|
|
10257
10356
|
return {
|
|
10258
10357
|
"@context": "https://schema.org",
|
|
@@ -10642,6 +10741,7 @@ export {
|
|
|
10642
10741
|
buildBreadcrumbJsonLd,
|
|
10643
10742
|
buildCollectionPageJsonLd,
|
|
10644
10743
|
buildOrganizationJsonLd,
|
|
10744
|
+
buildProductFaqJsonLd,
|
|
10645
10745
|
buildProductJsonLd,
|
|
10646
10746
|
buildWebsiteJsonLd,
|
|
10647
10747
|
computeAvailableSlots,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brainerce",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.58.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",
|