import type { LanguageCode as I18nLanguageCode } from "@swishapp/i18n"; import type { PlacementSpec } from "../dom/create-placement"; import { IntentOptions } from "../intents/intents"; import { CountryCode, LanguageCode } from "../storefront-api/types/storefront.types"; import { Intent, StorefrontApiOptions } from "../swish"; import type { Product, ProductVariant } from "../types"; import type { DrawerSectionParsed, HomeSectionParsed, ListDetailPageSectionParsed, ListDetailSectionParsed, ListsSectionParsed, NotificationsSectionParsed, OrderDetailSectionParsed, OrdersSectionParsed, ProductDetailSectionParsed, ProfileSectionParsed, SavesSectionParsed, UiOptionsParsed } from "./schemas"; export interface SwishOptions { auth: AuthOptions; storefront: StorefrontApiOptions; context: StorefrontContext; intents: IntentOptions; metafields: MetafieldOptions; placements: PlacementSpec[]; transforms: TransformOptionsResolved; translations?: Record>; ui: UiOptionsParsed; } export interface AuthOptions { tokenUrl: string; } export interface StorefrontContext { customer: { id: string | null; email: string | null; firstName: string | null; lastName: string | null; b2b: boolean | null; }; localization: { country: CountryCode; language: LanguageCode; market: string; }; myshopifyDomain: string; newCustomerAccounts: boolean; routes: { accountUrl: string; rootUrl: string; listDetailPagePath: string; }; } export interface MetafieldOptions { product: `${string}.${string}`[]; productVariant: `${string}.${string}`[]; } export type Badge = { id: string; label: string; style?: Record; }; export interface TransformOptions { productTitle?: (args: { product: Product; }) => string; productDescription?: (args: { product: Product; }) => string; productBadges?: (args: { product: Product; variant?: ProductVariant; defaultBadges: string[]; }) => (string | Badge)[]; productPrice?: (args: { product: Product; variant?: ProductVariant; }) => string | false | undefined; addToCartButton?: (args: { product: Product; }) => boolean; variantTitle?: (args: { variant: ProductVariant; }) => string; optionValues?: (args: { option: NonNullable["options"][number]; optionValues: NonNullable["options"][number]["optionValues"]; }) => NonNullable["options"][number]["optionValues"]; } export type TransformOptionsResolved = Required; export type UiOptions = UiOptionsParsed; export interface UiDesignOptions { appearance?: { iconThickness?: number | string; }; sizes?: { buttonHeight?: number | string; iconButtonSize?: number | string; formInputHeight?: number | string; iconSize?: number | string; imageCardAspectRatio?: string; imageSliderAspectRatio?: string; }; rounding?: { borderRadiusScale?: number | string; badgeBorderRadius?: string; buttonBorderRadius?: string; dialogBorderRadius?: string; formInputBorderRadius?: string; imageCardBorderRadius?: string; imageSliderBorderRadius?: string; thumbnailBorderRadius?: string; }; colors?: { backgroundRgb?: string; textColorRgb?: string; textColorDangerRgb?: string; headingColorRgb?: string; primaryButtonBackgroundRgb?: string; primaryButtonColorRgb?: string; neutralButtonBackgroundRgb?: string; neutralButtonColorRgb?: string; dangerButtonColorRgb?: string; statusDotBackgroundRgb?: string; badgeBackgroundRgb?: string; badgeColorRgb?: string; overlayBackground?: string; savedIconColor?: string; }; typography?: { headingFontFamily?: string; headingTextTransform?: string; headingFontSize?: number | string; headingLetterSpacing?: string; headingLineHeight?: number | string; headingFontWeight?: number | string; textFontFamily?: string; textFontSize?: number | string; textLetterSpacing?: string; textLineHeight?: number | string; textLineHeightParagraph?: number | string; textFontWeight?: number | string; buttonFontFamily?: string; buttonTextTransform?: string; buttonFontSize?: number | string; buttonLetterSpacing?: string; buttonLineHeight?: number | string; buttonFontWeight?: number | string; badgeFontFamily?: string; badgeTextTransform?: string; badgeFontSize?: number | string; badgeLetterSpacing?: string; badgeLineHeight?: number | string; badgeFontWeight?: number | string; }; productCard?: { productCardTitleFontSize?: number | string; productCardTitleFontWeight?: number | string; productCardTitleColor?: string; }; navigation?: { navHeight?: number | string; navBackground?: string; navShadow?: string; navLabelFontSize?: number | string; navLabelTextTransform?: string; navLabelLetterSpacing?: string; navActiveIndicatorColor?: string; }; optionPill?: { optionPillHeight?: number | string; optionPillBorderRadius?: string; optionPillBackground?: string; optionPillBorderColor?: string; optionPillFontSize?: number | string; optionPillPadding?: number | string; optionPillSelectedBackground?: string; optionPillSelectedColor?: string; optionPillSelectedBorderColor?: string; }; drawer?: { drawerWidth?: number | string; drawerMobileTopOffset?: number | string; }; imageSlider?: { imageSliderDotColorSelected?: string; }; } export interface ViewSection { type: TType; hidden?: boolean; design?: Record; options?: Record; } export type DrawerSection = DrawerSectionParsed; export type HomeSection = HomeSectionParsed; export type SavesSection = SavesSectionParsed; export type ListsSection = ListsSectionParsed; export type ListDetailSection = ListDetailSectionParsed; export type ListDetailPageSection = ListDetailPageSectionParsed; export type OrdersSection = OrdersSectionParsed; export type OrderDetailSection = OrderDetailSectionParsed; export type ProductDetailSection = ProductDetailSectionParsed; export type ProfileSection = ProfileSectionParsed; export type NotificationsSection = NotificationsSectionParsed; export interface DrawerLogoInput { url?: string; altText?: string; } export interface FooterMenuItemInput { id: string; enabled: boolean; intent: Intent; } export type DrawerSectionInput = (ViewSection<"drawer-header"> & { options?: { title?: string; logo?: DrawerLogoInput; useCloseButton?: boolean; accountButton?: boolean; notificationButton?: boolean; }; }) | (ViewSection<"drawer-footer"> & { options?: { displayType?: "floating" | "docked"; showIcons?: boolean; showText?: boolean; items?: FooterMenuItemInput[]; }; }); export interface MiniMenuItemInput { title: string; url: string; } export type SimpleHomeSectionType = "sign-in" | "notifications" | "recently-viewed" | "saved-from-cart" | "saved-items" | "lists"; export type HomeSectionInput = ViewSection | (ViewSection<"mini-menu"> & { items?: MiniMenuItemInput[]; }) | (ViewSection<"content-block"> & { title?: string; body?: string; image?: { url: string; width?: number; height?: number; }; link?: { url: string; target?: "_self" | "_blank"; }; }) | (ViewSection<"featured-collection"> & { handle: string; }); export type SavesSectionInput = (ViewSection<"lists-section"> & { options?: { display?: "myLists" | "forYouLists"; layout?: "list" | "slider"; }; }) | (ViewSection<"all-items-grid"> & { options?: { showSaveButton?: boolean; showQuickBuyButton?: boolean; showVariantTitle?: boolean; enableVariantChange?: boolean; showVariantOptionNames?: boolean; }; }); export type ListsSectionInput = ViewSection<"lists-grid"> & { options?: { displayType?: "list" | "slider"; }; }; export type ListDetailPageSectionInput = ViewSection<"list-items-grid"> & { options?: { desktopColumns?: number; showBuyButton?: boolean; showVariantOptionNames?: boolean; enableVariantChange?: boolean; }; }; export type ListDetailSectionInput = ViewSection<"list-items-grid"> & { options?: { showVariantOptionNames?: boolean; enableVariantChange?: boolean; }; }; export type OrdersSectionInput = ViewSection<"orders-list">; export type OrderDetailSectionInput = ViewSection<"order-info"> | ViewSection<"order-items"> | ViewSection<"order-actions">; export type VariantSelectDisplay = "pills" | "rows"; export type ProductDetailSectionInput = (ViewSection<"image-slider"> & { options?: { flush?: boolean; loop?: boolean; }; }) | (ViewSection<"product-info"> & { options?: { descriptionMaxLines?: number; variantSelectDisplayType?: VariantSelectDisplay; hideSingleValueOptions?: boolean; images?: { baseTint?: boolean; }; }; }) | (ViewSection<"buy-buttons"> & { options?: { shopPay?: boolean; }; }) | ViewSection<"complementary-products"> | ViewSection<"related-products">; export type ProfileSectionInput = ViewSection<"profile-form">; export type NotificationsSectionInput = ViewSection<"notifications-list">; export interface DrawerOptions { design?: Record; options?: { position?: "left" | "right"; }; sections: DrawerSection[]; } export interface HomeViewOptions { sections: HomeSection[]; } export interface SavesViewOptions { sections: SavesSection[]; } export interface ListsViewOptions { sections: ListsSection[]; } export interface ListDetailViewOptions { sections: ListDetailSection[]; } export interface ListDetailPageViewOptions { sections: ListDetailPageSection[]; } export interface OrdersViewOptions { sections: OrdersSection[]; } export interface OrderDetailViewOptions { sections: OrderDetailSection[]; } export interface ProductDetailViewOptions { sections: ProductDetailSection[]; } export interface ProfileViewOptions { sections: ProfileSection[]; } export interface NotificationsViewOptions { sections: NotificationsSection[]; } export type ViewSectionMap = { drawer: DrawerSection; home: HomeSection; saves: SavesSection; lists: ListsSection; listDetail: ListDetailSection; listDetailPage: ListDetailPageSection; orders: OrdersSection; orderDetail: OrderDetailSection; productDetail: ProductDetailSection; profile: ProfileSection; notifications: NotificationsSection; };