@benshi.ai/js-sdk
Version:
Benshi SDK
214 lines (183 loc) • 4.68 kB
text/typescript
import { BloodMeta } from "./blood.typings"
import { CurrencyCode } from "../../core/commonTypes"
import { OxygenMeta } from "./oxygen.typings"
export enum ECommerceTypes {
Cancel = "cancel_checkout",
Cart = "cart",
Checkout = "checkout",
Delivery = "delivery",
Item = "item",
List = "list",
Rate = "rate",
ScheduleDelivery = "schedule_delivery"
}
export enum ItemAction {
View = "view",
Detail = "detail",
Impression = "impression",
AddFavorite = "add_favorite",
RemoveFavorite = "remove_favorite",
AddReminder = "add_reminder",
RemoveReminder = "remove_reminder",
RemoveReminderAuto = "remove_reminder_auto"
}
export enum ItemType {
Blood = "blood",
Book = "book",
Clothing = "clothing",
Drug = "drug",
Electronics = "electronics",
MedicalEquipment = "medical_equipment",
Misc = "misc",
Oxygen = "oxygen"
}
export enum StockStatus {
InStock = 'in_stock',
LowStock = 'low_stock',
OutOfStock = 'out_of_stock'
}
// not supported by ts-interface-checker
// export type ItemTypeWithoutMeta = Exclude<ItemType, ItemType.Blood | ItemType.Oxygen>
export interface TypedItem {
id: string,
type: ItemType
}
export type BaseItemDetail = {
id: string,
quantity: number,
price: number,
currency: CurrencyCode,
stock_status?: StockStatus,
promo_id?: string
}
export type MetaBloodItemDetail = BaseItemDetail & { type: ItemType.Blood, meta: BloodMeta }
export type MetaOxygenItemDetail = BaseItemDetail & { type: ItemType.Oxygen, meta: OxygenMeta }
export type DrugItemDetail = BaseItemDetail & { type: ItemType.Drug }
export type BloodItemDetail = BaseItemDetail & { type: ItemType.Blood }
export type OxygenItemDetail = BaseItemDetail & { type: ItemType.Oxygen }
export type MedicalEquipmentDetail = BaseItemDetail & { type: ItemType.MedicalEquipment }
export type MetaItemDetail =
| MetaBloodItemDetail
| MetaOxygenItemDetail
| DrugItemDetail
| MedicalEquipmentDetail
export type ItemDetail =
| BloodItemDetail
| OxygenItemDetail
| DrugItemDetail
| MedicalEquipmentDetail
export interface ItemProperties {
action: ItemAction,
item: ItemDetail,
search_id?: string
meta?: any
}
/**
* @internal
*/
export interface InternalItemProperties extends ItemProperties {
usd_rate: number
}
export enum CartAction {
AddItem = "add_item",
RemoveItem = "remove_item"
}
export interface CartProperties {
id: string;
action: CartAction,
item: ItemDetail,
cart_price: number,
currency: CurrencyCode,
meta?: any
}
/**
* @internal
*/
export interface InternalCartProperties extends CartProperties {
usd_rate: number
}
export enum ListAction {
Add = "add_item",
Discard = "discard",
Edit = "edit_item",
Remove = "remove_item",
View = "view",
}
export enum ListType {
Cart = "cart",
Favourite = "favourite",
Order = "order",
Reminder = "reminder"
}
export interface CheckoutProperties {
id: string //order_id
is_successful: boolean
cart_price: number,
currency: CurrencyCode,
items: Array<MetaItemDetail>,
cart_id: string
meta?: any
}
/**
* @internal
*/
export interface InternalCheckoutProperties extends CheckoutProperties {
usd_rate: number
}
export enum DeliveryAction {
Delivered = "delivered"
}
export interface DeliveryProperties {
id: string,
action: DeliveryAction,
order_id: string,
meta?: any
}
export interface DrugProperties {
market_id: string,
name: string,
description?: string,
supplier_id: string,
supplier_name: string,
producer?: string,
packaging?: string,
active_ingredients: Array<string>,
drug_form?: string,
drug_strength?: string,
atc_anatomical_group?: string,
otc_or_ethical?: string
}
/**
* @internal
*/
export interface InternalDrugProperties extends DrugProperties {
id: string
}
export enum CancelType {
Cart = 'cart',
Order = 'order'
}
export interface CancelCheckoutProperties {
id: string,
type: CancelType,
items: TypedItem[],
reason: string,
meta?: any
}
export enum ScheduleDeliveryAction {
Schedule = "schedule",
Update = "update"
}
export interface ScheduleDeliveryProperties {
order_id: string,
is_urgent: boolean, // true = emergency, false = schedule
action: ScheduleDeliveryAction,
ts?: string // (RFC 3339 - currentTime for urgent, else pass the one provided.
meta?: any
}
/**
* @internal
*/
export interface InternalScheduleDeliveryProperties extends ScheduleDeliveryProperties {
ts: string
}