@depict-ai/utilishared 0.0.31 → 0.0.33

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/dist/index.d.ts CHANGED
@@ -112,7 +112,7 @@ export const Sentry: {
112
112
  * Severity level to send to sentry.
113
113
  * We can also send `log`, `info`, `debug`, `critical` and `fatal` but we haven't had a need for it yet.
114
114
  */
115
- export type Severity = "error" | "warning";
115
+ type Severity = "error" | "warning";
116
116
  export function catchify<T extends Function>(fn: T, msg?: string, severity?: Severity): T;
117
117
  /**
118
118
  * Send error message with given severity and extra info to sentry
@@ -200,7 +200,7 @@ export function make_random_classname(): string;
200
200
  export type event_types = "page_view" | "click" | "add_to_cart" | "purchase" | "element_visible";
201
201
  declare const allowed_keys: readonly ["tenant", "market", "type", "user_id", "session_id", "product_id", "entity_identifiers", "url", "entity_price", "currency", "document_referrer", "document_width", "attribution_id", "recommendation_id", "click_location", "ab_test_group", "variant_ids", "dsid", "transaction_id", "error_type", "detail", "recommendation_type", "search_result_id", "product_listing_result_id"];
202
202
  export type depict_body = Partial<{
203
- [K in typeof allowed_keys[number]]: any;
203
+ [K in (typeof allowed_keys)[number]]: any;
204
204
  }>;
205
205
  export type depict_payload = depict_body[];
206
206
  type any_properties = {
@@ -875,7 +875,7 @@ type ExclusiveId = {
875
875
  product_id?: undefined;
876
876
  product_ids?: undefined;
877
877
  };
878
- export type FetchRecsOptions = {
878
+ type FetchRecsOptions = {
879
879
  type: string;
880
880
  } & ExclusiveId;
881
881
  /**
@@ -886,10 +886,16 @@ export type FetchRecsOptions = {
886
886
  *
887
887
  * Formerly called get_displays
888
888
  */
889
- export function fetch_recs<T = Display>(t: Tenant, options: FetchRecsOptions, headers?: HeadersInit, get_url?: typeof default_get_fetch_url): Promise<T[]>;
889
+ export function fetch_recs<T = Display>(t: Tenant | {
890
+ market: string;
891
+ tenant: string;
892
+ }, options: FetchRecsOptions, headers?: HeadersInit, get_url?: typeof default_get_fetch_url): Promise<T[]>;
890
893
  export function fetch_recs_whole_response<R extends {
891
894
  displays: any[];
892
- }>(t: Tenant, options: FetchRecsOptions, headers?: HeadersInit, get_url?: typeof default_get_fetch_url): Promise<R>;
895
+ }>(t: Tenant | {
896
+ market: string;
897
+ tenant: string;
898
+ }, options: FetchRecsOptions, headers?: HeadersInit, get_url?: typeof default_get_fetch_url): Promise<R>;
893
899
  declare function default_get_fetch_url(type: PossibleEndpoint): string;
894
900
  export function ensure_parameter_in_url(url: any, param: any, value: any): string;
895
901
  export function querySelectorUpwards(element: Element | HTMLElement, selector: string): Element | null;
