import { OnsiteCoreWindow, EventData, Events } from "@mailbiz/onsite-core"; import { ProductPropertiesEvent } from "@mailbiz/tracker-core"; //#region [Window] interface VtexLocalStorage { orderform?: string; // VtexIOOrderFrom JSON string } interface VtexLegacyContext { catalog: any; checkout: { orderForm: VtexLegacyOrderForm; orderFormId?: string; }; } type RadioPubSubMethod = (callback: Function) => void; interface RadioPubSubInstance { subscribe: RadioPubSubMethod; unsubscribe: RadioPubSubMethod; broadcast: (data?: any) => void; } interface RadioPubSub { (eventName: string): RadioPubSubInstance; } interface VtexWindow extends OnsiteCoreWindow { radio?: RadioPubSub; vtexjs?: VtexLegacyContext; localStorage?: VtexLocalStorage; CATALOG_SDK?: VtexLegacyCatalog; dataLayer?: DataLayerEvent[]; ko: KnockoutStatic; } //#endregion //#region [KO] interface KnockoutStatic { contextFor: (element: HTMLElement) => ClientProfileDataContext | undefined; } interface KnockoutObservable { subscribe: (callback: (newValue: T) => void) => { dispose: () => void; }; } interface ClientProfileDataContext { $root: ClientProfileDataContextRoot; } interface ClientProfileDataContextRoot { toJSON: () => ClientProfileData; email: KnockoutObservable; firstEmail: KnockoutObservable; firstName: KnockoutObservable; lastName: KnockoutObservable; corporateName: KnockoutObservable; phone: KnockoutObservable; } interface ClientProfileData { email?: string; firstEmail?: string; firstName?: string; lastName?: string; corporateName?: string; phone?: string; } //#endregion //#region [Data Layer] interface DataLayerProduct { brand: string; category: string; dimension1: string; dimension2: string; dimension3: string; dimension4: string; id: string; name: string; price: number; variant: string; } interface DataLayerEvent { event?: string; ecommerce?: { detail?: { products?: DataLayerProduct[]; }; }; } //#endregion //#region [Vtex Order Form] interface ProductCategories { [categoryId: string]: string; } type PriceTags = PriceTag[]; interface PriceTag { name: string; value: number; rawValue: number; isPercentual: boolean; identifier: string; owner?: string; __typename?: string; ratesAndBenefitsIdentifier?: any; } interface PriceDefinition { calculatedSellingPrice: number; total: number; sellingPrices: SellingPrice[]; reason?: any; __typename?: string; } interface SellingPrice { value: number; quantity: number; __typename?: string; } interface VtexTotalizer { id: string; name: string; value: number; __typename?: string; } interface VtexLegacyShippingData { address: any; logisticsInfo: LogisticsInfo[]; selectedAddresses: VtexAddress[]; availableAddresses: VtexAddress[]; pickupPoints: any[]; trackingHints?: any[]; isFOB?: boolean | null; } interface LogisticsInfo { itemIndex: number; selectedSla: string | null; selectedDeliveryChannel: string | null; addressId: string | null; slas: any[]; shipsTo: string[]; itemId: string; deliveryChannels: DeliveryChannel[]; price?: number; sellingPrice?: number; listPrice?: number; shippingEstimate?: string; dockEstimate?: string; shippingEstimateDate?: string; lockTTL?: string; deliveryCompany?: string | null; polygonName?: string; transitTime?: string; deliveryIds?: any[]; deliveryWindow?: string | null; pickupPointId?: string | null; pickupStoreInfo?: { isPickupStore: boolean; friendlyName: string | null; address: string | null; additionalInfo: string | null; dockId: string | null; }; pickupDistance?: string | null; } interface DeliveryChannel { id: string; } interface PaymentData { updateStatus?: string; installmentOptions: InstallmentOption[]; paymentSystems: PaymentSystem[]; payments: Payment[]; giftCards?: any[]; giftCardMessages?: any[]; availableAccounts: any[]; availableTokens?: any[]; availableAssociations?: any; isValid?: boolean; __typename?: string; } interface InstallmentOption { paymentSystem: string; bin?: any; paymentName?: any; paymentGroupName?: any; value?: number; installments: Installment[]; __typename?: string; } interface Installment { count: number; hasInterestRate: boolean; interestRate: number; value: number; total: number; sellerMerchantInstallments?: SellerMerchantInstallment[]; __typename?: string; } interface SellerMerchantInstallment { id: string; count: number; hasInterestRate: boolean; interestRate: number; value: number; total: number; } interface PaymentSystem { id: number | string; name: string; groupName: string; validator: Validator; stringId: string; template?: string; requiresDocument: boolean; displayDocument?: boolean; isCustom: boolean; description: any; requiresAuthentication: boolean; dueDate: string; availablePayments?: any[] | null; __typename?: string; } interface Validator { regex: any; mask: any; cardCodeRegex: any; cardCodeMask: any; weights: any; useCvv: boolean; useExpirationDate: boolean; useCardHolderName: boolean; useBillingAddress: boolean; __typename?: string; } interface Seller { id: string; name: string; logo: string; } interface ClientPreferencesData { locale: string; optinNewsLetter?: any | null; optInNewsLetter?: any | null; savePersonalData?: boolean; savePaymentData?: boolean; __typename?: string; } interface VtexLegacyStorePreferencesData { countryCode: string; saveUserData: boolean; timeZone: string; currencyCode: string; currencyLocale: number; currencySymbol: string; currencyFormatInfo: CurrencyFormatInfo; } interface CurrencyFormatInfo { currencyDecimalDigits: number; currencyDecimalSeparator: string; currencyGroupSeparator: string; currencyGroupSize: number; startsWithCurrencySymbol: boolean; } interface ItemMetadata { items: ItemMetadataItem[]; } interface ItemMetadataItem { id: string; seller: string; name: string; skuName: string; productId: string; refId: string; ean: string | null; imageUrl: string; detailUrl: string; assemblyOptions: any[]; } interface RatesAndBenefitsData { rateAndBenefitsIdentifiers: RateAndBenefitsIdentifier[]; teaser: any[]; } interface RateAndBenefitsIdentifier { id: string; name: string; featured: boolean; description: string; matchedParameters: any; additionalInfo: any; triggeredBy?: any; } interface MarketingData { coupon: string | null; utmCampaign: string | null; utmMedium: string | null; utmSource: string | null; utmiCampaign: string | null; utmiPart: string | null; utmPartner?: string | null; utmipage?: string | null; marketingTags?: string[]; __typename?: string; } interface Payment { paymentSystem: string; bin: any; accountId: any; tokenId: any; installments: number | null; referenceValue: number; value: number; merchantSellerPayments?: any; __typename?: string; } interface OrderFormMessages { couponMessages?: any[]; generalMessages?: any[]; code?: string; fields?: any; status?: string; text?: string; __typename?: string; } interface VtexAddress { addressId: string; addressType: string; city: string; complement?: string; country: string; neighborhood: string; number: string; postalCode: string; receiverName: string | null; reference: any; state: string; street: string; isDisposable: boolean; geoCoordinates?: number[]; __typename?: string; } interface BaseClientData { email: string; firstName: string | null; lastName: string | null; document: string; documentType: string; phone: string | null; } interface VtexLegacyClientData extends BaseClientData { corporateDocument: string | null; corporateName: string | null; corporatePhone: string | null; customerClass: string | null; isCorporate: boolean; isProspect?: boolean; profileCompleteOnLoading: boolean; profileErrorOnLoading: boolean; stateInscription: string | null; tradeName: string | null; } interface ExtendedItemAdditionalInfo extends ItemAdditionalInfo { dimension: any; brandId: string; offeringInfo: any; offeringType: any; offeringTypeId: any; categoriesIds?: string; productClusterId?: string; commercialConditionId?: string; } interface ItemAdditionalInfo { brandName: string; __typename?: string; } interface BaseItem { uniqueId: string; id: string; productId: string; productRefId: string; refId: string; name: string; skuName: string; modalType: any; parentItemIndex: any; parentAssemblyBinding: any; assemblies?: any[]; price: number; listPrice: number; manualPrice: any; sellingPrice: number; isGift: boolean; productCategoryIds: string; productCategories: ProductCategories; quantity: number; seller: string; detailUrl: string; priceTags: PriceTags; availability: string; measurementUnit: string; unitMultiplier: number; priceDefinition: PriceDefinition; attachmentOfferings: any[]; offerings: any[]; attachments: any[]; bundleItems: any[]; } interface VtexLegacyItem extends BaseItem { additionalInfo: ExtendedItemAdditionalInfo; ean: string | null; priceValidUntil: string; tax: number; rewardValue: number; preSaleDate: any; sellerChain: string[]; imageUrl: string; components: any[]; availabilityMessage?: string; formattedPrice?: string; manufacturerCode: any; manualPriceAppliedBy?: string | null; taxCode?: any; } interface BaseOrderForm { loggedIn: boolean; canEditData: boolean; allowManualPrice: boolean; totalizers: VtexTotalizer[]; clientPreferencesData: ClientPreferencesData; marketingData: MarketingData | null; userProfileId: string | null; messages: OrderFormMessages; paymentData: PaymentData; value: number; customData: any | null; userType: string | null; } interface VtexLegacyOrderForm extends BaseOrderForm { items: VtexLegacyItem[]; clientProfileData: VtexLegacyClientData | null; orderFormId: string; salesChannel: string; isCheckedIn: boolean; storeId: string | null; checkedInPickupPointId: string | null; ignoreProfileData: boolean; selectableGifts: any[]; shippingData: VtexLegacyShippingData; sellers: Seller[]; commercialConditionData: any; storePreferencesData: VtexLegacyStorePreferencesData; giftRegistryData: any; openTextField: any; invoiceData: any; itemMetadata: ItemMetadata; hooksData: any; ratesAndBenefitsData: RatesAndBenefitsData; subscriptionData: any; merchantContextData: any; itemsOrdination: any; } //#endregion //#region [Vtex Catalog / Product] interface VtexLegacyCatalogProductCacheSku { available: boolean; availablequantity: number; bestPrice: number; bestPriceFormated: string; cacheVersionUsedToCallCheckout: string; dimensions: Record; discount?: number; fullSellingPrice: string; hasDiscount?: boolean; image: string; installments: number; installmentsInsterestRate: number; installmentsValue: number; listPrice: number; listPriceFormated: string; measures: { cubicweight: number; height: number; length: number; weight: number; width: number; }; rewardValue: number; seller: string; sellerId: string; sku: number; skuname: string; spotPrice: number; taxAsInt: number; taxFormated: string; unitMultiplier: number; validBestPrice?: boolean; validListPrice?: boolean; values: any[]; } interface VtexLegacyCatalogProductCache { available: boolean; dimensions: string[]; dimensionsInputType: Record; dimensionsMap: Record; displayMode: string; name: string; productId: number; salesChannel: string; skus: VtexLegacyCatalogProductCacheSku[]; } interface VtexLegacyCatalog { cache: { productWithVariations: Record; }; getProductWithVariations: () => {}; getShippingValue: () => {}; setProductWithVariationsCache: () => {}; } interface UniversalEventTracker { (eventName: Events, eventData: EventData): void; q?: Array<[ Events, EventData ]>; } //#region [Window] interface UniversalWindow extends OnsiteCoreWindow { mb_track: UniversalEventTracker; mb_recover_cart?: (payload: CartRecoveryPayload) => void; } //#endregion interface CartRecoveryPayload { cart_id: string; user_id: string; products: CartRecoveryProduct[]; } interface CartRecoveryProduct { product_id: string; sku: string; quantity: number; recovery_properties?: ProductPropertiesEvent; } declare global { interface Window extends UniversalWindow { } interface Window extends VtexWindow { } }