import { MakeOptional } from '@myparcel/ts-utils'; import { CarrierName } from '@myparcel/constants'; import { CarrierSetting, ConfigSetting, OptionType, PickupLocationsView, RelatedConfigOptionType } from '../data'; import { CustomValidator } from './validation.types'; import { SupportedPackageTypeName, SupportedPlatformName, PlatformConfiguration } from './platform.types'; import { DeliveryOptionsOutput } from './output.types'; import { SelectOption } from './options.types'; import { MakeRequired } from './common.types'; import { DeliveryOptionsAddress } from './address.types'; export interface MapTileLayerData { attribution: string; maxZoom?: number; token?: string; url: string; } export interface FilterableOption { allow: boolean; items: string[]; } export type Weekday = 0 | 1 | 2 | 3 | 4 | 5 | 6; export type DropOffEntryObject = { weekday: Weekday | `${Weekday}`; cutoffTimeSameDay?: string; cutoffTime?: string; }; export type DropOffEntry = Weekday | DropOffEntryObject; export type DeliveryOptionsStrings = Record; export type CarrierIdentifier = `${CarrierName}:${number}` | CarrierName; export type TimestampString = `${number}:${number}` | string; export type Price = number | null; export interface CarrierSettings extends Partial> { allowDeliveryOptions?: boolean | FilterableOption; allowEveningDelivery?: boolean | FilterableOption; allowExpressDelivery?: boolean | FilterableOption; allowMondayDelivery?: boolean; allowMorningDelivery?: boolean | FilterableOption; allowOnlyRecipient?: boolean; allowPickupLocations?: boolean | FilterableOption; allowSameDayDelivery?: boolean; allowSaturdayDelivery?: boolean; allowSignature?: boolean; allowStandardDelivery?: boolean | FilterableOption; cutoffTime?: TimestampString; cutoffTimeSameDay?: TimestampString; deliveryDaysWindow?: number; dropOffDays?: DropOffEntryObject[]; dropOffDelay?: number; packageType?: SupportedPackageTypeName; priceEveningDelivery?: Price; priceExpressDelivery?: Price; priceMondayDelivery?: Price; priceMorningDelivery?: Price; priceOnlyRecipient?: Price; pricePackageTypeDigitalStamp?: Price; pricePackageTypeMailbox?: Price; pricePackageTypePackageSmall?: Price; pricePickup?: Price; priceSameDayDelivery?: Price; priceSaturdayDelivery?: Price; priceSignature?: Price; priceStandardDelivery?: Price; } export interface InputCarrierSettings extends Omit, DeprecatedConfigOptions { dropOffDays?: DropOffEntry[] | string; } export type InputCarrierSettingsObject = Partial>; export type CarrierSettingsObject = Partial>; export interface DeliveryOptionsConfig extends Partial>, CarrierSettings { allowPickupLocationsViewSelection: boolean; apiBaseUrl: string; carrierSettings: CarrierSettingsObject; closedDays: Date[]; /** * Currency. Defaults to format of the browser. */ currency: string | undefined; /** * Locale. Defaults to the language of the browser. */ locale: string | undefined; pickupLocationsDefaultView: PickupLocationsView; pickupLocationsMapTileLayerData: string | MapTileLayerData; pickupShowDistance: boolean; platform: SupportedPlatformName; showDeliveryDate: boolean; showPriceSurcharge: boolean; showPriceZeroAsFree: boolean; showPrices: boolean; } export type ResolvedDeliveryOptionsConfig = MakeRequired; export interface DeprecatedConfigOptions { /** @deprecated use ShowDeliveryDate instead */ allowShowDeliveryDate?: boolean; /** @deprecated use dropOffDays instead */ fridayCutoffTime?: TimestampString; /** @deprecated use dropOffDays instead */ saturdayCutoffTime?: TimestampString; } /** * Includes deprecated options which will be filtered out. */ export type InputDeliveryOptionsConfig = { dropOffDays?: DropOffEntry[] | string; carrierSettings?: InputCarrierSettingsObject; } & Omit, 'carrierSettings' | 'dropOffDays'> & DeprecatedConfigOptions; export interface DeliveryOptionsConfiguration { address: DeliveryOptionsAddress; config: DeliveryOptionsConfig; initial: Partial; platformConfig: PlatformConfiguration; strings: DeliveryOptionsStrings; } export interface InputDeliveryOptionsConfiguration { address: DeliveryOptionsAddress; config: InputDeliveryOptionsConfig; initial?: Partial; platformConfig: PlatformConfiguration; strings?: DeliveryOptionsStrings; } export type RelatedConfigOption = { type: RelatedConfigOptionType; key: string; }; export interface BaseConfigOption { key: ConfigKey | string; parents?: ConfigKey[]; perCarrier?: boolean; related?: RelatedConfigOption[]; type?: T; validators?: CustomValidator[]; } export interface SelectConfigOption extends BaseConfigOption { options: SelectOption[]; type: OptionType.Select | OptionType.MultiSelect; } export type ConfigOption = BaseConfigOption | SelectConfigOption; export type ResolvedConfigOption = O extends ConfigOption ? O : ConfigOption; export type CarrierSettingsKey = CarrierSetting; export type ConfigKey = ConfigSetting | CarrierSettingsKey;