@elbwalker/utils
Version:
Shared utils for walkerOS packages
90 lines (75 loc) • 3.71 kB
TypeScript
import { Elb, WalkerOS } from '@elbwalker/types';
declare function getLanguage(navigatorRef: Navigator): string | undefined;
declare function getTimezone(): string | undefined;
declare function getScreenSize(windowRef: Window): string;
declare const elb: Elb.Fn;
declare function getAttribute(element: Element, name: string): string;
declare function getHashWeb(str: string, length?: number): Promise<string>;
declare function isVisible(element: HTMLElement): boolean;
type SendDataValue = WalkerOS.Property | WalkerOS.Properties;
type SendHeaders = {
[key: string]: string;
};
interface SendResponse {
ok: boolean;
data?: unknown;
error?: string;
}
type SendWebTransport = 'fetch' | 'beacon' | 'xhr';
interface SendWebOptions {
headers?: SendHeaders;
transport?: SendWebTransport;
method?: string;
}
interface SendWebOptionsFetch extends SendWebOptions {
credentials?: 'omit' | 'same-origin' | 'include';
noCors?: boolean;
}
type SendWebOptionsDynamic<T extends SendWebTransport> = T extends 'fetch' ? SendWebOptionsFetch : SendWebOptions;
type SendWebReturn<T extends SendWebTransport> = T extends 'fetch' ? Promise<SendResponse> : SendResponse;
declare function sendWeb<T extends SendWebTransport>(url: string, data?: SendDataValue, options?: SendWebOptionsDynamic<T> & {
transport?: T;
}): SendWebReturn<T>;
declare function sendWebAsFetch(url: string, data?: SendDataValue, options?: SendWebOptionsFetch): Promise<SendResponse>;
declare function sendWebAsBeacon(url: string, data?: SendDataValue): SendResponse;
declare function sendWebAsXhr(url: string, data?: SendDataValue, options?: SendWebOptions): SendResponse;
interface SessionConfig extends SessionStorageConfig {
consent?: string | string[];
storage?: boolean;
cb?: SessionCallback | false;
instance?: WalkerOS.Instance;
}
type SessionFunction = typeof sessionStorage | typeof sessionWindow;
type SessionCallback = (session: WalkerOS.SessionData, instance: WalkerOS.Instance | undefined, defaultCb: SessionCallback) => void;
declare function sessionStart(config?: SessionConfig): WalkerOS.SessionData | void;
type StorageType = 'cookie' | 'local' | 'session';
interface SessionStorageConfig extends SessionWindowConfig {
deviceKey?: string;
deviceStorage?: StorageType;
deviceAge?: number;
sessionKey?: string;
sessionStorage?: StorageType;
length?: number;
pulse?: boolean;
}
declare function sessionStorage(config?: SessionStorageConfig): WalkerOS.SessionData;
interface MarketingParameters {
[key: string]: string;
}
interface SessionWindowConfig {
data?: WalkerOS.Properties;
domains?: string[];
isStart?: boolean;
parameters?: MarketingParameters;
referrer?: string;
url?: string;
}
declare function sessionWindow(config?: SessionWindowConfig): WalkerOS.SessionData;
interface StorageValue {
e: number;
v: string;
}
declare function storageDelete(key: string, storage?: StorageType): void;
declare function storageRead(key: string, storage?: StorageType): WalkerOS.PropertyType;
declare function storageWrite(key: string, value: WalkerOS.PropertyType, maxAgeInMinutes?: number, storage?: StorageType, domain?: string): WalkerOS.PropertyType;
export { type SendWebOptions, type SendWebOptionsFetch, type SendWebReturn, type SendWebTransport, type SessionCallback, type SessionConfig, type SessionFunction, type SessionStorageConfig, type SessionWindowConfig, type StorageValue, elb, getAttribute, getHashWeb, getLanguage, getScreenSize, getTimezone, isVisible, sendWeb, sendWebAsBeacon, sendWebAsFetch, sendWebAsXhr, sessionStart, sessionStorage, sessionWindow, storageDelete, storageRead, storageWrite };