@@ -901,19 +907,11 @@ export function querySelectorAllElements<T extends Element>(elements: Node_Itera
901
907
  export function standard_price_format(price: number, places_after_comma?: number | "auto", decimal_delimiter?: string, thousands_delimiter?: string): string;
902
908
  export function intl_number_format_with_fallback(bcp47_country_code: string, number: number, numberformat_options?: Parameters<typeof Intl.NumberFormat>[1]): string;
903
909
  export function ensure_object_path(obj: object, step1: string, ...path: string[]): any;
904
- export type event_listener_array = [
905
- type: keyof HTMLElementEventMap,
906
- listener: (this: HTMLElement, ev: HTMLElementEventMap[keyof HTMLElementEventMap]) => any,
907
- options?: boolean | AddEventListenerOptions
908
- ][];
909
910
  export function Rec_Renderer(t: Tenant, rendering_options: RR_Options): Promise<RecRendererResult>;
910
911
  export function regex_templating(template: string, display?: Display | {
911
912
  [key: string]: any;
912
913
  }): string;
913
914
  export function clone_deep<T>(obj: T): T;
914
- export function post_process(t: Tenant, rendering_options: RR_Options, displays: Display[], index: number, functions: RR_PostProcessor[], // required, duh
915
- elements: NodeListOf<ChildNode> | Node_Array, event_listeners?: event_listener_array): Promise<NodeListOf<ChildNode> | Node_Array>;
916
- export function pre_processor_pipeline(t: Tenant, rendering_options: RR_Options, displays: Display[]): Promise<Display[]>;
917
915
  export class InfoForProcessing {
918
916
  constructor(t: Tenant, rendering_options: RR_Options, displays: Display[], index?: number, remove_display?: () => void, event_listeners?: [
919
917
  type: keyof HTMLElementEventMap,
@@ -1010,10 +1008,7 @@ export const check_displays: ({ recs, min_recs, market, type, product_id, tenant
1010
1008
  export function require_event_listener(element: Node, event: string, track_id: any, func: EventListenerOrEventListenerObject): void;
1011
1009
  export const default_view_tracking: RR_PostProcessor[];
1012
1010
  export const default_click_tracking: (typeof add_new_tab_listener)[];
1013
- export const tracking_function_map: Map<Function, WeakRef<Function>[]>;
1014
- export const rro_inserted_event_sent: WeakSet<RR_Options>;
1015
1011
  export function recs_inserted_tracking(elements: NodeListOf<ChildNode>, _display: Display, info: InfoForProcessing): NodeListOf<ChildNode>;
1016
- export const gtag_view_sent: WeakSet<Display[]>;
1017
1012
  export function gtag_view_post_processor(elements: NodeListOf<ChildNode>, _display: Display, info: InfoForProcessing): NodeListOf<ChildNode>;
1018
1013
  export function depict_page_view(elements: NodeListOf<ChildNode>, _display: Display, info: InfoForProcessing): NodeListOf<ChildNode>;
1019
1014
  export function gtag_click_post_processor(elements: NodeListOf<ChildNode>, display: Display, info: InfoForProcessing): NodeListOf<ChildNode>;
@@ -1022,17 +1017,12 @@ export function add_to_localstorage(elements: NodeListOf<ChildNode>, display: Di
1022
1017
  export function ga_click(elements: NodeListOf<ChildNode>, display: Display, info: InfoForProcessing): NodeListOf<ChildNode>;
1023
1018
  export const should_colorizeLogics: boolean;
1024
1019
  export function colorize_elements(elements: NodeListOf<ChildNode>, display: Display): NodeListOf<ChildNode>;
1025
- export type RR_Translations = {
1026
- [market: string]: {
1027
- [key: string]: string;
1028
- };
1029
- };
1030
- export type Extended_RR_Options = {
1020
+ type Extended_RR_Options = {
1031
1021
  view_tracking?: RR_PostProcessor[];
1032
1022
  click_tracking?: RR_PostProcessor[];
1033
1023
  } & RR_Options;
1034
1024
  export function default_rr(t: Tenant, rendering_options: Extended_RR_Options): Promise<RecRendererResult>;
1035
- export type GWVM_Options = {
1025
+ type GWVM_Options = {
1036
1026
  container_selector?: string;
1037
1027
  start_rows?: number;
1038
1028
  rows_per_click?: number;
@@ -1045,7 +1035,7 @@ export type GWVM_Options = {
1045
1035
  only_full_rows?: boolean;
1046
1036
  should_preload?: boolean;
1047
1037
  };
1048
- export interface GWVM_InfoForProcessing extends InfoForProcessing {
1038
+ interface GWVM_InfoForProcessing extends InfoForProcessing {
1049
1039
  extras: {
1050
1040
  [key: string]: any;
1051
1041
  load_more_currently_showing: number;
@@ -1056,8 +1046,8 @@ export interface GWVM_InfoForProcessing extends InfoForProcessing {
1056
1046
  };
1057
1047
  };
1058
1048
  }
1059
- export type GWVM_RR_Post_Pro = (elements: NodeListOf<ChildNode> | Node_Array, display: Display, info: GWVM_InfoForProcessing) => Promise<NodeListOf<ChildNode> | Node_Array> | NodeListOf<ChildNode> | Node_Array;
1060
- export type GWVM_RR_Options = Extended_RR_Options & {
1049
+ type GWVM_RR_Post_Pro = (elements: NodeListOf<ChildNode> | Node_Array, display: Display, info: GWVM_InfoForProcessing) => Promise<NodeListOf<ChildNode> | Node_Array> | NodeListOf<ChildNode> | Node_Array;
1050
+ type GWVM_RR_Options = Extended_RR_Options & {
1061
1051
  post_processors?: GWVM_RR_Post_Pro[];
1062
1052
  };
1063
1053
  /**
@@ -1093,7 +1083,7 @@ export function infinite_promise_creator(): {
1093
1083
  internal_resolve: ((value: any) => void) | undefined;
1094
1084
  resolve: (argument?: any) => void;
1095
1085
  };
1096
- export interface trimmed_GWVM_opts extends Omit<GWVM_Options, "start_rows" | "rows_per_click" | "recs_per_row"> {
1086
+ interface trimmed_GWVM_opts extends Omit<GWVM_Options, "start_rows" | "rows_per_click" | "recs_per_row"> {
1097
1087
  }
1098
1088
  /**
1099
1089
  * @deprecated please rewrite this, basing on RecommendationGrid and its `rows.ipns` option, next time you need infinite scroll
@@ -1113,7 +1103,7 @@ export type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType exten
1113
1103
  /**
1114
1104
  * @deprecated please use TwoLetterMarket / readonly arrays/objects instead
1115
1105
  */
1116
- export enum Market {
1106
+ enum Market {
1117
1107
  dk = "dk",
1118
1108
  uk = "uk",
1119
1109
  com = "com",
@@ -1132,7 +1122,7 @@ export enum Market {
1132
1122
  /**
1133
1123
  * @deprecated please use TwoLetterMarket / readonly arrays/objects instead
1134
1124
  */
1135
- export enum Locale {
1125
+ enum Locale {
1136
1126
  sv_SE = "sv-SE",
1137
1127
  no_NO = "no-NO",
1138
1128
  fi_FI = "fi-FI",
@@ -1151,18 +1141,14 @@ type CurrencyInfo = {
1151
1141
  /**
1152
1142
  * @deprecated please use TwoLetterMarket / readonly arrays/objects instead
1153
1143
  */
1154
- export const CURRENCY: Record<string, CurrencyInfo>;
1155
- /**
1156
- * @deprecated please use TwoLetterMarket / readonly arrays/objects instead
1157
- */
1158
- export type MarketDetails = {
1144
+ type MarketDetails = {
1159
1145
  currency: CurrencyInfo;
1160
1146
  locale_bcp47: Locale;
1161
1147
  };
1162
1148
  /**
1163
1149
  * @deprecated please use TwoLetterMarket / readonly arrays/objects instead
1164
1150
  */
1165
- export type MarketConfig = MarketDetails & {
1151
+ type MarketConfig = MarketDetails & {
1166
1152
  analytics_id: string;
1167
1153
  };
1168
1154
  /**
@@ -1204,7 +1190,7 @@ export interface Lazyfier {
1204
1190
  only_load_intersecting: boolean;
1205
1191
  ignore_data_urls?: boolean;
1206
1192
  }
1207
- export interface Lazyfier_Options {
1193
+ interface Lazyfier_Options {
1208
1194
  container?: HTMLElement;
1209
1195
  lazyfinder?: lazyfinder;
1210
1196
  selector?: string;
@@ -1219,13 +1205,12 @@ export class Lazyfier {
1219
1205
  start_observing_for_new_children_(override_container?: HTMLElement): void;
1220
1206
  constructor({ container, lazyfinder, selector, wait_for_dominsertion, only_load_intersecting, ignore_data_urls, verbose, }: Lazyfier_Options);
1221
1207
  }
1222
- export interface lazyfinder {
1208
+ interface lazyfinder {
1223
1209
  elements?: HTMLImageElementWithLoaded[];
1224
1210
  unload?: (element: HTMLImageElementWithLoaded) => void | Promise<void>;
1225
1211
  load?: (element: HTMLImageElementWithLoaded) => void | Promise<void>;
1226
1212
  }
1227
1213
  export function test_array_proxy_support(): boolean;
1228
- export function find_siblings<T extends Element>(element: Element, selector: string): T[];
1229
1214
  export interface Slider_Options {
1230
1215
  /**
1231
1216
  * Controls within what distance to hide the left slider button.
@@ -1298,7 +1283,7 @@ export interface Amazing_Lazy_Slider {
1298
1283
  export class Amazing_Lazy_Slider extends Amazing_Slider {
1299
1284
  constructor(options: Slider_Options, lazyfier_options?: Optional<ConstructorParameters<typeof Lazyfier>[0], "container">);
1300
1285
  }
1301
- export interface Pro_Slider_Options {
1286
+ interface Pro_Slider_Options {
1302
1287
  container?: string | Node_Iterable;
1303
1288
  root_selector?: string;
1304
1289
  override_rec_renderer?: typeof Rec_Renderer;
@@ -1354,9 +1339,9 @@ export const simplified_template_tool: (options: {
1354
1339
  postProcessor?: Function | undefined;
1355
1340
  preProcessor?: Function | undefined;
1356
1341
  }) => Promise<Depict>;
1357
- export interface special_lazyfier_options extends Omit<Lazyfier_Options, "t"> {
1342
+ interface special_lazyfier_options extends Omit<Lazyfier_Options, "t"> {
1358
1343
  }
1359
- export interface Deprecated_Slider_Options {
1344
+ interface Deprecated_Slider_Options {
1360
1345
  dlog?: Function;
1361
1346
  catchify?: Function;
1362
1347
  dist_to_hide_left?: number;
@@ -1371,11 +1356,11 @@ export interface Deprecated_Slider_Options {
1371
1356
  /**
1372
1357
  * @deprecated Please use Pro_Slider instead
1373
1358
  */
1374
- export class Deprecated_Amazing_Slider extends Amazing_Lazy_Slider {
1359
+ declare class Deprecated_Amazing_Slider extends Amazing_Lazy_Slider {
1375
1360
  constructor(static_options: Deprecated_Slider_Options, override_lazyfier_options?: special_lazyfier_options);
1376
1361
  }
1377
1362
  export function insert_styling_into_slider(slider: Deprecated_Amazing_Slider): void;
1378
- export interface RR_Slider_Options {
1363
+ interface RR_Slider_Options {
1379
1364
  container?: string | Node_Iterable;
1380
1365
  root_selector?: string;
1381
1366
  Rec_Renderer?: typeof Rec_Renderer;
@@ -1385,8 +1370,8 @@ export interface RR_Slider_Options {
1385
1370
  * @deprecated please use Pro_Slider instead
1386
1371
  */
1387
1372
  export function RR_Slider(t: Tenant, rendering_options: Extended_RR_Options, options_for_us?: RR_Slider_Options, slider_options?: Deprecated_Slider_Options, override_lazyfier_options?: special_lazyfier_options): ReturnType<typeof Rec_Renderer>;
1388
- export type PreProcessor = (tenant: Tenant, display: any, i?: number, with_loadmore?: boolean, with_slider?: boolean, infinite_scroll?: boolean) => any;
1389
- export type PostProcessor = (tenant: Tenant, items: HTMLCollection, display: any, slider?: Deprecated_Amazing_Slider) => HTMLCollection;
1373
+ type PreProcessor = (tenant: Tenant, display: any, i?: number, with_loadmore?: boolean, with_slider?: boolean, infinite_scroll?: boolean) => any;
1374
+ type PostProcessor = (tenant: Tenant, items: HTMLCollection, display: any, slider?: Deprecated_Amazing_Slider) => HTMLCollection;
1390
1375
  /**
1391
1376
  * @deprecated this uses template-tool-v1 which is long surpassed, please use RecommendationGrid or Pro_Slider (based on Recommendation-Renderer) instead
1392
1377
  */
@@ -1414,18 +1399,15 @@ export const wpff: (dlog: any, error_log?: any[] | undefined) => (url: RequestIn
1414
1399
  export const use_element: <E extends HTMLOrSVGElement = HTMLElement>(callback: (element: E) => void, element: E) => E;
1415
1400
  export const use_listener: <E extends HTMLElement = HTMLElement>(event: string, handler: EventListener, element: E) => E;
1416
1401
  export const classlist: (classes: (string | undefined)[]) => string;
1417
- export type Props = {
1402
+ type Props = {
1418
1403
  children: Elem[] | Elem;
1419
1404
  onClick: (e: MouseEvent) => void;
1420
1405
  [key: string]: any;
1421
1406
  };
1422
- export type Elem = Node | string;
1423
- export type Component = (props: Props, _unknown: unknown) => HTMLElement;
1407
+ type Elem = Node | string;
1408
+ type Component = (props: Props, _unknown: unknown) => HTMLElement;
1424
1409
  export const jsx: (tag: string | Component, { children, ...props }: Props, _unknown: unknown) => JSX.Element;
1425
1410
  export const jsxs: (tag: string | Component, { children, ...props }: Props, _unknown: unknown) => JSX.Element;
1426
- export const Fragment: ({ children }: {
1427
- children: Elem[] | Elem;
1428
- }, _unknown: unknown) => DocumentFragment;
1429
1411
  export const chevronRight: HTMLElement;
1430
1412
  export const chevronLeft: HTMLElement;
1431
1413
  export const expandingContainer: ({ duration }?: {
@@ -1448,9 +1430,9 @@ export function zip_async_iterables<T extends any[]>(iterables: IPNS<T[keyof T]>
1448
1430
  type Override = {
1449
1431
  overrides: Record</* Row: */ number, /* Column: */ number>;
1450
1432
  };
1451
- export type ColAtSize = /** [ <number of columns>, <min-width>, <max-width>, <spacing> ] */ readonly [number, null, string, string | null] | readonly [number, string, string, null, Override] | readonly [number, string, null, string | null] | readonly [number, string, string, string | null] | readonly [number, string, null] | readonly [number, string, string] | readonly [number, null, string] | readonly [number, string];
1452
- export type ColsAtSize = readonly ColAtSize[];
1453
- export type LayoutOptions = {
1433
+ type ColAtSize = /** [ <number of columns>, <min-width>, <max-width>, <spacing> ] */ readonly [number, null, string, string | null] | readonly [number, string, string, null, Override] | readonly [number, string, null, string | null] | readonly [number, string, string, string | null] | readonly [number, string, null] | readonly [number, string, string] | readonly [number, null, string] | readonly [number, string];
1434
+ type ColsAtSize = readonly ColAtSize[];
1435
+ type LayoutOptions = {
1454
1436
  container_element: Element;
1455
1437
  cols_at_size: ColsAtSize;
1456
1438
  grid_spacing: string;
@@ -1465,7 +1447,6 @@ export type LayoutOptions = {
1465
1447
  disable_partial_rows?: boolean;
1466
1448
  override_vertical_spacing?: string;
1467
1449
  };
1468
- export const media_query_header: (min: string, max?: string | undefined) => string;
1469
1450
  /**
1470
1451
  * Grid: Calculates CSS for a grid with a certain spacing and certain number of columns at certain screen sizes, including a view more button.
1471
1452
  * @param rows if set to 'all': Just generate grid styling without any viewing/hiding functionality. If an object: start_rows is the number of rows at the beginning. rows_per_click is the amount of rows to view on each view more buttonn click. button is the view more button to display. ipns is an async iterable infinite promise that you can use to get and set the number of currently viewed rows
@@ -1692,7 +1673,7 @@ export interface ListenableSetEvent<T> extends CustomEvent {
1692
1673
  */
1693
1674
  export class ListenableSet<T> extends Set<T> {
1694
1675
  #private;
1695
- addEventListener(event: "add" | "delete", callback: (ev: ListenableSetEvent<T>) => unknown, options?: Parameters<typeof EventTarget.prototype["addEventListener"]>[2]): void;
1676
+ addEventListener(event: "add" | "delete", callback: (ev: ListenableSetEvent<T>) => unknown, options?: Parameters<(typeof EventTarget.prototype)["addEventListener"]>[2]): void;
1696
1677
  removeEventListener(event: "add" | "delete", callback: (ev: Event) => unknown): void;
1697
1678
  add(property: T): this;
1698
1679
  delete(property: T): any;
@@ -1907,16 +1888,6 @@ export function insert_surfaces({ surfaces: input_surfaces, verb, target, remove
1907
1888
  succeeded: boolean;
1908
1889
  }>[];
1909
1890
  export const revertable_remove: (target: Element | Node_Array | string, should_stay_inserted: Promise<boolean>) => Promise<void>;
1910
- /**
1911
- * restore (if no allSettled and prototype.finally) native Promise and cement Promise - some customers force polyfill promise with flawed implementations of .all and .allSettled that randomly throw (see usage examples)
1912
- * @return void
1913
- */
1914
- export function replace_promise_with_native_if_exists_and_enforce(): void;
1915
- /**
1916
- * Creates a blank iframe inside <head> and returns window.Promise out of it
1917
- * @return a pristine, unpolyfilled window.Promise
1918
- */
1919
- export function get_iframe_promise(): PromiseConstructor;
1920
1891
  type MakePlaceholderRROption = {
1921
1892
  override_rec_renderer?: (t: Tenant, rendering_options: Extended_RR_Options) => Promise<RecRendererResult>;
1922
1893
  image_width?: number;
@@ -1949,6 +1920,16 @@ export function queueMacroTask(callback: VoidFunction): void;
1949
1920
  * @return a WeakSet to add nodes to which you remove and want to ignore removal errors for
1950
1921
  */
1951
1922
  export function removeChild_error_swallowing_factory(): WeakSet<Node>;
1923
+ /**
1924
+ * restore (if no allSettled and prototype.finally) native Promise and cement Promise - some customers force polyfill promise with flawed implementations of .all and .allSettled that randomly throw (see usage examples)
1925
+ * @return void
1926
+ */
1927
+ export function replace_promise_with_native_if_exists_and_enforce(): void;
1928
+ /**
1929
+ * Creates a blank iframe inside <head> and returns window.Promise out of it
1930
+ * @return a pristine, unpolyfilled window.Promise
1931
+ */
1932
+ export function get_iframe_promise(): PromiseConstructor;
1952
1933
  /**
1953
1934
  * Proxies XMLHttpRequest.prototype.open to an open function which also calls the provided `fetch_handler` with useful information as parameter
1954
1935
  * @param fetch_handler A function which is catchified and which's return value is ignored. It gets called every time an XHR request gets opened
@@ -2212,5 +2193,21 @@ export function SearchIcon(props?: JSX.SvgSVGAttributes<SVGSVGElement>): HTMLEle
2212
2193
  export function SortIconAsc(props?: JSX.SvgSVGAttributes<SVGSVGElement>): SVGElement;
2213
2194
  export function SortIconDesc(props?: JSX.SvgSVGAttributes<SVGSVGElement>): HTMLElement;
2214
2195
  export function TickIcon(props?: JSX.SvgSVGAttributes<SVGSVGElement>): HTMLElement;
2215
- export const version = "0.0.31";
2216
- export type { Display as DisplayWithVariants } from "./new_display";
2196
+ export const version = "0.0.33";
2197
+ /**
2198
+ * Shallowly converts all keys in an object from snake_case to camelCase.
2199
+ * Does not support symbol keys.
2200
+ *
2201
+ * @param obj the object. It will be cloned and not modified in-place.
2202
+ */
2203
+ export function camelCasifyObject<T extends {
2204
+ [key: string]: any;
2205
+ }, X extends T = T>(obj: T): X;
2206
+ /**
2207
+ * Shallowly converts all keys in an object from camelCase to snake_case.
2208
+ * Does not support symbol keys.
2209
+ * @param obj the object. It will be cloned and not modified in-place.
2210
+ */
2211
+ export function snakeCasifyObject<T extends {
2212
+ [key: string]: any;
2213
+ }, X extends T = T>(obj: T): X;