UNPKG

smartshopping-sdk

Version:

Coupon autoapply SDK

320 lines (319 loc) 8.71 kB
export type BorwserName = 'chrome' | 'firefox' | 'safari' | 'opera' | 'edge' | 'unknown'; export type EngineStage = 'inspect' | 'detect' | 'apply' | 'applyBest' | null; type ShadowSelector = { shadowRoots: Array<string>; target: string; }; export type Selector = string | ShadowSelector; export interface ErrorLogProps { selector?: Selector; message?: string; } interface ConditionElementVisisble { type: 'element_visible'; value: Selector; } interface ConditionElementExist { type: 'element_exist'; value: Selector; } interface ConditionLogic { type: 'or' | 'and' | 'not'; operands: Array<Condition>; } export type Condition = ConditionElementVisisble | ConditionElementExist | ConditionLogic; interface CommandIf { type: 'command_if'; condition: Condition; do: Array<Command>; else: Array<Command>; } interface IterationCodes { type: 'iteration_codes'; do: Array<Command>; } interface CommandWhile { type: 'command_while'; condition: Condition; do: Array<Command>; } export interface InteractAction { type: string; selector: Selector; eventClass?: InteractEventType; } export interface InteractResponse { type: 'added' | 'removed' | 'changed'; selector: Selector; } interface Anchor { type: 'anchor'; anchor: string; place: 'before' | 'after'; } interface CommandWait { type: 'command_wait'; response?: null | Array<InteractResponse>; timeout: number; } interface CommandInsert { type: 'command_insert'; selector: Selector; value?: string; } interface CommandApply { type: 'command_apply'; action: InteractAction; } interface CommandInteract { type: 'command_interact'; action: InteractAction; response: Array<InteractResponse>; timeout: number; } interface CommandForEach { type: 'command_for_each'; selector: string; indexName?: string; do: Array<Command>; } export type ExtractCut = { position: 'before'; rightEdge: string; } | { position: 'after'; leftEdge: string; } | { position: 'between'; leftEdge: string; rightEdge: string; }; export type ExtractFormat = 'number' | 'code' | 'decimalNumberWithoutDot' | 'raw' | 'undefinedCode'; interface CommandExtract { type: 'command_extract'; selector: Selector; target?: string; cut?: ExtractCut; format: ExtractFormat; codeIsValid?: boolean; } interface CommandStore { type: 'command_store'; target: 'total' | 'final' | 'code' | 'price' | 'title' | 'discountPrice' | 'variantGroupLabel' | 'variantGroupValue' | 'sku' | 'imageUrl'; } interface CommandReturn { type: 'command_return'; level: number; } interface CommandPushVariantGroup { type: 'command_push_variant_group'; } interface CommandPushVariantItem { type: 'command_push_variant_item'; } export type Command = CommandIf | CommandWhile | IterationCodes | Anchor | CommandWait | CommandInsert | CommandExtract | CommandStore | CommandApply | CommandInteract | CommandReturn | CommandForEach | CommandPushVariantGroup | CommandPushVariantItem; export interface EngineConfig { version: number; taskId: string; shopId: string; shopName: string; shopUrl: string; checkoutUrl: string; productUrl?: string; extendedLogs: boolean; extendedReports: boolean; inspect: Array<Command>; detect: Array<Command>; apply: Array<Command>; product: Array<Command>; applyBest: Array<Command>; selectorsToCheck: Array<Selector>; codes?: Array<string>; } export type ShopUrls = Omit<EngineConfig, 'inspect' | 'detect' | 'apply' | 'applyBest'>; export interface MessageInit { type: 'smartshopping_init'; checkout: boolean; product: boolean; config: string; promocodes?: Array<string>; persistedState?: EnginePersistedState; } interface MessagePersist { type: 'smartshopping_persist'; persistedState: EnginePersistedState; } interface MessageClearPersisted { type: 'smartshopping_clear'; } export interface MessageCheck { type: 'smartshopping_check'; defaultSelectors: { [key: string]: Array<Selector>; }; } export interface MessageSetCodes { type: 'smartshopping_codes'; promocodes: Array<string>; } export type LogEvent = { type: 'checkout'; shop: string; } | { type: 'product'; shop: string; } | { type: 'show'; shop: string; total: string; } | { type: 'show_slider'; shop: string; } | { type: 'close_slider'; shop: string; } | { type: 'detect'; shop: string; code: string; valid: boolean; } | { type: 'start'; shop: string; } | { type: 'abort'; shop: string; } | { type: 'error'; shop: string; stage: EngineStage; selector?: string; url: string; lang: string; browser: BorwserName; message: string; } | { type: 'success'; shop: string; code: string; total: string; discount: string; } | { type: 'report'; shop: string; url: string; total: string; discount: string; codes: string; layoutPage: string; } | { type: 'show_3d_party'; shop: string; } | { type: 'close_3d_party'; shop: string; } | { type: 'reactivate_3d_party'; shop: string; }; interface MessageLog { type: 'smartshopping_log'; event: LogEvent; } export type Message = MessageInit | MessageSetCodes | MessagePersist | MessageClearPersisted | MessageLog | MessageCheck; export interface EngineCheckoutState { total: null | number; } export interface EngineProductState { title: null | string; fullPrice: null | number; discountPrice: null | number; sku: null | string; imageUrl: null | string; variants: EngineProductVariantGroup[]; } export interface EngineProductVariantGroup { label: string; items: EngineProductVariantValue[]; } export interface EngineProductVariantValue { label: string; } export interface EngineDetectState { userCode: string; isValid: boolean; } export type EngineFinalCost = { [key: string]: number; }; export interface EngineExecContext { code: string; codeIsValid: boolean; activeParentElement: Element | null; value: string | null; return: number; criticalError: boolean; anchor: string | null; anchorCode: string | null; anchorStage: EngineStage; currentVariantGroupIndex: number | null; } export type EngineProgress = 'IDLE' | 'INSPECT' | 'INSPECT_END' | 'DETECT' | 'DETECT_END' | 'APPLY' | 'APPLY_END' | 'APPLY-BEST' | 'APPLY-BEST_END' | 'PRODUCT_INSPECT' | 'PRODUCT_INSPECT_END' | 'ERROR' | 'CANCEL'; export interface EngineState { checkoutState: EngineCheckoutState; productState: EngineProductState; finalCost: EngineFinalCost; progress: EngineProgress; config: EngineConfig; promocodes: Array<string>; detectState: EngineDetectState; bestCode: string; currentCode: string; checkout: boolean; product: boolean; } export interface EngineEvents { checkoutState?: (value: EngineCheckoutState, state: EngineState) => void; productState?: (value: EngineProductState, state: EngineState) => void; finalCost?: (value: EngineFinalCost, state: EngineState) => void; progress?: (value: EngineProgress, state: EngineState) => void; config?: (value: EngineConfig, state: EngineState) => void; promocodes?: (value: Array<string>, state: EngineState) => void; detectState?: (value: EngineDetectState, state: EngineState) => void; bestCode?: (value: string, state: EngineState) => void; currentCode?: (value: string, state: EngineState) => void; checkout?: (value: boolean, state: EngineState) => void; product?: (value: boolean, state: EngineState) => void; } export interface EnginePersistedState { context: EngineExecContext; finalCost: EngineFinalCost; productState: EngineProductState; checkoutState: EngineCheckoutState; promocodes: Array<string>; } export interface AdblockAndCookieOutput { isAdblockDisabled: boolean; isCookieEnabled: boolean; } export interface UserEndpoints { configs: { base: string[]; userConfig: string; shopConfig: string; versions: string; urls: string; defaultConfigs: string; }; stat: { base: string[]; logs: string; }; } export interface UserConfig { clientID: string; updateVersionsTime: number; endpoints: UserEndpoints; } export type InteractEventType = 'MouseEvent' | 'PointerEvent' | 'KeyboardEvent' | 'InputEvent' | 'FocusEvent' | 'CompositionEvent' | 'WheelEvent' | 'DragEvent' | 'TouchEvent' | 'ClipboardEvent' | 'Event'; export {};