import { OnsiteCoreWindow } from "@mailbiz/onsite-core"; //#region [Window] interface EcomplusWindow extends OnsiteCoreWindow { _context: EcomProductPageContext; ecomPassport: EcomPassport; ecomCart: EcomCart; storefrontApp: EcomStorefrontApp; } //#endregion //#region [Pubsub and Events] type PubSubMethod = (eventName: string, cb: Function) => void; interface EcomPubSub { off: PubSubMethod; on: PubSubMethod; once: PubSubMethod; } //#endregion //#region [Ecom Product Page] interface EcomProductPageContext extends EcomPubSub { body?: EcomProductPage; resource?: string; } interface EcomProductPage extends EcomProduct { notes?: string; body_html: string; body_text: string; inventory_records: Array; variations?: EcomProductVariations[]; } //#endregion //#region [Ecom Passport] interface EcomPassport extends EcomPubSub { lang: string; customer: Partial; getCustomer: () => Partial; getCustomerName: () => string; } interface EcomCustomer { _id: string; main_email: string; display_name: string; registry_type: string; enabled: boolean; login: boolean; accepts_marketing: boolean; currency_id: string; currency_symbol: string; name: { given_name: string; family_name: string; middle_name: string; }; birth_date: { day: number; month: number; year: number; }; phones: Array<{ number: string; }>; doc_number: string; addresses: Array<{ _id: string; zip: string; province_code: string; name: string; number: number; complement?: string; near_to?: string; street: string; city: string; borough: string; default: boolean; }>; orders: EcomCustomerOrder[]; } //#endregion //#region [Ecom Cart] interface EcomCart extends EcomPubSub, EcomCartData { storeId: string; addProduct: (product: GetProductDataResponse, variationId: string | undefined, quantity: string) => void; } interface EcomCartData { data: { items: EcomCartProduct[] | EcomOrderProduct[]; subtotal: number; _id: string; orders?: string[]; flags?: string[]; customers?: string[]; permalink?: string; }; } interface EcomCartProduct extends EcomProduct { variation_id: string; product_id: string; picture: EcomPicture; max_quantity: number; final_price: number; specifications: EcomProductVariationSpecifications; } //#endregion //#region [Ecom Product] interface EcomProduct { _id: string; name: string; available: boolean; sku: string; slug: string; base_price?: number; price: number; quantity: number; min_quantity?: number; pictures: EcomPicture[]; meta_title: string; subtitle: string; meta_description?: string; cost_price?: number; weight: { value: number; unit: string; }; dimensions: { height: { value: number; unit: string; }; width: { value: number; unit: string; }; length: { value: number; unit: string; }; }; brands?: Array<{ _id: string; name: string; slug: string; logo?: { url: string; size: string; alt: string; }; }>; commodity_type: string; visible: boolean; ad_relevance: number; currency_id: string; currency_symbol: string; manage_stock: boolean; condition: string; adult: boolean; auto_fill_related_products: boolean; videos?: Array<{ url: string; }>; keywords: Array; views: number; sales: number; total_sold: number; categories: Array<{ _id: string; name: string; slug: string; google_product_category_id?: number; }>; updated_at: string; store_id: number; created_at: string; customizations?: any[]; short_description?: string; } interface EcomProductVariations { _id: string; specifications?: EcomProductVariationSpecifications; name: string; sku: string; quantity: number; picture_id?: string; gtin?: string; mpn?: string; weight?: { value: number; unit: string; }; dimensions?: { width: { value: number; unit: string; }; height: { value: number; unit: string; }; length: { value: number; unit: string; }; }; price?: number; } interface EcomProductVariationSpecifications { [property: string]: EcomProductVariationSpecificationProperties[]; } interface EcomProductVariationSpecificationProperties { text: string; value: string; } //#endregion //#region [Ecom Storefront App] interface EcomStorefrontApp { amount: EcomStorefrontAmount; // This data is incorrect router: { currentRoute: { matched: { 0: { instances: { default: EcomStorefrontAppDefault; }; }; }; }; }; } interface EcomStorefrontAppDefault { discountCoupon?: string; amount?: EcomStorefrontAmount; selectedAddress?: EcomStorefrontAddress; order?: EcomStorefrontOrder; } interface EcomStorefrontAmount { discount: number; freight: number; subtotal: number; total: number; } interface EcomStorefrontAddress { borough: string; city: string; complement: string; default: boolean; name: string; near_to: string; number: number; province_code: string; street: string; zip: string; _id: string; } interface EcomStorefrontOrder { status: string; _id: string; number: number; transactions: Array<{ amount: number; intermediator: { payment_method: { code: string; }; transaction_id: string; transaction_code: string; buyer_id: string; }; notes: string; account_deposit: { valid_thru: string; }; status: { updated_at: string; current: string; }; type: string; payment_method: { code: string; name: string; }; currency_id: string; currency_symbol: string; app: { _id: string; label: string; intermediator: { name: string; link: string; code: string; }; }; _id: string; }>; opened_at: string; buyers: Array<{ main_email: string; display_name: string; name: { given_name: string; family_name: string; middle_name: string; }; photos: Array; phones: Array<{ number: string; }>; registry_type: string; doc_number: string; _id: string; }>; items: Array<{ quantity: number; customizations: Array; product_id: string; variation_id: string; picture: { zoom: { url: string; size: string; alt: string; }; big: { url: string; size: string; alt: string; }; normal: { url: string; size: string; alt: string; }; }; sku: string; name: string; price: number; final_price: number; _id: string; stock_status: string; }>; utm: {}; browser_ip: string; client_user_agent: string; channel_type: string; domain: string; checkout_link: string; status_link: string; amount: { subtotal: number; discount: number; freight: number; extra: number; total: number; }; shipping_lines: Array<{ _id: string; app: { _id: string; label: string; carrier: string; service_name: string; service_code: string; icon: string; }; to: { zip: string; province_code: string; name: string; city: string; borough: string; street: string; number: number; complement: string; near_to: string; }; from: { zip: string; street: string; number: number; }; own_hand: boolean; receipt: boolean; discount: number; total_price: number; delivery_time: { days: number; working_days: boolean; }; posting_deadline: { days: number; working_days: boolean; after_approval: boolean; }; custom_fields: Array<{ field: string; value: string; }>; package: { dimensions: { width: { value: number; unit: string; }; height: { value: number; unit: string; }; length: { value: number; unit: string; }; }; weight: { value: number; unit: string; }; }; }>; shipping_method_label: string; extra_discount: { discount_coupon: string; value: number; flags: Array; app: { label: string; _id: string; }; }; payment_method_label: string; staff_signature: boolean; source_name: string; currency_id: string; currency_symbol: string; budget_only: boolean; store_id: number; created_at: string; updated_at: string; financial_status: { current: string; updated_at: string; }; payments_history: Array<{ _id: string; transaction_id: string; status: string; date_time: string; flags: Array; notification_code?: string; customer_notified?: boolean; }>; metafields: Array<{}>; } //#endregion //#region [Order] interface EcomOrderProduct { _id: string; product_id: string; sku: string; name: string; picture: { zoom: { url: string; size: string; alt: string; }; big: { url: string; size: string; alt: string; }; normal: { url: string; size: string; alt: string; }; }; quantity: number; min_quantity: number; max_quantity: number; currency_id: string; currency_symbol: string; price: number; final_price: number; keep_item_quantity: boolean; keep_item_price: boolean; } interface EcomCustomerOrder { _id: string; amount: { subtotal: number; discount: number; freight: number; extra: number; total: number; }; shipping_method_label: string; payment_method_label: string; number: number; currency_id: string; currency_symbol: string; created_at: string; } interface GetProductDataResponse extends EcomProduct { variations?: EcomProductVariations[]; } //#endregion //#region [Generics] interface EcomPicture { zoom: { url: string; size: string; alt: string; }; big: { url: string; size: string; alt: string; }; normal: { url: string; size: string; alt: string; }; _id?: string; } declare global { interface Window extends EcomplusWindow { } }