@depict-ai/utilishared 2.1.7 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ES10/index.cjs +763 -3225
- package/ES10/index.d.ts +340 -1116
- package/ES10/index.js +764 -3164
- package/latest/index.cjs +806 -3169
- package/latest/index.d.ts +340 -1116
- package/latest/index.js +807 -3108
- package/package.json +2 -2
- package/server/ES10/index.cjs +764 -3222
- package/server/ES10/index.d.ts +340 -1116
- package/server/ES10/index.js +765 -3161
- package/server/latest/index.cjs +807 -3166
- package/server/latest/index.d.ts +340 -1116
- package/server/latest/index.js +808 -3105
package/server/latest/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSX, Accessor } from "solid-js";
|
|
2
|
-
export const version = "2.
|
|
2
|
+
export const version = "2.3.0";
|
|
3
3
|
export const is_debug: boolean;
|
|
4
4
|
/**
|
|
5
5
|
* Sets the prefix of dlog, dwarn, and derror messages in the browser console. Defaults to `[Depict]`.
|
|
@@ -329,742 +329,7 @@ export const depict_add_to_cart: (vars: Partial<{
|
|
|
329
329
|
}> & {
|
|
330
330
|
[key: string]: any;
|
|
331
331
|
}) => boolean | Promise<void | undefined> | undefined;
|
|
332
|
-
export
|
|
333
|
-
marketing: boolean;
|
|
334
|
-
necessary: boolean;
|
|
335
|
-
preferences: boolean;
|
|
336
|
-
statistics: boolean;
|
|
337
|
-
};
|
|
338
|
-
export function get_cookie(cookie_name: string): string | undefined;
|
|
339
|
-
export function Promise_Any<T>(promises: (T | PromiseLike<T>)[] | Iterable<T | PromiseLike<T>>): Promise<T>;
|
|
340
|
-
/**
|
|
341
|
-
* Broadcasts the product id of the current page to a BroadcastChannel `right_click_attribution`.
|
|
342
|
-
* This enables a page in another tab where right-clicking on a recommendation yielded to the opening of this page to send click tracking events.
|
|
343
|
-
*/
|
|
344
|
-
export function broadcast_product_id(product_id: string): Promise<void>;
|
|
345
|
-
/**
|
|
346
|
-
* This function is a post processor for recommendation renderer which adds a "new tab listener" to the recommendations. That means that it will listen for right-and wheel clicks on the elements and if a tab opens (=broadcasts the product id) of the clicked product it emulates a click event (using contextmenu_callback)
|
|
347
|
-
* @param elements Elements that event listeners will be added on
|
|
348
|
-
* @param display The display to take the product_id from
|
|
349
|
-
* @param info InfoForProcessing to get Tenant instance out of
|
|
350
|
-
* @return `elements` 1:1
|
|
351
|
-
*/
|
|
352
|
-
export function add_new_tab_listener(elements: NodeListOf<ChildNode> | Node_Array, display: Display, info?: any, get_event_listener_remover?: (remover: VoidFunction) => void): NodeListOf<ChildNode> | Node_Array;
|
|
353
|
-
/**
|
|
354
|
-
* This is the event handler for the new tab tracking function (add_new_tab_listener)
|
|
355
|
-
* @param e Click event
|
|
356
|
-
* @param product_id product_id of clicked product
|
|
357
|
-
* @return A promise resolving to void after 60s or when the product id was broadcasted
|
|
358
|
-
*/
|
|
359
|
-
export function contextmenu_callback(e: Event, product_id: string): Promise<void>;
|
|
360
|
-
/**
|
|
361
|
-
* Make parts of a type optional
|
|
362
|
-
*
|
|
363
|
-
* From: https://github.com/Microsoft/TypeScript/issues/25760#issuecomment-614417742
|
|
364
|
-
*/
|
|
365
|
-
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
366
|
-
export class ElementObserverEvent<ElemType extends CallbackableNode = HTMLElement, SelectorType extends string | CallbackableNode = string | CallbackableNode> {
|
|
367
|
-
constructor(opts: {
|
|
368
|
-
element_: ElemType;
|
|
369
|
-
selector_: SelectorType;
|
|
370
|
-
disconnector_: Disconnector;
|
|
371
|
-
mutation_record_?: MutationRecord;
|
|
372
|
-
event_?: ListenerNames;
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
export interface ElementObserverEvent<ElemType extends CallbackableNode = HTMLElement, SelectorType extends string | CallbackableNode = string | CallbackableNode> {
|
|
376
|
-
element: ElemType;
|
|
377
|
-
selector: SelectorType;
|
|
378
|
-
disconnector: Disconnector;
|
|
379
|
-
mutation_record?: MutationRecord;
|
|
380
|
-
event?: ListenerNames;
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Element.querySelectorAll is broken in Chrome 37-latest, use this instead.
|
|
384
|
-
* Related bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1286047
|
|
385
|
-
* @param element Quite broadly anything you'd normaly call querySelectorAll on, including "null"
|
|
386
|
-
* @param selector The selector to search for
|
|
387
|
-
* @return Stock return value
|
|
388
|
-
*/
|
|
389
|
-
export function patched_querySelectorAll<T extends Element>(element: Element | Document | DocumentFragment | null, selector: string): NodeListOf<T> | T[] | undefined;
|
|
390
|
-
export interface ElementObserver {
|
|
391
|
-
/**
|
|
392
|
-
* Immediately calls the callback with an ElementObserverEvent for nodes existing in the DOM that match the provided selector OR are the selector,
|
|
393
|
-
* also calls the callback with an ElementObserverEvent whenever ANYTHING in the DOM occurs that makes an element match the provided selector.
|
|
394
|
-
* @param selector Selector string or element to listen for
|
|
395
|
-
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
396
|
-
*/
|
|
397
|
-
onexists: EO_listener_also_taking_els;
|
|
398
|
-
/**
|
|
399
|
-
* Dispatches an ElementObserverEvent whenever a node is added to the DOM that matches the specified selector OR is the selector.
|
|
400
|
-
* @param selector CSS selector or element to observe
|
|
401
|
-
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
402
|
-
**/
|
|
403
|
-
oncreation: EO_listener_also_taking_els;
|
|
404
|
-
/**
|
|
405
|
-
* Dispatches an ElementObserverEvent whenever a node is removed from the DOM that matches the specified selector OR is the selector.
|
|
406
|
-
* @param selector CSS selector or element to observe
|
|
407
|
-
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
408
|
-
*/
|
|
409
|
-
onremoved: EO_listener_also_taking_els;
|
|
410
|
-
/**
|
|
411
|
-
* Dispatches an ElementObserverEvent whenever a node that matches the specified selector or its children change in the DOM.
|
|
412
|
-
* @param selector CSS selector or element to observe
|
|
413
|
-
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
414
|
-
*/
|
|
415
|
-
onchange: EO_listener;
|
|
416
|
-
/**
|
|
417
|
-
* Immediately calls the callback with an ElementObserverEvent on nodes that match the provided selector OR are the selector.
|
|
418
|
-
* @param selector Selector string or element to look for in the DOM
|
|
419
|
-
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
420
|
-
*/
|
|
421
|
-
ifexists: EO_listener_also_taking_els;
|
|
422
|
-
/**
|
|
423
|
-
* Adds a territory to the observer. The observer will observe all elements in the new territory and the one it observed before. `ifexists` checks made in the past won't be made again. Add your shadow roots here on creation and `observer` will finds elements in them.
|
|
424
|
-
*/
|
|
425
|
-
add_territory: (what: HTMLElement | Document | DocumentFragment) => void;
|
|
426
|
-
/**
|
|
427
|
-
* Removes a territory again. Useful for no longer observing shadow roots.
|
|
428
|
-
*/
|
|
429
|
-
remove_territory: (what: HTMLElement | Document | DocumentFragment) => void;
|
|
430
|
-
/**
|
|
431
|
-
* See docs for observer.onexists. Will return a Promise that resolves to the element out of the first call of an observer.onexists callback.
|
|
432
|
-
* @param selector Selector string or element to wait for
|
|
433
|
-
* @param timeout timeout to stop listening and resolve the Promise with `undefined`
|
|
434
|
-
*/
|
|
435
|
-
wait_for_element: <ElemType extends HTMLElement = HTMLElement>(selector: string | ElemType, timeout?: number) => Promise<ElemType>;
|
|
436
|
-
/**
|
|
437
|
-
* See docs for observer.on<listener>. Will return a Promise that resolves to the first element that matches the given listener and selector. I.e. `wait_for_listener("removed", ".old-recs");` will resolve to the first element matching `.old-recs` that is removed from the DOM
|
|
438
|
-
* @param listener one of the possible functions on ElementObserver that start with "on", without the "on". So "creation", "change", "exists" or "removed"
|
|
439
|
-
* @param selector String containing CSS selector
|
|
440
|
-
* @param timeout timeout to stop listening and resolve the Promise with `undefined`
|
|
441
|
-
*/
|
|
442
|
-
wait_for_listener: <ElemType extends HTMLElement = HTMLElement, SelectorType = string | CallbackableNode>(listener: SelectorType extends CallbackableNode ? "creation" | "removed" : "exists" | "creation" | "removed" | "change", selector: SelectorType, timeout?: number) => Promise<ElemType>;
|
|
443
|
-
}
|
|
444
|
-
export class ElementObserver {
|
|
445
|
-
#private;
|
|
446
|
-
constructor({
|
|
447
|
-
territory
|
|
448
|
-
}?: {
|
|
449
|
-
territory?: HTMLElement | Document | DocumentFragment | (HTMLElement | Document | DocumentFragment)[];
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
type EO_listener = <ElemType extends HTMLElement = HTMLElement>(selector: string, callback: ObserverCallbackFunction<ElemType>) => Disconnector;
|
|
453
|
-
type EO_listener_also_taking_els = <ElemType extends CallbackableNode = HTMLElement, SelectorType extends string | CallbackableNode = string | CallbackableNode>(selector: SelectorType, callback: ObserverCallbackFunction<ElemType, SelectorType>) => Disconnector;
|
|
454
|
-
type ListenerNames = "exists" | "creation" | "removed" | "change";
|
|
455
|
-
type ObserverCallbackFunction<ElemType extends CallbackableNode, SelectorType extends string | CallbackableNode = string | CallbackableNode> = (event: ElementObserverEvent<ElemType, SelectorType>) => any;
|
|
456
|
-
export type Disconnector = () => unknown;
|
|
457
|
-
type CallbackableNode = Element | Text | Comment;
|
|
458
|
-
/**
|
|
459
|
-
* Epic alien tech that categorizes DOM mutations, allowing one to listen and quickly (+2 ticks in the microtask queue, all before paint) react to DOM mutations such as elements (matching a selector) being added, deleted or changed.
|
|
460
|
-
*/
|
|
461
|
-
export const observer: ElementObserver;
|
|
462
|
-
/**
|
|
463
|
-
* Useful for the `thresholds` option of IntersectionObserver - if you want to be notified at a 10% change, call this and set num_steps to 10. Pls see https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/thresholds
|
|
464
|
-
* @param numSteps How many steps (notifications) there should be between 0 and 100% intersection
|
|
465
|
-
* @return Stuff to give to IntersectionObserver
|
|
466
|
-
*/
|
|
467
|
-
export function buildThresholdList(numSteps: number): number[];
|
|
468
|
-
/**
|
|
469
|
-
* A Post processor for Recommendation renderer to add impression tracking to all displays
|
|
470
|
-
*/
|
|
471
|
-
export const impression_tracking_post_processor: RR_PostProcessor<any>;
|
|
472
|
-
interface ImpressionTrackingOptions {
|
|
473
|
-
/** The element to observe for impressions. */
|
|
474
|
-
element: HTMLElement;
|
|
475
|
-
/** The impression data to send to the api (this is combined with context data) */
|
|
476
|
-
data: ExplicitImpressionEventData;
|
|
477
|
-
/** When true the element will be observed by the IntersectionObserver only after it's inserted into the DOM.
|
|
478
|
-
* Sometimes with a pollyfilled IntersectionObserver it ignores elements that are not in the DOM yet.
|
|
479
|
-
* Defaults to true.
|
|
480
|
-
* */
|
|
481
|
-
wait_for_dom_insertion?: boolean;
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Registers the passed element for impression tracking.
|
|
485
|
-
* The element will be observed for intersection with the viewport.
|
|
486
|
-
* Also handles sending the impression event.
|
|
487
|
-
*
|
|
488
|
-
* @return A function to stop observing the element for impressions
|
|
489
|
-
*/
|
|
490
|
-
export const impression_track_element: ({
|
|
491
|
-
element,
|
|
492
|
-
data,
|
|
493
|
-
wait_for_dom_insertion
|
|
494
|
-
}: ImpressionTrackingOptions) => () => void;
|
|
495
|
-
/** The start and end visibility threshold for an intersection to count as an impression */
|
|
496
|
-
export let impression_threshold: number[];
|
|
497
|
-
export const set_impression_threshold: (start: number, end: number) => number[];
|
|
498
|
-
/** The minimum duration the element has to be visible above the thresholds before it counts as an impression */
|
|
499
|
-
export const has_to_be_intersecting_for = 500;
|
|
500
|
-
/** What explicit information is needed to form an ImpressionEvent */
|
|
501
|
-
export type ExplicitImpressionEventData = {
|
|
502
|
-
recommendation_type?: string;
|
|
503
|
-
entity_price?: number;
|
|
504
|
-
market?: string;
|
|
505
|
-
tenant?: string;
|
|
506
|
-
product_id?: string;
|
|
507
|
-
} & ({
|
|
508
|
-
recommendation_id: string;
|
|
509
|
-
} | {
|
|
510
|
-
search_result_id: string;
|
|
511
|
-
} | {
|
|
512
|
-
product_listing_result_id: string;
|
|
513
|
-
} | {
|
|
514
|
-
suggestions_result_id: string;
|
|
515
|
-
});
|
|
516
|
-
/** What an impression event looks like when sent to the api */
|
|
517
|
-
export type ImpressionEvent = {
|
|
518
|
-
/** The type for impression events should be element_visible */
|
|
519
|
-
type: "element_visible";
|
|
520
|
-
} & (ExplicitImpressionEventData | TrackingEventContextData);
|
|
521
|
-
/**
|
|
522
|
-
* Sends an impression event to the api.
|
|
523
|
-
*
|
|
524
|
-
* Impression events always use websockets.
|
|
525
|
-
*/
|
|
526
|
-
export const send_impression_event: (data: Optional<ImpressionEvent, "type">) => void;
|
|
527
|
-
/**
|
|
528
|
-
* Adds an event listener to a given element (example: recommendation link) which adds the provided product_id and recommendation_id to the 'depict' localStorage object
|
|
529
|
-
* @param {HTMLElement} a_element - The element to listen on the "click event"
|
|
530
|
-
* @param {string} product_id - A unique identifier for the product which can be used to rerecognize it on the product page
|
|
531
|
-
* @param {string} recommendation_id - The recommendation ID of the recommendation
|
|
532
|
-
* @param {Function} additional_listener - An additional function to execute onclick
|
|
533
|
-
*/
|
|
534
|
-
export function bind_tracking_to_link(a_element: Element, product_id: string, recommendation_id: string, additional_listener?: Function): ((e: Event) => void) | undefined;
|
|
535
|
-
export type A2CTrackingFunction = (product_id: string, recommendation_id: string, was_unmatching: boolean, event: Event) => any;
|
|
536
|
-
/**
|
|
537
|
-
* Adds an event listener to a given element (example: the purchase button) which calls `tracking_fn(product_id,recommendation_id)` if the product_id exists in the 'depict' localStorage object
|
|
538
|
-
* @param {HTMLElement} button - The element to listen on the "click event"
|
|
539
|
-
* @param {Function} get_product_id - A function to get the product_id of the current page/the product associated with the add to cart button
|
|
540
|
-
* @param {A2CTrackingFunction} tracking_fn - A function which gets executed on click of button
|
|
541
|
-
* @param {Boolean} [unmatching_tracking] - also call tracking_fn on products not found in localStorage.
|
|
542
|
-
*/
|
|
543
|
-
export function bind_to_a2c_button(button: Element, get_product_id: (url?: string, e?: Event) => string | Promise<string>, tracking_fn: A2CTrackingFunction, unmatching_tracking?: boolean, event?: string): Promise<void>;
|
|
544
|
-
type after_navig_fn = (arg0: Parameters<typeof history.replaceState | typeof history.pushState>, what_happened: "replaceState" | "pushState") => any;
|
|
545
|
-
/**
|
|
546
|
-
* AsyncIterable which resolves with the new href every time location.href changes
|
|
547
|
-
*/
|
|
548
|
-
export const stateless_href_change_ipns: IPNS<string>;
|
|
549
|
-
/**
|
|
550
|
-
* AsyncIterable which resolves when you await it with the current href and then once every time it changes
|
|
551
|
-
*/
|
|
552
|
-
export const href_change_ipns: IPNS<string>;
|
|
553
|
-
/**
|
|
554
|
-
* Functions to instantly (synchronously) call when a "popstate" event occurs, before the href_change_ipns' resolve
|
|
555
|
-
* This kind of bypasses the IPNS' point, and I'm sorry for that inconsistency, but I'm working on a feature that's not in the roadmap and am encountering issues due to the 1 tick delay of the IPNS. IPNS were a mistake, I'm sorry for them.
|
|
556
|
-
*/
|
|
557
|
-
export const instant_exec_on_suspect_history_change: Set<(what_happened?: "replaceState" | "pushState" | "popstate", args?: PopStateEvent | Parameters<typeof history.replaceState> | Parameters<typeof history.pushState>) => void>;
|
|
558
|
-
export function on_next_navigation(callback: (new_href: string) => void): Promise<void>;
|
|
559
|
-
/**
|
|
560
|
-
* Proxies history.pushState, and, if the second argument is true, history.replaceState so that it executes the provided `after_navigation` function after the navigation (calling the original function) but before returning to what called it.
|
|
561
|
-
* Please also consider adding a listener to the `popstate` event (`window.addEventListener("popstate", handler)`) to cover ALL navigation possibilities.
|
|
562
|
-
* @param after_navigation Function to call after history.replaceState and history.pushState
|
|
563
|
-
* @param replace_replaceState=true Whether to call the function also on history.replaceState.
|
|
564
|
-
* @return Void
|
|
565
|
-
*/
|
|
566
|
-
export function history_replacer(after_navigation: after_navig_fn, replace_replaceState?: boolean): Promise<void>;
|
|
567
|
-
interface TrackingData {
|
|
568
|
-
/** The active market, if any */
|
|
569
|
-
market?: string;
|
|
570
|
-
/** The merchant id */
|
|
571
|
-
tenant: string;
|
|
572
|
-
}
|
|
573
|
-
export interface PageViewEventData extends TrackingData {
|
|
574
|
-
/** If the page is a pdp, include the product_id */
|
|
575
|
-
product_id?: string;
|
|
576
|
-
}
|
|
577
|
-
export interface PageViewTrackingData extends TrackingData {
|
|
578
|
-
/** A function that returns the product_id of the product being displayed on href,
|
|
579
|
-
* if the href points to a PDP */
|
|
580
|
-
get_product_id: (href: string) => string | undefined | Promise<string | undefined>;
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Sends a page_view event to Depict tracking if it hasn't been sent yet for the current page url
|
|
584
|
-
* It also broadcasts the current URL to a BroadcastChannel using the function `broadcast_url`, this is used for right click + open in new tab tracking
|
|
585
|
-
* @return A promise resolving to void
|
|
586
|
-
*/
|
|
587
|
-
export function send_page_view_if_needed(data: PageViewEventData): Promise<void>;
|
|
588
|
-
/**
|
|
589
|
-
* Sends a page_view event to Depict tracking, and another one any time the page URL changes
|
|
590
|
-
*/
|
|
591
|
-
export function send_page_view_on_navigation(data: PageViewTrackingData): Promise<void>;
|
|
592
|
-
export function make_tracker_send_to_depict(ga_tracker: any, append_to_url?: string): void;
|
|
593
|
-
export function create_ga_queue(): void;
|
|
594
|
-
/**
|
|
595
|
-
* Returns current consent status synchronously, meaning the user might not have seen the dialog yet (in which case this will return false)
|
|
596
|
-
* @return Current consent status, whether selected or not
|
|
597
|
-
*/
|
|
598
|
-
export const cookiebot_get_consent: () => any;
|
|
599
|
-
/**
|
|
600
|
-
* Returns an promise that resolves when the end user has selected to grant or withold tracking consent.
|
|
601
|
-
* @return Consent status, once selected
|
|
602
|
-
*/
|
|
603
|
-
export function cookiebot_wait_for_consent(): Promise<boolean>;
|
|
604
|
-
/**
|
|
605
|
-
* Returns an IPNS that resolves with initial consent when Cookiebot has loaded, or immediately if a consent cookie already exists.
|
|
606
|
-
* As well as a new consent object every time the consent status has changed
|
|
607
|
-
* @return An IPNS resolving to the consent object
|
|
608
|
-
*/
|
|
609
|
-
export function cookiebot_get_cookie_ipns(): IPNS<ConsentObj>;
|
|
610
|
-
/**
|
|
611
|
-
* Anonymize Depict id until required consent level has been given through Cookiebot.
|
|
612
|
-
*
|
|
613
|
-
* This can be used for tenants using Cookiebot for privacy policy. It will set {@link get_depict_id} to return "anonymous" until
|
|
614
|
-
* required consent level has been given. The required consent level is defined by env.DEPICT_TRACKING_CONSENT_LEVEL.
|
|
615
|
-
* It will do a initial check for existing cookie with the required consent to avoid sending "anonymous" even if we have required consent.
|
|
616
|
-
*
|
|
617
|
-
* NOTE that this uses {@link set_depict_id_fn} to set {@link get_depict_id} and shouldn't be mixed with other uses of {@link set_depict_id_fn}.
|
|
618
|
-
*/
|
|
619
|
-
export const init_cookiebot_tracking: (anon_id?: any) => Promise<void | undefined>;
|
|
620
|
-
declare global {
|
|
621
|
-
interface Window {
|
|
622
|
-
Cookiebot?: {
|
|
623
|
-
name: string;
|
|
624
|
-
consented: boolean;
|
|
625
|
-
declined: boolean;
|
|
626
|
-
changed: boolean;
|
|
627
|
-
hasResponse: boolean;
|
|
628
|
-
consentID: string;
|
|
629
|
-
consent: Consent;
|
|
630
|
-
isOutsideEU: boolean;
|
|
631
|
-
isOutOfRegion: boolean;
|
|
632
|
-
host: string;
|
|
633
|
-
domain: string;
|
|
634
|
-
currentPath: string;
|
|
635
|
-
doNotTrack: boolean;
|
|
636
|
-
consentLevel: string;
|
|
637
|
-
isRenewal: boolean;
|
|
638
|
-
forceShow: boolean;
|
|
639
|
-
dialog: null;
|
|
640
|
-
responseMode: string;
|
|
641
|
-
serial: string;
|
|
642
|
-
scriptId: string;
|
|
643
|
-
scriptElement: ScriptElement;
|
|
644
|
-
whitelist: any[];
|
|
645
|
-
cookieList: CookieList;
|
|
646
|
-
pathlist: any[];
|
|
647
|
-
userIsInPath: boolean;
|
|
648
|
-
cookieEnabled: boolean;
|
|
649
|
-
versionChecked: boolean;
|
|
650
|
-
versionRequested: boolean;
|
|
651
|
-
version: number;
|
|
652
|
-
latestVersion: number;
|
|
653
|
-
isNewVersion: boolean;
|
|
654
|
-
CDN: string;
|
|
655
|
-
source: string;
|
|
656
|
-
retryCounter: number;
|
|
657
|
-
frameRetryCounter: number;
|
|
658
|
-
bulkConsentFrameRetryCounter: number;
|
|
659
|
-
setOnloadFrameRetryCounter: number;
|
|
660
|
-
optOutLifetime: number;
|
|
661
|
-
consentLifetime: null;
|
|
662
|
-
framework: string;
|
|
663
|
-
hasFramework: boolean;
|
|
664
|
-
frameworkBlocked: boolean;
|
|
665
|
-
frameworkLoaded: boolean;
|
|
666
|
-
iframeReady: boolean;
|
|
667
|
-
iframe: Iframe;
|
|
668
|
-
bulkconsent: null;
|
|
669
|
-
bulkresetdomains: any[];
|
|
670
|
-
bulkconsentsubmitted: boolean;
|
|
671
|
-
isbulkrenewal: boolean;
|
|
672
|
-
wipe: Wipe;
|
|
673
|
-
consentUTC: Date;
|
|
674
|
-
IABConsentString: string;
|
|
675
|
-
GACMConsentString: string;
|
|
676
|
-
dataLayerName: string;
|
|
677
|
-
loaded: boolean;
|
|
678
|
-
autoblock: boolean;
|
|
679
|
-
mutationObserver: null;
|
|
680
|
-
mutationCounter: number;
|
|
681
|
-
mutationFallback: boolean;
|
|
682
|
-
mutationFallbackDocAttributes: any[];
|
|
683
|
-
mutationHandlerFallbackCharsetLoaded: boolean;
|
|
684
|
-
mutationAppName: string;
|
|
685
|
-
mutationEventListeners: any[];
|
|
686
|
-
mutationOnloadEventListeners: any[];
|
|
687
|
-
mutateEventListeners: boolean;
|
|
688
|
-
mutationHandlerFirstScript: null;
|
|
689
|
-
postPonedMutations: any[];
|
|
690
|
-
nonAsyncMutations: any[];
|
|
691
|
-
deferMutations: any[];
|
|
692
|
-
geoRegions: any[];
|
|
693
|
-
userCountry: string;
|
|
694
|
-
userCulture: string;
|
|
695
|
-
windowOnloadTriggered: boolean;
|
|
696
|
-
botDetectionDisabled: boolean;
|
|
697
|
-
regulations: Regulations;
|
|
698
|
-
regulationRegions: RegulationRegions;
|
|
699
|
-
commonTrackers: CommonTrackers;
|
|
700
|
-
configuration: Configuration;
|
|
701
|
-
inlineConfiguration: null;
|
|
702
|
-
processLinkClickCounter: number;
|
|
703
|
-
performanceEntriesCounter: number;
|
|
704
|
-
OverrideEventListenersOnloadFired: any[];
|
|
705
|
-
OverrideEventListenersOnloadToFire: any[];
|
|
706
|
-
fallbackScriptNodes: any[];
|
|
707
|
-
fallbackDeferNodes: any[];
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
export interface CommonTrackers {
|
|
712
|
-
domains: Domain[];
|
|
713
|
-
}
|
|
714
|
-
export interface Domain {
|
|
715
|
-
d: string;
|
|
716
|
-
c: number[];
|
|
717
|
-
}
|
|
718
|
-
export interface Configuration {
|
|
719
|
-
loaded: boolean;
|
|
720
|
-
loadRetry: number;
|
|
721
|
-
tags: any[];
|
|
722
|
-
trackingDomains: any[];
|
|
723
|
-
}
|
|
724
|
-
export interface Consent {
|
|
725
|
-
stamp: string;
|
|
726
|
-
necessary: boolean;
|
|
727
|
-
preferences: boolean;
|
|
728
|
-
statistics: boolean;
|
|
729
|
-
marketing: boolean;
|
|
730
|
-
}
|
|
731
|
-
export interface CookieList {
|
|
732
|
-
cookieTablePreference: any[];
|
|
733
|
-
cookieTableStatistics: any[];
|
|
734
|
-
cookieTableAdvertising: any[];
|
|
735
|
-
cookieTableUnclassified: any[];
|
|
736
|
-
}
|
|
737
|
-
export interface Iframe {
|
|
738
|
-
cookieconsentDataStyleDisplay: string;
|
|
739
|
-
mtjQuery171028673205955022363: number;
|
|
740
|
-
}
|
|
741
|
-
export interface RegulationRegions {
|
|
742
|
-
gdpr: string[];
|
|
743
|
-
ccpa: string[];
|
|
744
|
-
lgpd: string[];
|
|
745
|
-
}
|
|
746
|
-
export interface Regulations {
|
|
747
|
-
gdprApplies: boolean;
|
|
748
|
-
ccpaApplies: boolean;
|
|
749
|
-
lgpdApplies: boolean;
|
|
750
|
-
}
|
|
751
|
-
export interface ScriptElement {}
|
|
752
|
-
export interface Wipe {
|
|
753
|
-
preferences: boolean;
|
|
754
|
-
statistics: boolean;
|
|
755
|
-
marketing: boolean;
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* Returns current consent status synchronously, meaning the user might not have seen the dialog yet (in which case this will return false)
|
|
759
|
-
* @return Current consent status, whether selected or not
|
|
760
|
-
*/
|
|
761
|
-
export const optanon_get_consent: () => any;
|
|
762
|
-
/**
|
|
763
|
-
* Returns an promise that resolves when the end user has selected to grant or withold tracking consent.
|
|
764
|
-
* @return Consent status
|
|
765
|
-
*/
|
|
766
|
-
export function optanon_wait_for_consent(): Promise<boolean>;
|
|
767
|
-
/**
|
|
768
|
-
* Returns an IPNS that resolves with initial consent when Optanon has loaded, or immediately if a consent cookie already exists.
|
|
769
|
-
* As well as a new consent object every time the consent status has changed
|
|
770
|
-
* @return An IPNS resolving to the consent object
|
|
771
|
-
*/
|
|
772
|
-
export function optanon_get_cookie_ipns(): IPNS<ConsentObj>;
|
|
773
|
-
/**
|
|
774
|
-
* Anonymize Depict id until required consent level has been given through OneTrust's Optanon.
|
|
775
|
-
*
|
|
776
|
-
* This can be used for tenants using OneTrust for privacy policy. It will set {@link get_depict_id} to return "anonymous" until
|
|
777
|
-
* required consent level has been given. The required consent level is defined by env.DEPICT_TRACKING_CONSENT_LEVEL.
|
|
778
|
-
* It will do a initial check for existing cookie with the required consent to avoid sending "anonymous" even if we have required consent.
|
|
779
|
-
*
|
|
780
|
-
* NOTE that this uses {@link set_depict_id_fn} to set {@link get_depict_id} and shouldn't be mixed with other uses of {@link set_depict_id_fn}.
|
|
781
|
-
*/
|
|
782
|
-
export const init_optanon_tracking: (anon_id?: any) => Promise<void | undefined>;
|
|
783
|
-
export const load_gtag: (GA_ID: string, strict?: boolean | undefined) => Promise<void | undefined>;
|
|
784
|
-
export const setup_gtag: (GA_ID: string) => void | undefined;
|
|
785
|
-
export const gtag_view: <T extends Display>(raw_displays: T[], get_product_id: (url?: string | T | undefined) => string | Promise<string>, more?: {
|
|
786
|
-
[key: string]: any;
|
|
787
|
-
list_name?: string | undefined;
|
|
788
|
-
} | ((display: T) => {
|
|
789
|
-
[key: string]: any;
|
|
790
|
-
}) | undefined) => Promise<void | undefined>;
|
|
791
|
-
export const gtag_click: (product_id: string | number, index: number, more?: object | undefined) => Promise<any>;
|
|
792
|
-
export const send_ga: (action: string) => any;
|
|
793
|
-
export const setup_ga: (GAID: string) => void | undefined;
|
|
794
|
-
export const ga_rec_click: () => any;
|
|
795
|
-
export const ga_purchase_click: () => any;
|
|
796
|
-
export const insert_styling: (css: string) => Promise<void | undefined>;
|
|
797
|
-
/**
|
|
798
|
-
* A function meant to use to track the main add to cart button on the product page of an integration.
|
|
799
|
-
* * @param tenant instance of `Tenant` class
|
|
800
|
-
* @param selector The selector to use to find the button
|
|
801
|
-
* @param validator A function that can invalidate the click event before tracking is sent
|
|
802
|
-
* @return A `Disconnector` to stop looking for more add to cart buttons to track
|
|
803
|
-
*/
|
|
804
|
-
export const track_a2c: (tenant: Tenant, selector: string, validator?: ((e: Event) => boolean) | undefined) => Disconnector;
|
|
805
|
-
/**
|
|
806
|
-
* Basically a RecRendererResult with less strict typing
|
|
807
|
-
*/
|
|
808
|
-
export interface Surface<T extends Display> {
|
|
809
|
-
elements?: Node_Array;
|
|
810
|
-
displays?: T[];
|
|
811
|
-
should_stay_inserted?: Promise<boolean>;
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* Functions existing on ChildNode that are commonly used to insert recommendations into the DOM
|
|
815
|
-
*/
|
|
816
|
-
export type InsertionVerb = "after" | "before" | "replaceWith" | "append" | "prepend" | "replaceChildren";
|
|
817
|
-
/**
|
|
818
|
-
* Tries to extract a product id from an url.
|
|
819
|
-
* The method used to retrive product id used here is very narrow, probably better to use something else instead?
|
|
820
|
-
*
|
|
821
|
-
* @example normal_get_product_id("www.foo.com/bar/baz.html") // "baz"
|
|
822
|
-
*
|
|
823
|
-
* @param url The url to check, defaults to `window.location`
|
|
824
|
-
* @returns
|
|
825
|
-
*/
|
|
826
|
-
export const normal_get_product_id: (url?: string) => string;
|
|
827
|
-
declare global {
|
|
828
|
-
interface Document {
|
|
829
|
-
depictwashere: boolean;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
/**
|
|
833
|
-
* If you need custom market logic that {@link depict_init_with_market_logic} doesn't support then use this function.
|
|
834
|
-
*
|
|
835
|
-
* Used to initialize an integration-script, this should always be the entrypoint of an integration.
|
|
836
|
-
*
|
|
837
|
-
* Makes sure that your script doesn't run twice
|
|
838
|
-
*/
|
|
839
|
-
export const depict_init: (callback: () => Promise<void>) => void;
|
|
840
|
-
/**
|
|
841
|
-
* Initialize an integration-script like {@link depict_init}, but with automatic handling of unsupported and unknown markets.
|
|
842
|
-
*
|
|
843
|
-
* @param options.extract_market A function that extracts the current market, and if the market is supported, unsupported or unknown
|
|
844
|
-
* @param options.callback If `extract_market` returned a supported market, calls `depict_init` with this callback.
|
|
845
|
-
* @param options.supported_markets Markets where our script should run, in order to get the best typechecking you should add a `as const`
|
|
846
|
-
* modifier to this type like so `["foo", "bar"] as const`.
|
|
847
|
-
* @param options.unsupported_markets Markets we are aware of and where our script shouldn't run.
|
|
848
|
-
* @param options.preferred_demo_market Market to use on .demo.depict.ai, if an override is needed for all users.
|
|
849
|
-
* depict-override-market query parameter will override this behaviour.
|
|
850
|
-
*
|
|
851
|
-
* ### Behaviour
|
|
852
|
-
*
|
|
853
|
-
* - market is unsupported - log to console and exit
|
|
854
|
-
* - market is unknown - report to sentry and exit
|
|
855
|
-
*
|
|
856
|
-
* ### Override market
|
|
857
|
-
*
|
|
858
|
-
* When running in debug mode the market can be overridden by setting a `depict-override-market` query param.
|
|
859
|
-
* For example http://tenant.domain?depict-override-market=ez
|
|
860
|
-
*/
|
|
861
|
-
export function depict_init_with_market_logic<T extends readonly string[]>(callback: (market: T[number]) => Promise<void>, get_market: () => Promise<string | undefined> | string | undefined, supported_markets: T, unsupported_markets: string[], preferred_demo_market?: string): void;
|
|
862
|
-
type IdType = string | undefined | Promise<string | undefined>;
|
|
863
|
-
export interface Tenant<ProductId extends IdType> {
|
|
864
|
-
TENANT: string;
|
|
865
|
-
tenant: string;
|
|
866
|
-
MARKET: TwoLetterMarket;
|
|
867
|
-
market: TwoLetterMarket;
|
|
868
|
-
TYPE: string;
|
|
869
|
-
type: string;
|
|
870
|
-
GA_ID: string;
|
|
871
|
-
gaid: string;
|
|
872
|
-
get_product_id: (url?: string) => ProductId extends string | undefined ? string : Promise<string>;
|
|
873
|
-
product_id: (url?: string) => string | Promise<string>;
|
|
874
|
-
dataset: DOMStringMap;
|
|
875
|
-
modify: boolean;
|
|
876
|
-
is_debug: boolean;
|
|
877
|
-
debug: boolean;
|
|
878
|
-
dlog: typeof dlog;
|
|
879
|
-
Sentry: typeof Sentry;
|
|
880
|
-
catchify: typeof catchify;
|
|
881
|
-
err: (...errors: any[]) => undefined;
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Tenant class. This describes which site/customer one is on, in which market, and some more information. It also sends the page_view event if not already done and highlights elements with a `.depict` class if `localStorage['highlight-depict']` is `"true"`
|
|
885
|
-
* @param options A object with constructor options
|
|
886
|
-
*/
|
|
887
|
-
export class Tenant<ProductId extends IdType = IdType> {
|
|
888
|
-
constructor(options: {
|
|
889
|
-
TENANT?: string;
|
|
890
|
-
TYPE?: string;
|
|
891
|
-
MARKET: TwoLetterMarket;
|
|
892
|
-
GA_ID: string;
|
|
893
|
-
get_product_id: (url?: string) => ProductId;
|
|
894
|
-
current_script_override?: HTMLScriptElement;
|
|
895
|
-
pageview_tracking?: boolean;
|
|
896
|
-
});
|
|
897
|
-
}
|
|
898
|
-
/**
|
|
899
|
-
* This is a list of alpha-2 country codes plus some two letter combinations commonly used to describe markets
|
|
900
|
-
*/
|
|
901
|
-
export type TwoLetterMarket = "af" | "al" | "dz" | "as" | "ad" | "ao" | "ai" | "aq" | "ag" | "ar" | "am" | "aw" | "au" | "at" | "az" | "bs" | "bh" | "bd" | "bb" | "by" | "be" | "bz" | "bj" | "bm" | "bt" | "bo" | "bq" | "ba" | "bw" | "bv" | "br" | "io" | "bn" | "bg" | "bf" | "bi" | "cv" | "kh" | "cm" | "ca" | "ky" | "cf" | "td" | "cl" | "cn" | "cx" | "cc" | "co" | "km" | "cd" | "cg" | "ck" | "cr" | "hr" | "cu" | "cw" | "cy" | "cz" | "ci" | "dk" | "dj" | "dm" | "do" | "ec" | "eg" | "sv" | "gq" | "er" | "ee" | "sz" | "et" | "fk" | "fo" | "fj" | "fi" | "fr" | "gf" | "pf" | "tf" | "ga" | "gm" | "ge" | "de" | "gh" | "gi" | "gr" | "gl" | "gd" | "gp" | "gu" | "gt" | "gg" | "gn" | "gw" | "gy" | "ht" | "hm" | "va" | "hn" | "hk" | "hu" | "is" | "in" | "id" | "ir" | "iq" | "ie" | "im" | "il" | "it" | "jm" | "jp" | "je" | "jo" | "kz" | "ke" | "ki" | "kp" | "kr" | "kw" | "kg" | "la" | "lv" | "lb" | "ls" | "lr" | "ly" | "li" | "lt" | "lu" | "mo" | "mg" | "mw" | "my" | "mv" | "ml" | "mt" | "mh" | "mq" | "mr" | "mu" | "yt" | "mx" | "fm" | "md" | "mc" | "mn" | "me" | "ms" | "ma" | "mz" | "mm" | "na" | "nr" | "np" | "nl" | "nc" | "nz" | "ni" | "ne" | "ng" | "nu" | "nf" | "mp" | "no" | "om" | "pk" | "pw" | "ps" | "pa" | "pg" | "py" | "pe" | "ph" | "pn" | "pl" | "pt" | "pr" | "qa" | "mk" | "ro" | "ru" | "rw" | "re" | "bl" | "sh" | "kn" | "lc" | "mf" | "pm" | "vc" | "ws" | "sm" | "st" | "sa" | "sn" | "rs" | "sc" | "sl" | "sg" | "sx" | "sk" | "si" | "sb" | "so" | "za" | "gs" | "ss" | "es" | "lk" | "sd" | "sr" | "sj" | "se" | "ch" | "sy" | "tw" | "tj" | "tz" | "th" | "tl" | "tg" | "tk" | "to" | "tt" | "tn" | "tr" | "tm" | "tc" | "tv" | "ug" | "ua" | "ae" | "gb" | "um" | "us" | "uy" | "uz" | "vu" | "ve" | "vn" | "vg" | "vi" | "wf" | "eh" | "ye" | "zm" | "zw" | "ax" | "uk" | "en" | "da" | "eu" | "sv" | "oc" | "nb" | "sq";
|
|
902
|
-
type ImpressionTrackOptions = {
|
|
903
|
-
t?: Tenant;
|
|
904
|
-
impression_tracking?: false;
|
|
905
|
-
} | {
|
|
906
|
-
impression_tracking: true;
|
|
907
|
-
t: Tenant;
|
|
908
|
-
};
|
|
909
|
-
type TenantSpecificationOptions = {
|
|
910
|
-
t?: Tenant;
|
|
911
|
-
tenant: string;
|
|
912
|
-
market: string;
|
|
913
|
-
get_product_id: (url?: string) => string | Promise<string>;
|
|
914
|
-
} | {
|
|
915
|
-
t: Tenant;
|
|
916
|
-
tenant?: string;
|
|
917
|
-
market?: string;
|
|
918
|
-
get_product_id?: (url?: string) => string | Promise<string>;
|
|
919
|
-
};
|
|
920
|
-
type ElementDiscoveryOptions = {
|
|
921
|
-
product_selector: string;
|
|
922
|
-
product_elements?: null | void | undefined;
|
|
923
|
-
} | {
|
|
924
|
-
product_selector?: null | void | undefined;
|
|
925
|
-
product_elements: HTMLElement[];
|
|
926
|
-
};
|
|
927
|
-
type A2CButtonDiscoveryOptions = {
|
|
928
|
-
a2c_selector: string;
|
|
929
|
-
a2c_elements?: null | void | undefined;
|
|
930
|
-
} | {
|
|
931
|
-
a2c_selector?: null | void | undefined;
|
|
932
|
-
a2c_elements: HTMLElement[];
|
|
933
|
-
};
|
|
934
|
-
/**
|
|
935
|
-
* @deprecated Please use DPC instead.
|
|
936
|
-
* Does not support ModernDisplays.
|
|
937
|
-
*/
|
|
938
|
-
export const AIO: (options: {
|
|
939
|
-
attempt_gtag_view_tracking?: boolean | undefined;
|
|
940
|
-
no_gtag?: boolean | undefined;
|
|
941
|
-
shade?: boolean | undefined;
|
|
942
|
-
always_track_a2c?: boolean | undefined;
|
|
943
|
-
get_rec_id?: ((elem: HTMLElement) => string | undefined) | undefined;
|
|
944
|
-
get_prod_id?: ((elem: HTMLElement) => (string | undefined) | Promise<string | undefined>) | undefined;
|
|
945
|
-
get_ga_prod_id?: ((elem: HTMLElement) => string | undefined | Promise<string | undefined>) | undefined;
|
|
946
|
-
click_location_prefix?: ((elem: HTMLElement) => string | undefined) | undefined;
|
|
947
|
-
rec_a2c_selector?: string | undefined;
|
|
948
|
-
rec_a2c_unbubbled?: boolean | undefined;
|
|
949
|
-
get_display?: ((elem: HTMLElement) => Partial<LegacyDisplay> | undefined) | undefined;
|
|
950
|
-
} & ImpressionTrackOptions & TenantSpecificationOptions & ElementDiscoveryOptions & A2CButtonDiscoveryOptions, gtag_options?: {
|
|
951
|
-
[key: string]: any;
|
|
952
|
-
list_name?: string | undefined;
|
|
953
|
-
} | undefined) => Promise<{
|
|
954
|
-
add_a2c_element: (element: HTMLElement) => void;
|
|
955
|
-
add_product_element: (element: HTMLElement) => Promise<void | undefined>;
|
|
956
|
-
} | undefined>;
|
|
957
|
-
export const paint_red: (element: HTMLElement) => void | undefined;
|
|
958
|
-
/**
|
|
959
|
-
* A function that attempts to "serialize" an object to a text representation that helps with debugging when using sentry
|
|
960
|
-
* @param anything Something to try to serialize - this function is crappy and your mileage may vary
|
|
961
|
-
* @param depth How deep to go when recursing
|
|
962
|
-
* @return An object that is somehow closer to text (better serializable by sentry) or text
|
|
963
|
-
*/
|
|
964
|
-
export function serialize_object(anything: Object, depth?: number): Object;
|
|
965
|
-
export const wait: (delay: number) => Promise<unknown>;
|
|
966
|
-
/**
|
|
967
|
-
* Fetch with retry and exponetial back off. This is the 2.0 version of the previous Windows proof fetch.
|
|
968
|
-
*
|
|
969
|
-
* Windows proof fetch is a utility which retries fetch requests 10 times when they fail. Reason for this is a certain windows 10 build where the network stack randomly breaks 20% of https connections
|
|
970
|
-
* @param url Url to perform fetch towards
|
|
971
|
-
* @param options Fetch options
|
|
972
|
-
* @param max_retries Max number of retries, defaults to 10
|
|
973
|
-
* @param useFetch The fetch function to use, defaults to the global fetch
|
|
974
|
-
* @returns The fetch response
|
|
975
|
-
*/
|
|
976
|
-
export function fetch_retry(url: RequestInfo | URL, options?: RequestInit, max_retries?: number, useFetch?: typeof fetch): Promise<false | Response>;
|
|
977
|
-
type PossibleEndpoint = "general" | "product" | "products" | "category";
|
|
978
|
-
type ExclusiveId = {
|
|
979
|
-
category_id: string;
|
|
980
|
-
product_id?: undefined;
|
|
981
|
-
product_ids?: undefined;
|
|
982
|
-
} | {
|
|
983
|
-
category_id?: undefined;
|
|
984
|
-
product_id: string;
|
|
985
|
-
product_ids?: undefined;
|
|
986
|
-
} | {
|
|
987
|
-
category_id?: undefined;
|
|
988
|
-
product_id?: undefined;
|
|
989
|
-
product_ids: string[];
|
|
990
|
-
} | {
|
|
991
|
-
category_id?: undefined;
|
|
992
|
-
product_id?: undefined;
|
|
993
|
-
product_ids?: undefined;
|
|
994
|
-
};
|
|
995
|
-
type FetchRecsOptions = {
|
|
996
|
-
type: string;
|
|
997
|
-
user_id?: string;
|
|
998
|
-
session_id?: string;
|
|
999
|
-
metadata?: Record<string, any>;
|
|
1000
|
-
} & ExclusiveId;
|
|
1001
|
-
/**
|
|
1002
|
-
* @deprecated, use fetchDepictRecommendations instead
|
|
1003
|
-
* Fetches recommendations from the depict v2 recommendation api.
|
|
1004
|
-
* Will select the endpoint after which id property is given.
|
|
1005
|
-
*
|
|
1006
|
-
* API Docs: https://api.depict.ai/docs
|
|
1007
|
-
*
|
|
1008
|
-
* Formerly called get_displays
|
|
1009
|
-
*/
|
|
1010
|
-
export function fetch_recs<T extends Display = Display>(t: Tenant | {
|
|
1011
|
-
market: string;
|
|
1012
|
-
tenant: string;
|
|
1013
|
-
}, options: FetchRecsOptions, headers?: HeadersInit, get_url?: typeof default_get_fetch_url): Promise<T[]>;
|
|
1014
|
-
export function fetch_recs_whole_response<R extends {
|
|
1015
|
-
displays: any[];
|
|
1016
|
-
}>(t: Tenant | {
|
|
1017
|
-
market: string;
|
|
1018
|
-
tenant: string;
|
|
1019
|
-
}, options: FetchRecsOptions, headers?: HeadersInit, get_url?: typeof default_get_fetch_url): Promise<R>;
|
|
1020
|
-
declare function default_get_fetch_url(type: PossibleEndpoint): string;
|
|
1021
|
-
export function ensure_parameter_in_url(url: any, param: any, value: any): string;
|
|
1022
|
-
export function querySelectorUpwards(element: Element | HTMLElement, selector: string): Element | null;
|
|
1023
|
-
export function html2elems(html: string): NodeListOf<ChildNode>;
|
|
1024
|
-
export function html2elem(html: string): Element | null;
|
|
1025
|
-
/** On demo domain: make all urls relative */
|
|
1026
|
-
export function relativify(url: string | RegExp, also_onchange?: boolean, override_dev_url?: string, stfu?: boolean, also_in_all_shadow_roots?: boolean): void;
|
|
1027
|
-
export function querySelectorAllElements<T extends Element>(elements: Node_Iterable, selector: string): T[];
|
|
1028
|
-
export function standard_price_format(price: number, places_after_comma?: number | "auto", decimal_delimiter?: string, thousands_delimiter?: string): string;
|
|
1029
|
-
export function intl_number_format_with_fallback(bcp47_country_code: string, number: number, numberformat_options?: Parameters<typeof Intl.NumberFormat>[1]): string;
|
|
1030
|
-
export function ensure_object_path(obj: object, step1: string, ...path: string[]): any;
|
|
1031
|
-
export function Rec_Renderer<T extends Display>(t: Tenant | null, rendering_options: RR_Options<T>): Promise<RecRendererResult<T>>;
|
|
1032
|
-
export function regex_templating(template: string, display?: Display | {
|
|
1033
|
-
[key: string]: any;
|
|
1034
|
-
}): string;
|
|
1035
|
-
export function clone_deep<T>(obj: T): T;
|
|
1036
|
-
export class InfoForProcessing<T extends Display> {
|
|
1037
|
-
constructor(t: Tenant | null, rendering_options: RR_Options<T>, displays: T[], index?: number, remove_display?: () => void, event_listeners?: [type: keyof HTMLElementEventMap, listener: (this: HTMLElement, ev: HTMLElementEventMap[keyof HTMLElementEventMap]) => any, options?: boolean | AddEventListenerOptions][]);
|
|
1038
|
-
}
|
|
1039
|
-
type RegisterEventListener = (type: keyof HTMLElementEventMap, listener: (this: HTMLElement, ev: HTMLElementEventMap[keyof HTMLElementEventMap]) => any, options?: boolean | AddEventListenerOptions) => void;
|
|
1040
|
-
export interface InfoForProcessing<T extends Display> {
|
|
1041
|
-
t: Tenant;
|
|
1042
|
-
rendering_options: RR_Options<T>;
|
|
1043
|
-
displays: T[];
|
|
1044
|
-
index: number;
|
|
1045
|
-
remove_display?: () => void;
|
|
1046
|
-
register_event_listener: RegisterEventListener;
|
|
1047
|
-
event_listeners?: [type: keyof HTMLElementEventMap, listener: (this: HTMLElement, ev: HTMLElementEventMap[keyof HTMLElementEventMap]) => any, options?: boolean | AddEventListenerOptions][];
|
|
1048
|
-
extras?: {
|
|
1049
|
-
[key: string]: any;
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
export type RR_PreProcessor<T extends Display> = (display: T, info: InfoForProcessing<T>) => Promise<T> | T;
|
|
1053
|
-
export type RR_PostProcessor<T extends Display> = (elements: NodeListOf<ChildNode> | Node_Array, display: T, info: InfoForProcessing<T>) => Promise<NodeListOf<ChildNode> | Node_Array> | NodeListOf<ChildNode> | Node_Array;
|
|
1054
|
-
export type RR_Options<T extends Display> = {
|
|
1055
|
-
template: string | ((arg0: T, info: InfoForProcessing<T>) => Promise<string | Node_Array> | string | Node_Array);
|
|
1056
|
-
recs?: T[] | undefined | Promise<T[] | undefined>;
|
|
1057
|
-
type: string;
|
|
1058
|
-
min_items_to_report?: number;
|
|
1059
|
-
min_items_to_run?: number;
|
|
1060
|
-
max_items?: number;
|
|
1061
|
-
extra_api_options?: {
|
|
1062
|
-
[key: string]: any;
|
|
1063
|
-
};
|
|
1064
|
-
pre_processors?: RR_PreProcessor<T>[];
|
|
1065
|
-
post_processors?: RR_PostProcessor<T>[];
|
|
1066
|
-
headers?: HeadersInit;
|
|
1067
|
-
} & FetchRecsOptions;
|
|
332
|
+
export function get_cookie(cookie_name: string): string | undefined;
|
|
1068
333
|
/**
|
|
1069
334
|
* Product properties that are used to render the product cards. Used until early 2023
|
|
1070
335
|
*/
|
|
@@ -1169,77 +434,6 @@ export const check_displays: (args_0: {
|
|
|
1169
434
|
* @deprecated You should no longer need to use this. Use observer.onexists to add an event listener to an element once it exists.
|
|
1170
435
|
*/
|
|
1171
436
|
export function require_event_listener(element: Node, event: string, track_id: any, func: EventListenerOrEventListenerObject): void;
|
|
1172
|
-
export const default_view_tracking: (RR_PostProcessor<any> | typeof depict_page_view)[];
|
|
1173
|
-
export const default_click_tracking: (typeof depict_click_tracking_post_processor | typeof add_new_tab_listener)[];
|
|
1174
|
-
export function recs_inserted_tracking<T extends Display>(elements: NodeListOf<ChildNode> | Node_Array, _display: Display, info: InfoForProcessing<T>): NodeListOf<ChildNode> | Node_Array;
|
|
1175
|
-
export function gtag_view_post_processor<T extends Display>(elements: NodeListOf<ChildNode> | Node_Array, _display: Display, info: InfoForProcessing<T>): NodeListOf<ChildNode> | Node_Array;
|
|
1176
|
-
export function depict_page_view<T extends Display>(elements: NodeListOf<ChildNode> | Node_Array, _display: Display, info: InfoForProcessing<T>): NodeListOf<ChildNode> | Node_Array;
|
|
1177
|
-
export function gtag_click_post_processor<T extends Display>(elements: NodeListOf<ChildNode> | Node_Array, display: Display, info: InfoForProcessing<T>): NodeListOf<ChildNode> | Node_Array;
|
|
1178
|
-
export function depict_click_tracking_post_processor<T extends Display>(elements: NodeListOf<ChildNode> | Node_Array, display: Display, info: InfoForProcessing<T>): NodeListOf<ChildNode> | Node_Array;
|
|
1179
|
-
export function add_to_localstorage<T extends Display>(elements: NodeListOf<ChildNode> | Node_Array, display: Display, info: InfoForProcessing<T>): NodeListOf<ChildNode> | Node_Array;
|
|
1180
|
-
export function ga_click<T extends Display>(elements: NodeListOf<ChildNode> | Node_Array, display: Display, info: InfoForProcessing<T>): NodeListOf<ChildNode> | Node_Array;
|
|
1181
|
-
export const should_colorizeLogics: boolean;
|
|
1182
|
-
export function colorize_elements(elements: NodeListOf<ChildNode> | Node_Array, display: Display): NodeListOf<ChildNode> | Node_Array;
|
|
1183
|
-
type Extended_RR_Options<T extends Display> = {
|
|
1184
|
-
view_tracking?: RR_PostProcessor<T>[];
|
|
1185
|
-
click_tracking?: RR_PostProcessor<T>[];
|
|
1186
|
-
} & RR_Options<T>;
|
|
1187
|
-
export function default_rr<T extends Display>(t: Tenant | null, rendering_options: Extended_RR_Options<T>): Promise<RecRendererResult<T>>;
|
|
1188
|
-
type GWVM_Options = {
|
|
1189
|
-
container_selector?: string;
|
|
1190
|
-
start_rows?: number;
|
|
1191
|
-
rows_per_click?: number;
|
|
1192
|
-
recs_per_row?: number | ((showing: number) => number);
|
|
1193
|
-
button?: string | HTMLElement;
|
|
1194
|
-
override_rec_renderer?: typeof Rec_Renderer;
|
|
1195
|
-
title_selector?: string;
|
|
1196
|
-
title?: string | HTMLElement;
|
|
1197
|
-
container_template: string | Node_Array;
|
|
1198
|
-
only_full_rows?: boolean;
|
|
1199
|
-
should_preload?: boolean;
|
|
1200
|
-
};
|
|
1201
|
-
interface GWVM_InfoForProcessing<T extends Display> extends InfoForProcessing<T> {
|
|
1202
|
-
extras: {
|
|
1203
|
-
[key: string]: any;
|
|
1204
|
-
load_more_currently_showing: number;
|
|
1205
|
-
load_more: (num?: number | Event) => void;
|
|
1206
|
-
load_more_ipo: {
|
|
1207
|
-
promise: Promise<number>;
|
|
1208
|
-
resolve: (argument?: number) => void;
|
|
1209
|
-
};
|
|
1210
|
-
};
|
|
1211
|
-
}
|
|
1212
|
-
type GWVM_RR_Post_Pro = (elements: NodeListOf<ChildNode> | Node_Array, display: Display, info: GWVM_InfoForProcessing) => Promise<NodeListOf<ChildNode> | Node_Array> | NodeListOf<ChildNode> | Node_Array;
|
|
1213
|
-
type GWVM_RR_Options = Extended_RR_Options & {
|
|
1214
|
-
post_processors?: GWVM_RR_Post_Pro[];
|
|
1215
|
-
};
|
|
1216
|
-
/**
|
|
1217
|
-
* @deprecated please use RecommendationGrid instead
|
|
1218
|
-
*/
|
|
1219
|
-
export function GWVM_Renderer(t: Tenant, options: GWVM_RR_Options, GWVM_opts: GWVM_Options): Promise<{
|
|
1220
|
-
elements?: ChildNode[] | undefined;
|
|
1221
|
-
load_more?: ((num?: number | Event) => void) | undefined;
|
|
1222
|
-
displays?: Display[] | undefined;
|
|
1223
|
-
}>;
|
|
1224
|
-
/**
|
|
1225
|
-
* Used auto generate recommendations with view more button.
|
|
1226
|
-
* @param t The tenant used for recommendations
|
|
1227
|
-
* @param options Rendering options for recommendations such as total number of recommendations and template.
|
|
1228
|
-
* `GWVM_RR_Options` extends the same typing used for options in `default_rr and` `recommendation-renderer`
|
|
1229
|
-
* @param GWVM_opts Grid options, starting row, rows per view more click, container templates
|
|
1230
|
-
* @param rec_selector The selector used to find the rendered recs (by recommendation renderer
|
|
1231
|
-
* for which the first options object was used) for the width calculation. Default: ".rec_outer".
|
|
1232
|
-
* @deprecated please use RecommendationGrid instead
|
|
1233
|
-
*/
|
|
1234
|
-
export function Auto_GWVM(t: Tenant, options: GWVM_RR_Options, GWVM_opts: Omit<GWVM_Options, "recs_per_row">, {
|
|
1235
|
-
rec_selector
|
|
1236
|
-
}?: {
|
|
1237
|
-
rec_selector?: string;
|
|
1238
|
-
}): Promise<{
|
|
1239
|
-
elements?: Node_Array | undefined;
|
|
1240
|
-
load_more?: ((num?: number | Event) => void) | undefined;
|
|
1241
|
-
displays?: Display[] | undefined;
|
|
1242
|
-
}>;
|
|
1243
437
|
/**
|
|
1244
438
|
* @deprecated use async_iterable_ipns instead. This can skip values which yields unexpected results.
|
|
1245
439
|
*/
|
|
@@ -1248,23 +442,6 @@ export function infinite_promise_creator(): {
|
|
|
1248
442
|
internal_resolve: ((value: any) => void) | undefined;
|
|
1249
443
|
resolve: (argument?: any) => void;
|
|
1250
444
|
};
|
|
1251
|
-
interface trimmed_GWVM_opts extends Omit<GWVM_Options, "start_rows" | "rows_per_click" | "recs_per_row"> {}
|
|
1252
|
-
/**
|
|
1253
|
-
* @deprecated please rewrite this, basing on RecommendationGrid and its `rows.ipns` option, next time you need infinite scroll
|
|
1254
|
-
*/
|
|
1255
|
-
export function infinite_renderer(t: Tenant, options: GWVM_RR_Options, GWVM_opts: trimmed_GWVM_opts, {
|
|
1256
|
-
rec_selector
|
|
1257
|
-
}?: {
|
|
1258
|
-
rec_selector?: string;
|
|
1259
|
-
}): Promise<{
|
|
1260
|
-
elements?: Node_Array | undefined;
|
|
1261
|
-
load_more?: ((num?: number | Event | undefined) => void) | undefined;
|
|
1262
|
-
displays?: Display[] | undefined;
|
|
1263
|
-
}>;
|
|
1264
|
-
/**
|
|
1265
|
-
* @deprecated Emil's utility in integration.ts is better because it doesn't cause multiply <style> tags and doesn't require a tenant class
|
|
1266
|
-
*/
|
|
1267
|
-
export function deprecated_insert_styling(t: Tenant, css: string, extra_html?: string): Promise<void>;
|
|
1268
445
|
/**
|
|
1269
446
|
* @deprecated This is a predecessor to reactive_template which is much more limited (can only have two states) plus it's much more cumbersome to use, which is why I'm deprecating it.
|
|
1270
447
|
*/
|
|
@@ -1272,6 +449,118 @@ export function placeholder(...args: Parameters<typeof placeholder_worker>): acc
|
|
|
1272
449
|
type accepted_element_types = Node_Array[0] | Node_Array;
|
|
1273
450
|
type accepted_input_that_resolves_to_elements = accepted_element_types | Promise<accepted_element_types> | (() => accepted_element_types) | (() => Promise<accepted_element_types>);
|
|
1274
451
|
declare function placeholder_worker(placeholder_elements: accepted_input_that_resolves_to_elements, final_elements: accepted_input_that_resolves_to_elements, switching_trigger?: infinite_promise_no_skip<boolean> | Promise<boolean>): Promise<void>;
|
|
452
|
+
export class ElementObserverEvent<ElemType extends CallbackableNode = HTMLElement, SelectorType extends string | CallbackableNode = string | CallbackableNode> {
|
|
453
|
+
constructor(opts: {
|
|
454
|
+
element_: ElemType;
|
|
455
|
+
selector_: SelectorType;
|
|
456
|
+
disconnector_: Disconnector;
|
|
457
|
+
mutation_record_?: MutationRecord;
|
|
458
|
+
event_?: ListenerNames;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
export interface ElementObserverEvent<ElemType extends CallbackableNode = HTMLElement, SelectorType extends string | CallbackableNode = string | CallbackableNode> {
|
|
462
|
+
element: ElemType;
|
|
463
|
+
selector: SelectorType;
|
|
464
|
+
disconnector: Disconnector;
|
|
465
|
+
mutation_record?: MutationRecord;
|
|
466
|
+
event?: ListenerNames;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Element.querySelectorAll is broken in Chrome 37-latest, use this instead.
|
|
470
|
+
* Related bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1286047
|
|
471
|
+
* @param element Quite broadly anything you'd normaly call querySelectorAll on, including "null"
|
|
472
|
+
* @param selector The selector to search for
|
|
473
|
+
* @return Stock return value
|
|
474
|
+
*/
|
|
475
|
+
export function patched_querySelectorAll<T extends Element>(element: Element | Document | DocumentFragment | null, selector: string): NodeListOf<T> | T[] | undefined;
|
|
476
|
+
export interface ElementObserver {
|
|
477
|
+
/**
|
|
478
|
+
* Immediately calls the callback with an ElementObserverEvent for nodes existing in the DOM that match the provided selector OR are the selector,
|
|
479
|
+
* also calls the callback with an ElementObserverEvent whenever ANYTHING in the DOM occurs that makes an element match the provided selector.
|
|
480
|
+
* @param selector Selector string or element to listen for
|
|
481
|
+
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
482
|
+
*/
|
|
483
|
+
onexists: EO_listener_also_taking_els;
|
|
484
|
+
/**
|
|
485
|
+
* Dispatches an ElementObserverEvent whenever a node is added to the DOM that matches the specified selector OR is the selector.
|
|
486
|
+
* @param selector CSS selector or element to observe
|
|
487
|
+
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
488
|
+
**/
|
|
489
|
+
oncreation: EO_listener_also_taking_els;
|
|
490
|
+
/**
|
|
491
|
+
* Dispatches an ElementObserverEvent whenever a node is removed from the DOM that matches the specified selector OR is the selector.
|
|
492
|
+
* @param selector CSS selector or element to observe
|
|
493
|
+
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
494
|
+
*/
|
|
495
|
+
onremoved: EO_listener_also_taking_els;
|
|
496
|
+
/**
|
|
497
|
+
* Dispatches an ElementObserverEvent whenever a node that matches the specified selector or its children change in the DOM.
|
|
498
|
+
* @param selector CSS selector or element to observe
|
|
499
|
+
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
500
|
+
*/
|
|
501
|
+
onchange: EO_listener;
|
|
502
|
+
/**
|
|
503
|
+
* Immediately calls the callback with an ElementObserverEvent on nodes that match the provided selector OR are the selector.
|
|
504
|
+
* @param selector Selector string or element to look for in the DOM
|
|
505
|
+
* @param callback Function that will be called with the ElementObserverEvent. Exceptions and promise rejections of the callback will be caught and sent to sentry.
|
|
506
|
+
*/
|
|
507
|
+
ifexists: EO_listener_also_taking_els;
|
|
508
|
+
/**
|
|
509
|
+
* Adds a territory to the observer. The observer will observe all elements in the new territory and the one it observed before. `ifexists` checks made in the past won't be made again. Add your shadow roots here on creation and `observer` will finds elements in them.
|
|
510
|
+
*/
|
|
511
|
+
add_territory: (what: HTMLElement | Document | DocumentFragment) => void;
|
|
512
|
+
/**
|
|
513
|
+
* Removes a territory again. Useful for no longer observing shadow roots.
|
|
514
|
+
*/
|
|
515
|
+
remove_territory: (what: HTMLElement | Document | DocumentFragment) => void;
|
|
516
|
+
/**
|
|
517
|
+
* See docs for observer.onexists. Will return a Promise that resolves to the element out of the first call of an observer.onexists callback.
|
|
518
|
+
* @param selector Selector string or element to wait for
|
|
519
|
+
* @param timeout timeout to stop listening and resolve the Promise with `undefined`
|
|
520
|
+
*/
|
|
521
|
+
wait_for_element: <ElemType extends HTMLElement = HTMLElement>(selector: string | ElemType, timeout?: number) => Promise<ElemType>;
|
|
522
|
+
/**
|
|
523
|
+
* See docs for observer.on<listener>. Will return a Promise that resolves to the first element that matches the given listener and selector. I.e. `wait_for_listener("removed", ".old-recs");` will resolve to the first element matching `.old-recs` that is removed from the DOM
|
|
524
|
+
* @param listener one of the possible functions on ElementObserver that start with "on", without the "on". So "creation", "change", "exists" or "removed"
|
|
525
|
+
* @param selector String containing CSS selector
|
|
526
|
+
* @param timeout timeout to stop listening and resolve the Promise with `undefined`
|
|
527
|
+
*/
|
|
528
|
+
wait_for_listener: <ElemType extends HTMLElement = HTMLElement, SelectorType = string | CallbackableNode>(listener: SelectorType extends CallbackableNode ? "creation" | "removed" : "exists" | "creation" | "removed" | "change", selector: SelectorType, timeout?: number) => Promise<ElemType>;
|
|
529
|
+
}
|
|
530
|
+
export class ElementObserver {
|
|
531
|
+
#private;
|
|
532
|
+
constructor({
|
|
533
|
+
territory
|
|
534
|
+
}?: {
|
|
535
|
+
territory?: HTMLElement | Document | DocumentFragment | (HTMLElement | Document | DocumentFragment)[];
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
type EO_listener = <ElemType extends HTMLElement = HTMLElement>(selector: string, callback: ObserverCallbackFunction<ElemType>) => Disconnector;
|
|
539
|
+
type EO_listener_also_taking_els = <ElemType extends CallbackableNode = HTMLElement, SelectorType extends string | CallbackableNode = string | CallbackableNode>(selector: SelectorType, callback: ObserverCallbackFunction<ElemType, SelectorType>) => Disconnector;
|
|
540
|
+
type ListenerNames = "exists" | "creation" | "removed" | "change";
|
|
541
|
+
type ObserverCallbackFunction<ElemType extends CallbackableNode, SelectorType extends string | CallbackableNode = string | CallbackableNode> = (event: ElementObserverEvent<ElemType, SelectorType>) => any;
|
|
542
|
+
export type Disconnector = () => unknown;
|
|
543
|
+
type CallbackableNode = Element | Text | Comment;
|
|
544
|
+
/**
|
|
545
|
+
* Epic alien tech that categorizes DOM mutations, allowing one to listen and quickly (+2 ticks in the microtask queue, all before paint) react to DOM mutations such as elements (matching a selector) being added, deleted or changed.
|
|
546
|
+
*/
|
|
547
|
+
export const observer: ElementObserver;
|
|
548
|
+
/**
|
|
549
|
+
* Useful for the `thresholds` option of IntersectionObserver - if you want to be notified at a 10% change, call this and set num_steps to 10. Pls see https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/thresholds
|
|
550
|
+
* @param numSteps How many steps (notifications) there should be between 0 and 100% intersection
|
|
551
|
+
* @return Stuff to give to IntersectionObserver
|
|
552
|
+
*/
|
|
553
|
+
export function buildThresholdList(numSteps: number): number[];
|
|
554
|
+
export function ensure_parameter_in_url(url: any, param: any, value: any): string;
|
|
555
|
+
export function querySelectorUpwards(element: Element | HTMLElement, selector: string): Element | null;
|
|
556
|
+
export function html2elems(html: string): NodeListOf<ChildNode>;
|
|
557
|
+
export function html2elem(html: string): Element | null;
|
|
558
|
+
/** On demo domain: make all urls relative */
|
|
559
|
+
export function relativify(url: string | RegExp, also_onchange?: boolean, override_dev_url?: string, stfu?: boolean, also_in_all_shadow_roots?: boolean): void;
|
|
560
|
+
export function querySelectorAllElements<T extends Element>(elements: Node_Iterable, selector: string): T[];
|
|
561
|
+
export function standard_price_format(price: number, places_after_comma?: number | "auto", decimal_delimiter?: string, thousands_delimiter?: string): string;
|
|
562
|
+
export function intl_number_format_with_fallback(bcp47_country_code: string, number: number, numberformat_options?: Parameters<typeof Intl.NumberFormat>[1]): string;
|
|
563
|
+
export function ensure_object_path(obj: object, step1: string, ...path: string[]): any;
|
|
1275
564
|
declare global {
|
|
1276
565
|
interface HTMLImageElementWithLoaded extends HTMLImageElement {
|
|
1277
566
|
loaded?: boolean;
|
|
@@ -1281,7 +570,7 @@ declare global {
|
|
|
1281
570
|
}
|
|
1282
571
|
}
|
|
1283
572
|
export interface Lazyfier {
|
|
1284
|
-
t:
|
|
573
|
+
t: {};
|
|
1285
574
|
container: HTMLElement;
|
|
1286
575
|
selector: string;
|
|
1287
576
|
lazyfinder: lazyfinder;
|
|
@@ -1394,77 +683,18 @@ export class Amazing_Slider {
|
|
|
1394
683
|
autoinvalidate_cache
|
|
1395
684
|
}: Slider_Options);
|
|
1396
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* Make parts of a type optional
|
|
688
|
+
*
|
|
689
|
+
* From: https://github.com/Microsoft/TypeScript/issues/25760#issuecomment-614417742
|
|
690
|
+
*/
|
|
691
|
+
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
1397
692
|
export interface Amazing_Lazy_Slider {
|
|
1398
693
|
lazyfier: Lazyfier;
|
|
1399
694
|
}
|
|
1400
695
|
export class Amazing_Lazy_Slider extends Amazing_Slider {
|
|
1401
696
|
constructor(options: Slider_Options, lazyfier_options?: Optional<ConstructorParameters<typeof Lazyfier>[0], "container">);
|
|
1402
697
|
}
|
|
1403
|
-
interface Pro_Slider_Options {
|
|
1404
|
-
container?: string | Node_Iterable;
|
|
1405
|
-
root_selector?: string;
|
|
1406
|
-
override_rec_renderer?: typeof Rec_Renderer;
|
|
1407
|
-
insertion_verb?: "append" | "prepend" | "before" | "after" | "replaceWith";
|
|
1408
|
-
lazyfier_options?: ConstructorParameters<typeof Amazing_Lazy_Slider>[1];
|
|
1409
|
-
}
|
|
1410
|
-
/**
|
|
1411
|
-
* @deprecated please use RecommendationSlider instead
|
|
1412
|
-
*/
|
|
1413
|
-
export function Pro_Slider<T extends Display>(t: Tenant, rendering_options: Extended_RR_Options<T>, options_for_us?: Pro_Slider_Options, slider_options?: Slider_Options): ReturnType<typeof Rec_Renderer<T>>;
|
|
1414
|
-
/**
|
|
1415
|
-
* @deprecated Please use recommendation renderer instead
|
|
1416
|
-
*/
|
|
1417
|
-
export class Depict {
|
|
1418
|
-
#private;
|
|
1419
|
-
settings: any;
|
|
1420
|
-
data: any;
|
|
1421
|
-
tracker: void;
|
|
1422
|
-
constructor(settings: any);
|
|
1423
|
-
init(callback: Function, existingDisplays?: object[]): void;
|
|
1424
|
-
loadRecommendations(callback: any): void;
|
|
1425
|
-
trackGAEvent(action: any, index: any, product_id: any, ga_product_ids?: string[]): void;
|
|
1426
|
-
trackPageView(): void;
|
|
1427
|
-
trackClick(index: any): boolean | Promise<void | undefined> | undefined;
|
|
1428
|
-
trackAddToCart(pId: any): boolean | Promise<void | undefined> | undefined;
|
|
1429
|
-
createContainer(root: any, container: any, prepend?: boolean): void;
|
|
1430
|
-
renderTemplate({
|
|
1431
|
-
prep,
|
|
1432
|
-
root,
|
|
1433
|
-
template,
|
|
1434
|
-
itemPreprocessor,
|
|
1435
|
-
itemPostprocessor
|
|
1436
|
-
}?: any): void;
|
|
1437
|
-
}
|
|
1438
|
-
declare global {
|
|
1439
|
-
interface Document {
|
|
1440
|
-
_depict_modify: boolean | undefined;
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
interface TemplateToolOptions {
|
|
1444
|
-
max_items?: number;
|
|
1445
|
-
min_items?: number;
|
|
1446
|
-
DNT?: boolean;
|
|
1447
|
-
debug?: boolean;
|
|
1448
|
-
type?: string;
|
|
1449
|
-
product_id?: Function | ((url?: string) => string);
|
|
1450
|
-
sendGa?: boolean;
|
|
1451
|
-
loadHack?: boolean;
|
|
1452
|
-
shade?: boolean;
|
|
1453
|
-
gaid?: string;
|
|
1454
|
-
tenant?: string;
|
|
1455
|
-
market?: string;
|
|
1456
|
-
}
|
|
1457
|
-
/**
|
|
1458
|
-
* @deprecated Please use RecommendationRenderer instead
|
|
1459
|
-
*/
|
|
1460
|
-
export const simplified_template_tool: (options: {
|
|
1461
|
-
options: TemplateToolOptions;
|
|
1462
|
-
recs?: object[] | undefined;
|
|
1463
|
-
root: Element;
|
|
1464
|
-
template: string;
|
|
1465
|
-
postProcessor?: Function | undefined;
|
|
1466
|
-
preProcessor?: Function | undefined;
|
|
1467
|
-
}) => Promise<Depict>;
|
|
1468
698
|
interface special_lazyfier_options extends Omit<Lazyfier_Options, "t"> {}
|
|
1469
699
|
interface Deprecated_Slider_Options {
|
|
1470
700
|
dlog?: Function;
|
|
@@ -1485,58 +715,13 @@ declare class Deprecated_Amazing_Slider extends Amazing_Lazy_Slider {
|
|
|
1485
715
|
constructor(static_options: Deprecated_Slider_Options, override_lazyfier_options?: special_lazyfier_options);
|
|
1486
716
|
}
|
|
1487
717
|
export function insert_styling_into_slider(slider: Deprecated_Amazing_Slider): void;
|
|
1488
|
-
interface RR_Slider_Options {
|
|
1489
|
-
container?: string | Node_Iterable;
|
|
1490
|
-
root_selector?: string;
|
|
1491
|
-
Rec_Renderer?: typeof Rec_Renderer;
|
|
1492
|
-
insertion_verb?: "append" | "prepend" | "before" | "after" | "replaceWith";
|
|
1493
|
-
}
|
|
1494
718
|
/**
|
|
1495
|
-
*
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
* @deprecated this uses template-tool-v1 which is long surpassed, please use RecommendationGrid or Pro_Slider (based on Recommendation-Renderer) instead
|
|
1502
|
-
*/
|
|
1503
|
-
export function get_recs_with_template({
|
|
1504
|
-
t,
|
|
1505
|
-
recs,
|
|
1506
|
-
title,
|
|
1507
|
-
infinite_scroll,
|
|
1508
|
-
with_slider,
|
|
1509
|
-
with_loadmore,
|
|
1510
|
-
template_tool_options,
|
|
1511
|
-
slider_options,
|
|
1512
|
-
pre_processors,
|
|
1513
|
-
post_processors,
|
|
1514
|
-
container_template,
|
|
1515
|
-
// container template
|
|
1516
|
-
template,
|
|
1517
|
-
// recommendation template
|
|
1518
|
-
chunk_size_for_load_more,
|
|
1519
|
-
insertion_promise,
|
|
1520
|
-
view_more_text
|
|
1521
|
-
}: {
|
|
1522
|
-
t: Tenant;
|
|
1523
|
-
recs?: any[];
|
|
1524
|
-
with_loadmore?: boolean;
|
|
1525
|
-
title?: string | Node[] | NodeList;
|
|
1526
|
-
infinite_scroll?: boolean;
|
|
1527
|
-
template_tool_options?: TemplateToolOptions;
|
|
1528
|
-
with_slider?: boolean;
|
|
1529
|
-
slider_options?: Deprecated_Slider_Options;
|
|
1530
|
-
pre_processors?: PreProcessor[];
|
|
1531
|
-
post_processors?: PostProcessor[];
|
|
1532
|
-
container_template: string;
|
|
1533
|
-
template: string;
|
|
1534
|
-
chunk_size_for_load_more?: number;
|
|
1535
|
-
insertion_promise?: Promise<void | unknown>;
|
|
1536
|
-
view_more_text?: string;
|
|
1537
|
-
}): Promise<ChildNode[] | void>;
|
|
1538
|
-
export function default_pre_processor(_t: any, d: any, i: number, with_loadmore: boolean, with_slider: boolean, infinite_scroll: boolean): any;
|
|
1539
|
-
export function default_post_processor(_t: any, itms: HTMLCollection, d: any, slider: Deprecated_Amazing_Slider | null): HTMLCollection;
|
|
719
|
+
* A function that attempts to "serialize" an object to a text representation that helps with debugging when using sentry
|
|
720
|
+
* @param anything Something to try to serialize - this function is crappy and your mileage may vary
|
|
721
|
+
* @param depth How deep to go when recursing
|
|
722
|
+
* @return An object that is somehow closer to text (better serializable by sentry) or text
|
|
723
|
+
*/
|
|
724
|
+
export function serialize_object(anything: Object, depth?: number): Object;
|
|
1540
725
|
/**
|
|
1541
726
|
* @deprecated please use `fetch_retry()` instead
|
|
1542
727
|
*
|
|
@@ -1581,6 +766,8 @@ export const expandingContainer: ({
|
|
|
1581
766
|
content: HTMLDivElement;
|
|
1582
767
|
container: HTMLDivElement;
|
|
1583
768
|
};
|
|
769
|
+
export const should_colorizeLogics: boolean;
|
|
770
|
+
export function colorize_elements(elements: NodeListOf<ChildNode> | Node_Array, display: Display): NodeListOf<ChildNode> | Node_Array;
|
|
1584
771
|
/**
|
|
1585
772
|
* Like Promise.any but for async iterable infinite promises (object that have `.state` and a [Symbol.asyncIterator]). Returns an array of all current values when one value udpates.
|
|
1586
773
|
* @param iterables Array of IPNS
|
|
@@ -1651,84 +838,6 @@ export function layout_get_visible_recs_without_partial_rows(rows: number, max_r
|
|
|
1651
838
|
* @return String of generated CSS
|
|
1652
839
|
*/
|
|
1653
840
|
export function n_col_styling_with_dist(selector_beginning: string, default_grid_spacing_text: string, cols_at_size: ColsAtSize, layout: "slider" | "grid", override_vertical_spacing?: string, only_generate_top_margins?: number): string;
|
|
1654
|
-
export interface RecommendationGridOptions<T extends Display> extends Omit<LayoutOptions, "container_element" | "layout"> {
|
|
1655
|
-
container_elements: Node_Array;
|
|
1656
|
-
container_selector?: string;
|
|
1657
|
-
override_rec_renderer?: typeof default_rr<T>;
|
|
1658
|
-
lazyfier_options?: Omit<Lazyfier_Options, "t">;
|
|
1659
|
-
eager_images?: boolean;
|
|
1660
|
-
}
|
|
1661
|
-
/**
|
|
1662
|
-
* RecommendationGrid: Searches your container_elements for ".grid" or `container_selector`, runs default_rr or `override_rec_renderer` and puts the recs into the found element. Then runs `Grid` on it.
|
|
1663
|
-
* @param t Instance of Tenant
|
|
1664
|
-
* @param recommendation_renderer_options Options for default_rr or override_rec_renderer
|
|
1665
|
-
* @param container_elements The elements from your container template.
|
|
1666
|
-
* @param container_selector Selector for finding the element in container_elements that should be the recommendations' immediate parents. A.k.a the selector for the "insertion point"
|
|
1667
|
-
* @param override_rec_renderer Other recommendation renderer to use apart from default_rr (i.e. placeholder_rr)
|
|
1668
|
-
* @param lazyfier_options Options for Lazyfier which does lazyloading of the images. Optional. Keys with the same name as the options passed by RecommendationGrid will override them.
|
|
1669
|
-
* @param eager_images Don't lazyload images
|
|
1670
|
-
* @param ...options_for_grid Options for Grid. See documentation of Grid.
|
|
1671
|
-
* @constructor
|
|
1672
|
-
*/
|
|
1673
|
-
export function RecommendationGrid<T extends Display>(t: Tenant | null, recommendation_renderer_options: Extended_RR_Options<T>, {
|
|
1674
|
-
container_elements,
|
|
1675
|
-
container_selector,
|
|
1676
|
-
override_rec_renderer,
|
|
1677
|
-
lazyfier_options,
|
|
1678
|
-
eager_images,
|
|
1679
|
-
...options_for_grid
|
|
1680
|
-
}: RecommendationGridOptions<T>): Promise<RecRendererResult<T>>;
|
|
1681
|
-
export interface EasySliderOptions<T extends Display> extends Omit<LayoutOptions, "container_element" | "rows" | "layout"> {
|
|
1682
|
-
rows?: {
|
|
1683
|
-
start_rows?: number;
|
|
1684
|
-
ipns?: IPNS<number>;
|
|
1685
|
-
} | "all";
|
|
1686
|
-
container_elements: Node_Array;
|
|
1687
|
-
container_selector?: string;
|
|
1688
|
-
override_rec_renderer?: typeof default_rr<T>;
|
|
1689
|
-
lazyfier_options?: Omit<Lazyfier_Options, "t">;
|
|
1690
|
-
eager_images?: boolean;
|
|
1691
|
-
dist_to_hide_left?: number;
|
|
1692
|
-
dist_to_hide_right?: number;
|
|
1693
|
-
stepstoslide?: number;
|
|
1694
|
-
center_target?: boolean;
|
|
1695
|
-
constructor_plugins?: ((arg0: Slider_Options) => any)[];
|
|
1696
|
-
mutation_plugins?: ((mutations: IntersectionObserverEntry[], intersecting_items: Record<number, IntersectionObserverEntry>) => any)[];
|
|
1697
|
-
button_contents?: {
|
|
1698
|
-
right: Node_Iterable;
|
|
1699
|
-
left: Node_Iterable;
|
|
1700
|
-
};
|
|
1701
|
-
button_elems?: {
|
|
1702
|
-
right: HTMLElement;
|
|
1703
|
-
left: HTMLElement;
|
|
1704
|
-
};
|
|
1705
|
-
override_vertical_spacing?: string;
|
|
1706
|
-
}
|
|
1707
|
-
export type RecommendationSliderSurface<T extends Display> = Record<string, never> | {
|
|
1708
|
-
elements: Node_Array;
|
|
1709
|
-
slider: Amazing_Slider | Amazing_Lazy_Slider;
|
|
1710
|
-
displays: T[];
|
|
1711
|
-
};
|
|
1712
|
-
/**
|
|
1713
|
-
*
|
|
1714
|
-
* The most epic RecommendationSlider todate
|
|
1715
|
-
* @param t Instance of tenant class
|
|
1716
|
-
* @param recommendation_renderer_options Options for Recommendation Renderer
|
|
1717
|
-
* @param RecommendationGrid_options Similar options object to RecommendationGrid except that it also contains options to Amazing_Slider
|
|
1718
|
-
* @return a Surface (object) that contains displays, elements and the instance of the slider class (as `slider`)
|
|
1719
|
-
*/
|
|
1720
|
-
export function RecommendationSlider<T extends Display>(t: Tenant | null, recommendation_renderer_options: Extended_RR_Options<T>, {
|
|
1721
|
-
container_elements,
|
|
1722
|
-
container_selector,
|
|
1723
|
-
override_rec_renderer,
|
|
1724
|
-
lazyfier_options,
|
|
1725
|
-
eager_images,
|
|
1726
|
-
grid_spacing,
|
|
1727
|
-
cols_at_size,
|
|
1728
|
-
override_vertical_spacing,
|
|
1729
|
-
rows,
|
|
1730
|
-
...slider_options
|
|
1731
|
-
}: EasySliderOptions<T>): Promise<RecommendationSliderSurface<T> | RecRendererResult<T> | Surface<T>>;
|
|
1732
841
|
export function slider_autoscroll_factory(interval?: number): {
|
|
1733
842
|
constructor_plugin(this: Amazing_Slider): void;
|
|
1734
843
|
mutation_plugin: (this: Amazing_Slider, _intersections: IntersectionObserverEntry[], intersecting_mutations: Record<number, IntersectionObserverEntry>) => void;
|
|
@@ -1746,13 +855,11 @@ export function make_button2(): {
|
|
|
1746
855
|
right: HTMLImageElement[];
|
|
1747
856
|
};
|
|
1748
857
|
export function slider_dots_factory({
|
|
1749
|
-
t,
|
|
1750
858
|
navcont_insertion_fn,
|
|
1751
859
|
navdot,
|
|
1752
860
|
dontshowonedot,
|
|
1753
861
|
bitesize
|
|
1754
862
|
}: {
|
|
1755
|
-
t: Tenant;
|
|
1756
863
|
navcont_insertion_fn?: (slider: Amazing_Slider, navcont: HTMLDivElement) => any;
|
|
1757
864
|
navdot: (unique_name: number, index: number) => Element;
|
|
1758
865
|
dontshowonedot?: boolean;
|
|
@@ -1762,7 +869,7 @@ export function slider_dots_factory({
|
|
|
1762
869
|
mutation_plugin: (intersections: IntersectionObserverEntry[], intersecting_mutations: Record<number, IntersectionObserverEntry>) => void;
|
|
1763
870
|
};
|
|
1764
871
|
export function navdot(unique_name: string | number): HTMLLabelElement;
|
|
1765
|
-
export function slider_draggable_factory(
|
|
872
|
+
export function slider_draggable_factory(): {
|
|
1766
873
|
constructor_plugin: (slider_options: any) => void;
|
|
1767
874
|
mutation_plugin: (intersections: IntersectionObserverEntry[], intersecting_mutations: Record<number, IntersectionObserverEntry>) => void;
|
|
1768
875
|
post_pro_plugin: {
|
|
@@ -1823,17 +930,89 @@ export function slider_snapping_factory(options?: {
|
|
|
1823
930
|
constructor_plugin: (slider_options: any) => void | undefined;
|
|
1824
931
|
mutation_plugin: (intersections: IntersectionObserverEntry[], intersecting_mutations: Record<number, IntersectionObserverEntry>) => void | undefined;
|
|
1825
932
|
};
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
933
|
+
type after_navig_fn = (arg0: Parameters<typeof history.replaceState | typeof history.pushState>, what_happened: "replaceState" | "pushState") => any;
|
|
934
|
+
/**
|
|
935
|
+
* AsyncIterable which resolves with the new href every time location.href changes
|
|
936
|
+
*/
|
|
937
|
+
export const stateless_href_change_ipns: IPNS<string>;
|
|
938
|
+
/**
|
|
939
|
+
* AsyncIterable which resolves when you await it with the current href and then once every time it changes
|
|
940
|
+
*/
|
|
941
|
+
export const href_change_ipns: IPNS<string>;
|
|
942
|
+
/**
|
|
943
|
+
* Functions to instantly (synchronously) call when a "popstate" event occurs, before the href_change_ipns' resolve
|
|
944
|
+
* This kind of bypasses the IPNS' point, and I'm sorry for that inconsistency, but I'm working on a feature that's not in the roadmap and am encountering issues due to the 1 tick delay of the IPNS. IPNS were a mistake, I'm sorry for them.
|
|
945
|
+
*/
|
|
946
|
+
export const instant_exec_on_suspect_history_change: Set<(what_happened?: "replaceState" | "pushState" | "popstate", args?: PopStateEvent | Parameters<typeof history.replaceState> | Parameters<typeof history.pushState>) => void>;
|
|
947
|
+
export function on_next_navigation(callback: (new_href: string) => void): Promise<void>;
|
|
948
|
+
/**
|
|
949
|
+
* Proxies history.pushState, and, if the second argument is true, history.replaceState so that it executes the provided `after_navigation` function after the navigation (calling the original function) but before returning to what called it.
|
|
950
|
+
* Please also consider adding a listener to the `popstate` event (`window.addEventListener("popstate", handler)`) to cover ALL navigation possibilities.
|
|
951
|
+
* @param after_navigation Function to call after history.replaceState and history.pushState
|
|
952
|
+
* @param replace_replaceState=true Whether to call the function also on history.replaceState.
|
|
953
|
+
* @return Void
|
|
954
|
+
*/
|
|
955
|
+
export function history_replacer(after_navigation: after_navig_fn, replace_replaceState?: boolean): Promise<void>;
|
|
1835
956
|
export type ReactiveTemplateValueContents = string | number | Node_Array[number] | undefined | (string | number | Node_Array[number])[];
|
|
1836
957
|
export function reactive_template(initial_value?: ReactiveTemplateValueContents): readonly [Node_Array, () => ReactiveTemplateValueContents, (arg0: ReactiveTemplateValueContents) => void];
|
|
958
|
+
export const insert_styling: (css: string) => Promise<void | undefined>;
|
|
959
|
+
/**
|
|
960
|
+
* Basically a RecRendererResult with less strict typing
|
|
961
|
+
*/
|
|
962
|
+
export interface Surface<T extends Display> {
|
|
963
|
+
elements?: Node_Array;
|
|
964
|
+
displays?: T[];
|
|
965
|
+
should_stay_inserted?: Promise<boolean>;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Functions existing on ChildNode that are commonly used to insert recommendations into the DOM
|
|
969
|
+
*/
|
|
970
|
+
export type InsertionVerb = "after" | "before" | "replaceWith" | "append" | "prepend" | "replaceChildren";
|
|
971
|
+
/**
|
|
972
|
+
* Tries to extract a product id from an url.
|
|
973
|
+
* The method used to retrive product id used here is very narrow, probably better to use something else instead?
|
|
974
|
+
*
|
|
975
|
+
* @example normal_get_product_id("www.foo.com/bar/baz.html") // "baz"
|
|
976
|
+
*
|
|
977
|
+
* @param url The url to check, defaults to `window.location`
|
|
978
|
+
* @returns
|
|
979
|
+
*/
|
|
980
|
+
export const normal_get_product_id: (url?: string) => string;
|
|
981
|
+
declare global {
|
|
982
|
+
interface Document {
|
|
983
|
+
depictwashere: boolean;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* If you need custom market logic that {@link depict_init_with_market_logic} doesn't support then use this function.
|
|
988
|
+
*
|
|
989
|
+
* Used to initialize an integration-script, this should always be the entrypoint of an integration.
|
|
990
|
+
*
|
|
991
|
+
* Makes sure that your script doesn't run twice
|
|
992
|
+
*/
|
|
993
|
+
export const depict_init: (callback: () => Promise<void>) => void;
|
|
994
|
+
/**
|
|
995
|
+
* Initialize an integration-script like {@link depict_init}, but with automatic handling of unsupported and unknown markets.
|
|
996
|
+
*
|
|
997
|
+
* @param options.extract_market A function that extracts the current market, and if the market is supported, unsupported or unknown
|
|
998
|
+
* @param options.callback If `extract_market` returned a supported market, calls `depict_init` with this callback.
|
|
999
|
+
* @param options.supported_markets Markets where our script should run, in order to get the best typechecking you should add a `as const`
|
|
1000
|
+
* modifier to this type like so `["foo", "bar"] as const`.
|
|
1001
|
+
* @param options.unsupported_markets Markets we are aware of and where our script shouldn't run.
|
|
1002
|
+
* @param options.preferred_demo_market Market to use on .demo.depict.ai, if an override is needed for all users.
|
|
1003
|
+
* depict-override-market query parameter will override this behaviour.
|
|
1004
|
+
*
|
|
1005
|
+
* ### Behaviour
|
|
1006
|
+
*
|
|
1007
|
+
* - market is unsupported - log to console and exit
|
|
1008
|
+
* - market is unknown - report to sentry and exit
|
|
1009
|
+
*
|
|
1010
|
+
* ### Override market
|
|
1011
|
+
*
|
|
1012
|
+
* When running in debug mode the market can be overridden by setting a `depict-override-market` query param.
|
|
1013
|
+
* For example http://tenant.domain?depict-override-market=ez
|
|
1014
|
+
*/
|
|
1015
|
+
export function depict_init_with_market_logic<T extends readonly string[]>(callback: (market: T[number]) => Promise<void>, get_market: () => Promise<string | undefined> | string | undefined, supported_markets: T, unsupported_markets: string[], preferred_demo_market?: string): void;
|
|
1837
1016
|
/**
|
|
1838
1017
|
* A wrapper around window.matchMedia, basically cross browser compatibly adds an event listener to a media query that triggers when it changes
|
|
1839
1018
|
* @param query The media query (without `@media`)
|
|
@@ -1876,33 +1055,130 @@ export function sizes_to_surface(surface_per_size: [surface_index: number, min:
|
|
|
1876
1055
|
* Returns a promise that resolve the next time the href is changed
|
|
1877
1056
|
*/
|
|
1878
1057
|
export function promise_until_next_navigation(): Promise<string | undefined>;
|
|
1879
|
-
export function orderpage_transaction_id_extractor(t: Tenant, selector: string, filter?: (text: string) => string | undefined): void;
|
|
1880
1058
|
/**
|
|
1881
|
-
*
|
|
1882
|
-
*
|
|
1883
|
-
* @param
|
|
1884
|
-
* @param
|
|
1885
|
-
*
|
|
1059
|
+
* Adds an event listener to a given element (example: recommendation link) which adds the provided product_id and recommendation_id to the 'depict' localStorage object
|
|
1060
|
+
* @param {HTMLElement} a_element - The element to listen on the "click event"
|
|
1061
|
+
* @param {string} product_id - A unique identifier for the product which can be used to rerecognize it on the product page
|
|
1062
|
+
* @param {string} recommendation_id - The recommendation ID of the recommendation
|
|
1063
|
+
* @param {Function} additional_listener - An additional function to execute onclick
|
|
1064
|
+
*/
|
|
1065
|
+
export function bind_tracking_to_link(a_element: Element, product_id: string, recommendation_id: string, additional_listener?: Function): ((e: Event) => void) | undefined;
|
|
1066
|
+
export type A2CTrackingFunction = (product_id: string, recommendation_id: string, was_unmatching: boolean, event: Event) => any;
|
|
1067
|
+
/**
|
|
1068
|
+
* Adds an event listener to a given element (example: the purchase button) which calls `tracking_fn(product_id,recommendation_id)` if the product_id exists in the 'depict' localStorage object
|
|
1069
|
+
* @param {HTMLElement} button - The element to listen on the "click event"
|
|
1070
|
+
* @param {Function} get_product_id - A function to get the product_id of the current page/the product associated with the add to cart button
|
|
1071
|
+
* @param {A2CTrackingFunction} tracking_fn - A function which gets executed on click of button
|
|
1072
|
+
* @param {Boolean} [unmatching_tracking] - also call tracking_fn on products not found in localStorage.
|
|
1073
|
+
*/
|
|
1074
|
+
export function bind_to_a2c_button(button: Element, get_product_id: (url?: string, e?: Event) => string | Promise<string>, tracking_fn: A2CTrackingFunction, unmatching_tracking?: boolean, event?: string): Promise<void>;
|
|
1075
|
+
export function make_tracker_send_to_depict(ga_tracker: any, append_to_url?: string): void;
|
|
1076
|
+
export function create_ga_queue(): void;
|
|
1077
|
+
/**
|
|
1078
|
+
* A Post processor for Recommendation renderer to add impression tracking to all displays
|
|
1079
|
+
*/
|
|
1080
|
+
export const impression_tracking_post_processor: (items: any, display: any, info: any) => any;
|
|
1081
|
+
interface ImpressionTrackingOptions {
|
|
1082
|
+
/** The element to observe for impressions. */
|
|
1083
|
+
element: HTMLElement;
|
|
1084
|
+
/** The impression data to send to the api (this is combined with context data) */
|
|
1085
|
+
data: ExplicitImpressionEventData;
|
|
1086
|
+
/** When true the element will be observed by the IntersectionObserver only after it's inserted into the DOM.
|
|
1087
|
+
* Sometimes with a pollyfilled IntersectionObserver it ignores elements that are not in the DOM yet.
|
|
1088
|
+
* Defaults to true.
|
|
1089
|
+
* */
|
|
1090
|
+
wait_for_dom_insertion?: boolean;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Registers the passed element for impression tracking.
|
|
1094
|
+
* The element will be observed for intersection with the viewport.
|
|
1095
|
+
* Also handles sending the impression event.
|
|
1096
|
+
*
|
|
1097
|
+
* @return A function to stop observing the element for impressions
|
|
1098
|
+
*/
|
|
1099
|
+
export const impression_track_element: ({
|
|
1100
|
+
element,
|
|
1101
|
+
data,
|
|
1102
|
+
wait_for_dom_insertion
|
|
1103
|
+
}: ImpressionTrackingOptions) => () => void;
|
|
1104
|
+
/** The start and end visibility threshold for an intersection to count as an impression */
|
|
1105
|
+
export let impression_threshold: number[];
|
|
1106
|
+
export const set_impression_threshold: (start: number, end: number) => number[];
|
|
1107
|
+
/** The minimum duration the element has to be visible above the thresholds before it counts as an impression */
|
|
1108
|
+
export const has_to_be_intersecting_for = 500;
|
|
1109
|
+
/** What explicit information is needed to form an ImpressionEvent */
|
|
1110
|
+
export type ExplicitImpressionEventData = {
|
|
1111
|
+
recommendation_type?: string;
|
|
1112
|
+
entity_price?: number;
|
|
1113
|
+
market?: string;
|
|
1114
|
+
tenant?: string;
|
|
1115
|
+
product_id?: string;
|
|
1116
|
+
} & ({
|
|
1117
|
+
recommendation_id: string;
|
|
1118
|
+
} | {
|
|
1119
|
+
search_result_id: string;
|
|
1120
|
+
} | {
|
|
1121
|
+
product_listing_result_id: string;
|
|
1122
|
+
} | {
|
|
1123
|
+
suggestions_result_id: string;
|
|
1124
|
+
});
|
|
1125
|
+
/** What an impression event looks like when sent to the api */
|
|
1126
|
+
export type ImpressionEvent = {
|
|
1127
|
+
/** The type for impression events should be element_visible */
|
|
1128
|
+
type: "element_visible";
|
|
1129
|
+
} & (ExplicitImpressionEventData | TrackingEventContextData);
|
|
1130
|
+
/**
|
|
1131
|
+
* Sends an impression event to the api.
|
|
1132
|
+
*
|
|
1133
|
+
* Impression events always use websockets.
|
|
1134
|
+
*/
|
|
1135
|
+
export const send_impression_event: (data: Optional<ImpressionEvent, "type">) => void;
|
|
1136
|
+
export function Promise_Any<T>(promises: (T | PromiseLike<T>)[] | Iterable<T | PromiseLike<T>>): Promise<T>;
|
|
1137
|
+
/**
|
|
1138
|
+
* Broadcasts the product id of the current page to a BroadcastChannel `right_click_attribution`.
|
|
1139
|
+
* This enables a page in another tab where right-clicking on a recommendation yielded to the opening of this page to send click tracking events.
|
|
1140
|
+
*/
|
|
1141
|
+
export function broadcast_product_id(product_id: string): Promise<void>;
|
|
1142
|
+
/**
|
|
1143
|
+
* This function is a post processor for recommendation renderer which adds a "new tab listener" to the recommendations. That means that it will listen for right-and wheel clicks on the elements and if a tab opens (=broadcasts the product id) of the clicked product it emulates a click event (using contextmenu_callback)
|
|
1144
|
+
* @param elements Elements that event listeners will be added on
|
|
1145
|
+
* @param display The display to take the product_id from
|
|
1146
|
+
* @param info InfoForProcessing to get Tenant instance out of
|
|
1147
|
+
* @return `elements` 1:1
|
|
1886
1148
|
*/
|
|
1887
|
-
export function
|
|
1149
|
+
export function add_new_tab_listener(elements: NodeListOf<ChildNode> | Node_Array, display: Display, info?: any, get_event_listener_remover?: (remover: VoidFunction) => void): NodeListOf<ChildNode> | Node_Array;
|
|
1888
1150
|
/**
|
|
1889
|
-
*
|
|
1890
|
-
* @param
|
|
1151
|
+
* This is the event handler for the new tab tracking function (add_new_tab_listener)
|
|
1152
|
+
* @param e Click event
|
|
1153
|
+
* @param product_id product_id of clicked product
|
|
1154
|
+
* @return A promise resolving to void after 60s or when the product id was broadcasted
|
|
1891
1155
|
*/
|
|
1892
|
-
export function
|
|
1156
|
+
export function contextmenu_callback(e: Event, product_id: string): Promise<void>;
|
|
1157
|
+
interface TrackingData {
|
|
1158
|
+
/** The active market, if any */
|
|
1159
|
+
market?: string;
|
|
1160
|
+
/** The merchant id */
|
|
1161
|
+
tenant: string;
|
|
1162
|
+
}
|
|
1163
|
+
export interface PageViewEventData extends TrackingData {
|
|
1164
|
+
/** If the page is a pdp, include the product_id */
|
|
1165
|
+
product_id?: string;
|
|
1166
|
+
}
|
|
1167
|
+
export interface PageViewTrackingData extends TrackingData {
|
|
1168
|
+
/** A function that returns the product_id of the product being displayed on href,
|
|
1169
|
+
* if the href points to a PDP */
|
|
1170
|
+
get_product_id: (href: string) => string | undefined | Promise<string | undefined>;
|
|
1171
|
+
}
|
|
1893
1172
|
/**
|
|
1894
|
-
*
|
|
1895
|
-
*
|
|
1896
|
-
* @
|
|
1897
|
-
* @param id_extractor Maps an URL to a transaction ID string, or something falsy if no transaction ID is found.
|
|
1898
|
-
* For example: url => url.searchParams.get("orderId")
|
|
1173
|
+
* Sends a page_view event to Depict tracking if it hasn't been sent yet for the current page url
|
|
1174
|
+
* It also broadcasts the current URL to a BroadcastChannel using the function `broadcast_url`, this is used for right click + open in new tab tracking
|
|
1175
|
+
* @return A promise resolving to void
|
|
1899
1176
|
*/
|
|
1900
|
-
export function
|
|
1901
|
-
export function send_transaction_id_to_depict(t: Tenant, input_id: string, session_id?: string, filter?: (text: string) => string | undefined): void;
|
|
1177
|
+
export function send_page_view_if_needed(data: PageViewEventData): Promise<void>;
|
|
1902
1178
|
/**
|
|
1903
|
-
*
|
|
1904
|
-
|
|
1905
|
-
export function
|
|
1179
|
+
* Sends a page_view event to Depict tracking, and another one any time the page URL changes
|
|
1180
|
+
*/
|
|
1181
|
+
export function send_page_view_on_navigation(data: PageViewTrackingData): Promise<void>;
|
|
1906
1182
|
export interface ListenableSetEvent<T> extends CustomEvent {
|
|
1907
1183
|
detail: T;
|
|
1908
1184
|
}
|
|
@@ -2076,23 +1352,18 @@ interface ShopifyMetaProduct {
|
|
|
2076
1352
|
* This function gives you that object in a safe way that won't break Shopify.
|
|
2077
1353
|
*/
|
|
2078
1354
|
export const get_shopify_analytics_meta_product: () => Promise<ShopifyMetaProduct | undefined>;
|
|
1355
|
+
export const wait: (delay: number) => Promise<unknown>;
|
|
2079
1356
|
/**
|
|
2080
|
-
*
|
|
2081
|
-
*
|
|
2082
|
-
*
|
|
2083
|
-
* @param
|
|
2084
|
-
* @param
|
|
2085
|
-
* @
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
functions_to_variants
|
|
2091
|
-
}: {
|
|
2092
|
-
t: Tenant;
|
|
2093
|
-
experiment_id: string;
|
|
2094
|
-
functions_to_variants: Function[];
|
|
2095
|
-
}): Promise<any>;
|
|
1357
|
+
* Fetch with retry and exponetial back off. This is the 2.0 version of the previous Windows proof fetch.
|
|
1358
|
+
*
|
|
1359
|
+
* Windows proof fetch is a utility which retries fetch requests 10 times when they fail. Reason for this is a certain windows 10 build where the network stack randomly breaks 20% of https connections
|
|
1360
|
+
* @param url Url to perform fetch towards
|
|
1361
|
+
* @param options Fetch options
|
|
1362
|
+
* @param max_retries Max number of retries, defaults to 10
|
|
1363
|
+
* @param useFetch The fetch function to use, defaults to the global fetch
|
|
1364
|
+
* @returns The fetch response
|
|
1365
|
+
*/
|
|
1366
|
+
export function fetch_retry(url: RequestInfo | URL, options?: RequestInit, max_retries?: number, useFetch?: typeof fetch): Promise<false | Response>;
|
|
2096
1367
|
/**
|
|
2097
1368
|
* Ensures that the attribute value of an element is what an AsyncIterable resolves with
|
|
2098
1369
|
* @param el Element to set attribute on
|
|
@@ -2145,53 +1416,6 @@ export function insert_surfaces<T extends Display>({
|
|
|
2145
1416
|
succeeded: boolean;
|
|
2146
1417
|
}>[];
|
|
2147
1418
|
export const revertable_remove: (target: string | Element | Node_Array, should_stay_inserted: Promise<boolean>) => Promise<void | undefined>;
|
|
2148
|
-
type MakePlaceholderRROption<T extends Display> = {
|
|
2149
|
-
override_rec_renderer?: (t: Tenant | null, rendering_options: Extended_RR_Options<T>) => Promise<RecRendererResult<T>>;
|
|
2150
|
-
image_width?: number;
|
|
2151
|
-
image_height?: number;
|
|
2152
|
-
color?: string;
|
|
2153
|
-
num_items?: number;
|
|
2154
|
-
on_no_rendering_result?: (result?: RecRendererResult<T>) => any;
|
|
2155
|
-
post_rendering?: (surface?: RecRendererResult<T>) => Promise<void> | void;
|
|
2156
|
-
};
|
|
2157
|
-
/**
|
|
2158
|
-
* We want to deprecate this
|
|
2159
|
-
*/
|
|
2160
|
-
export type PlaceholderRenderingDisplay = {
|
|
2161
|
-
sale_price: number;
|
|
2162
|
-
page_url: "#" | string;
|
|
2163
|
-
image_url: string;
|
|
2164
|
-
original_price: number;
|
|
2165
|
-
product_id: "placeholder" | string;
|
|
2166
|
-
recommendation_id: "placeholder" | string;
|
|
2167
|
-
title: string;
|
|
2168
|
-
brand: string;
|
|
2169
|
-
};
|
|
2170
|
-
export const random_text_placeholder: () => string;
|
|
2171
|
-
export const placeholder_svg: (image_width: number, image_height: number, color?: string) => string;
|
|
2172
|
-
/**
|
|
2173
|
-
* Wraps default_rr or provided override_rec_renderer in two rendering passes where the first one will render placeholders and the second one what actually is asked for. As soon as the second pass completes the result of the first one is replaced with it.
|
|
2174
|
-
* @param [override_rec_renderer=default_rr] The recommendation renderer to use
|
|
2175
|
-
* @param [image_width=2000] Width of placeholder image svg (use to set aspect ratio)
|
|
2176
|
-
* @param [image_height=2000] Height of placeholder image svg (use to set aspect ratio)
|
|
2177
|
-
* @param [num_items=10] Number of placeholders to render
|
|
2178
|
-
* @param [color="#d9d9d9"] Color of placeholder image svg
|
|
2179
|
-
* @param [on_no_rendering_result] If rendering of actual recommendations fails (doesn't yield any `elements`) this function will be called with the rendering result as first argument
|
|
2180
|
-
* @param [post_rendering] Will be called and awaited after rendering of actual recommendations, has a chance to change them before they get inserted into the DOM
|
|
2181
|
-
* @return It returns the same as a normal recommenation renderer would, meaning an object that might contain `displays` and `elements`
|
|
2182
|
-
*/
|
|
2183
|
-
export function make_placeholder_rr<T extends Display>({
|
|
2184
|
-
override_rec_renderer,
|
|
2185
|
-
image_width,
|
|
2186
|
-
image_height,
|
|
2187
|
-
num_items,
|
|
2188
|
-
color,
|
|
2189
|
-
on_no_rendering_result,
|
|
2190
|
-
post_rendering
|
|
2191
|
-
}?: MakePlaceholderRROption<T>): Promise<(t: Tenant | null, rendering_options: Extended_RR_Options<T | PlaceholderRenderingDisplay>) => Promise<Record<string, never> | {
|
|
2192
|
-
elements: Node_Array;
|
|
2193
|
-
displays: T[];
|
|
2194
|
-
}>>;
|
|
2195
1419
|
/**
|
|
2196
1420
|
* Makes Node.prototype.removeChild not throw and emulate correct removal when a node is being removed by React's VDOM diffing that we have already removed before
|
|
2197
1421
|
* @return a WeakSet to add nodes to which you remove and want to ignore removal errors for
|
|
@@ -2461,7 +1685,7 @@ export function make_url_with_query_params(base: string, params: {
|
|
|
2461
1685
|
export interface ImageOptions extends Partial<HTMLImageElement> {
|
|
2462
1686
|
aspect_ratio: number;
|
|
2463
1687
|
class?: string;
|
|
2464
|
-
rendering_options?:
|
|
1688
|
+
rendering_options?: Record<any, any>;
|
|
2465
1689
|
srcset_opts?: Parameters<typeof make_sourceset_component>[0];
|
|
2466
1690
|
alt: string;
|
|
2467
1691
|
remove_on_error?: boolean;
|