@amedia/user 0.13.33 → 0.13.35

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/user.d.ts ADDED
@@ -0,0 +1,735 @@
1
+ declare module '@amedia/user/actions/authentication' {
2
+ import { UserAttributes } from '@amedia/user/types';
3
+ export const login: (requestedUrl: URL | string) => void;
4
+ export const logout: () => Promise<void>;
5
+ export const getSession: () => Promise<UserAttributes>;
6
+
7
+ }
8
+ declare module '@amedia/user/actions/authentication.spec' {
9
+ export {};
10
+
11
+ }
12
+ declare module '@amedia/user/actions/authorization' {
13
+ import { UserAttributes } from '@amedia/user/types';
14
+ type SetCookieResponse = {
15
+ success: boolean;
16
+ accessFeatures: string[];
17
+ };
18
+ export const getAccess: (accessFeatures?: string[]) => Promise<Pick<UserAttributes, 'access'>>;
19
+ export const activate: (accessFeatures: string[]) => Promise<string[]>;
20
+ export const hasAccess: (currentAccessFeatures: string[], requestedAccessFeatures: string[]) => boolean;
21
+ export const setUserAccessCookie: (publicationDomain: string) => Promise<SetCookieResponse>;
22
+ export const setNonUserAccessCookie: (publicationDomain: string) => Promise<SetCookieResponse>;
23
+ export const setAccessCookies: (publicationDomain: string) => Promise<SetCookieResponse>;
24
+ export const setHasPerformedPaywallReload: (requestedUrl?: string | undefined) => void;
25
+ export const hasRecentlyPerformedPaywallReload: (requestedUrl?: string | undefined) => boolean;
26
+ export {};
27
+
28
+ }
29
+ declare module '@amedia/user/actions/authorization.spec' {
30
+ /**
31
+ * @jest-environment jsdom
32
+ */
33
+ export {};
34
+
35
+ }
36
+ declare module '@amedia/user/actions/preferences' {
37
+ import { Record, Boolean } from 'runtypes';
38
+ import { UserAttributes } from '@amedia/user/types';
39
+ export const PrivacyPreferencesSchema: Record<{
40
+ allowResearchUsage: Boolean;
41
+ connectWithSurveys: Boolean;
42
+ personalizedAds: Boolean;
43
+ personalizedContent: Boolean;
44
+ }, false>;
45
+ export const getPrivacyPreferences: () => Promise<Pick<UserAttributes, 'privacyPreferences'>>;
46
+
47
+ }
48
+ declare module '@amedia/user/actions/preferences.spec' {
49
+ export {};
50
+
51
+ }
52
+ declare module '@amedia/user/actions/storage' {
53
+ export const requestStorage: (namespaces: string[]) => void;
54
+ export const updateStorage: (storage: {
55
+ [namespace: string]: object;
56
+ }) => void;
57
+ export const saveStorage: (storage: {
58
+ [namespace: string]: object;
59
+ }) => void;
60
+
61
+ }
62
+ declare module '@amedia/user/actions/userData' {
63
+ import { UserAttributes } from '@amedia/user/types';
64
+ export const requestAttributes: (attributes: Array<keyof UserAttributes>) => Promise<void>;
65
+
66
+ }
67
+ declare module '@amedia/user/actions/userData.spec' {
68
+ export {};
69
+
70
+ }
71
+ declare module '@amedia/user/autologin/index' {
72
+ export type Strategies = Array<{
73
+ name: string;
74
+ handler: () => Promise<boolean>;
75
+ }>;
76
+ export const AUTOLOGIN_COOKIE_TTL = 60000;
77
+ export const attemptAutoLoginJob: () => Promise<void>;
78
+ export const attemptPaywallAutoLogin: () => Promise<void>;
79
+
80
+ }
81
+ declare module '@amedia/user/autologin/index.spec' {
82
+ export {};
83
+
84
+ }
85
+ declare module '@amedia/user/autologin/thirdPartyCookie' {
86
+ export const CACHE_KEY = "haveTriedThirdPartyLoginCheck";
87
+ export const CACHE_TTL: number;
88
+ export default function thirdPartyCookie(): Promise<boolean>;
89
+
90
+ }
91
+ declare module '@amedia/user/autologin/thirdPartyCookie.spec' {
92
+ export {};
93
+
94
+ }
95
+ declare module '@amedia/user/cache/engines/global' {
96
+ import { CacheEntry, Engine } from '@amedia/user/cache/types';
97
+ global {
98
+ export var amediaUserCache: {
99
+ [index: string]: CacheEntry;
100
+ };
101
+ interface Window {
102
+ amediaUserCache?: {
103
+ [index: string]: CacheEntry;
104
+ };
105
+ }
106
+ namespace NodeJS {
107
+ interface Global {
108
+ amediaUserCache?: {
109
+ [index: string]: CacheEntry;
110
+ };
111
+ }
112
+ }
113
+ }
114
+ export const get: (key: string) => Promise<CacheEntry>;
115
+ export const set: (key: string, data: unknown, expires: number) => Promise<void>;
116
+ export const remove: (key: string) => Promise<void>;
117
+ export const clear: () => Promise<void>;
118
+ const _default: Engine;
119
+ export default _default;
120
+
121
+ }
122
+ declare module '@amedia/user/cache/engines/global.spec' {
123
+ export {};
124
+
125
+ }
126
+ declare module '@amedia/user/cache/index' {
127
+ import { Static } from 'runtypes';
128
+ import { RuntypeBase } from 'runtypes/lib/runtype';
129
+ import { Engine } from '@amedia/user/cache/types';
130
+ export const setCacheEngine: (engine: Engine) => void;
131
+ const _default: {
132
+ get: <T extends RuntypeBase<unknown>>(key: string, validator: T) => Promise<void | Static<T>>;
133
+ set: (key: string, value: unknown, expires: number) => Promise<void>;
134
+ remove: (key: string) => Promise<void>;
135
+ clear: () => Promise<void>;
136
+ };
137
+ export default _default;
138
+
139
+ }
140
+ declare module '@amedia/user/cache/index.spec' {
141
+ export {};
142
+
143
+ }
144
+ declare module '@amedia/user/cache/types' {
145
+ export type CacheEntry = {
146
+ key: string;
147
+ data: unknown;
148
+ expires: number;
149
+ };
150
+ export type Engine = {
151
+ get: (key: string) => Promise<CacheEntry | null>;
152
+ set: (key: string, data: unknown, expires: number) => Promise<void>;
153
+ remove: (key: string) => Promise<void>;
154
+ clear: () => Promise<void>;
155
+ };
156
+
157
+ }
158
+ declare module '@amedia/user/clients/europa' {
159
+ import { Unknown, Dictionary } from 'runtypes';
160
+ export const EuropaSchema: Dictionary<Unknown, string>;
161
+ export const clearLocalCache: () => Promise<void>;
162
+ export const updateNamespace: (namespace: string, data: Object) => Promise<void | {}>;
163
+ export const getNamespaces: <S extends {
164
+ [namespace: string]: {
165
+ [index: string]: unknown;
166
+ };
167
+ }, Namespaces extends (keyof S)[]>(namespaces: Namespaces, options?: {
168
+ ignoreCache: boolean;
169
+ }) => Promise<Pick<S, Namespaces[number]>>;
170
+ export const saveNamespace: (namespace: string, data: Object) => Promise<Pick<{
171
+ [namespace: string]: {
172
+ [index: string]: unknown;
173
+ };
174
+ }, string>>;
175
+ export const getAllNamespaces: () => Promise<{
176
+ [x: string]: unknown;
177
+ }>;
178
+ export const deleteNamespaceKey: (namespace: string, key: string) => Promise<Pick<{
179
+ [namespace: string]: {
180
+ [index: string]: unknown;
181
+ };
182
+ }, string>>;
183
+
184
+ }
185
+ declare module '@amedia/user/clients/europa.spec' {
186
+ export {};
187
+
188
+ }
189
+ declare module '@amedia/user/clients/jupiter' {
190
+ import { Array, Literal, Number, Record, Static, String, Union } from 'runtypes';
191
+ import { UserAttributes } from '@amedia/user/types';
192
+ export type AccessFeatures = string[];
193
+ export const CheckAccessForPaperSchema: Record<{
194
+ status: Literal<"success">;
195
+ access: Union<[Literal<"granted">, Literal<"denied">]>;
196
+ publication: Record<{
197
+ id: Number;
198
+ domain: String;
199
+ }, false>;
200
+ access_features: Array<String, false>;
201
+ }, false>;
202
+ export type CheckAccessForPaper = Static<typeof CheckAccessForPaperSchema>;
203
+ const GetVstokenSchema: Record<{
204
+ status: Literal<"success">;
205
+ cookie: String;
206
+ access_features: Array<String, false>;
207
+ }, false>;
208
+ export type GetVstoken = Static<typeof GetVstokenSchema>;
209
+ const GetNonUserAccessSchema: Record<{
210
+ status: Literal<"success">;
211
+ vstoken_cookie: String;
212
+ uuid: String;
213
+ access_features: Array<String, false>;
214
+ }, false>;
215
+ export type GetNonUserAccess = Static<typeof GetNonUserAccessSchema>;
216
+ export const checkForAccess: (publicationDomain: string, accessFeatures: AccessFeatures) => Promise<Pick<UserAttributes, 'access'>>;
217
+ export const getUserAccess: (publicationDomain: string) => Promise<GetVstoken>;
218
+ export const getNonUserAccess: (publicationDomain: string) => Promise<GetNonUserAccess>;
219
+ export {};
220
+
221
+ }
222
+ declare module '@amedia/user/clients/jupiter.spec' {
223
+ export {};
224
+
225
+ }
226
+ declare module '@amedia/user/clients/mercury' {
227
+ export class UserDeactivatedError extends Error {
228
+ }
229
+ export const activateSubscription: (accessFeatures: string[]) => Promise<string[]>;
230
+
231
+ }
232
+ declare module '@amedia/user/clients/mercury.spec' {
233
+ export {};
234
+
235
+ }
236
+ declare module '@amedia/user/clients/mercuryLog' {
237
+ type Context = Record<string, unknown>;
238
+ const log: {
239
+ error: (message: string, context: Context) => void;
240
+ warn: (message: string, context: Context) => void;
241
+ info: (message: string, context: Context) => void;
242
+ debug: (message: string, context: Context) => void;
243
+ };
244
+ export default log;
245
+
246
+ }
247
+ declare module '@amedia/user/clients/mercuryLog.spec' {
248
+ export {};
249
+
250
+ }
251
+ declare module '@amedia/user/clients/nebula' {
252
+ import { UserAttributes } from '@amedia/user/types';
253
+ export const getInfo: (publicationDomain: string, browserId: string, trackingKey?: string | undefined) => Promise<Pick<UserAttributes, 'extraData'>>;
254
+
255
+ }
256
+ declare module '@amedia/user/clients/nebula.spec' {
257
+ export {};
258
+
259
+ }
260
+ declare module '@amedia/user/clients/pluto' {
261
+ import { UserAttributes } from '@amedia/user/types';
262
+ export const resolveBadPlutoResponse: (response: Response) => Promise<void>;
263
+ export const getCurrentSession: () => Promise<UserAttributes>;
264
+ export const removeSession: (domain: string) => Promise<void>;
265
+
266
+ }
267
+ declare module '@amedia/user/clients/pluto.spec' {
268
+ export {};
269
+
270
+ }
271
+ declare module '@amedia/user/eventHandlers/activation' {
272
+ export enum ActivationEvents {
273
+ REQUEST_ACTIVATION = "amedia-user.activation.request-activation",
274
+ ON_ACTIVATION_COMPLETE = "amedia-user.activation.on-activation-complete"
275
+ }
276
+ global {
277
+ interface WindowEventMap {
278
+ [ActivationEvents.REQUEST_ACTIVATION]: CustomEvent<{
279
+ accessFeatures: string[];
280
+ }>;
281
+ [ActivationEvents.ON_ACTIVATION_COMPLETE]: CustomEvent<{
282
+ accessFeatures: string[];
283
+ }>;
284
+ }
285
+ }
286
+ export const listenForActivationRequests: () => void;
287
+
288
+ }
289
+ declare module '@amedia/user/eventHandlers/authentication' {
290
+ export enum AuthenticationEvents {
291
+ REQUEST_LOGIN = "amedia-user.authentication.request-login",
292
+ REQUEST_LOGOUT = "amedia-user.authentication.request-logout",
293
+ ON_LOGGED_OUT = "amedia-user.authentication.on-logged-out"
294
+ }
295
+ global {
296
+ interface WindowEventMap {
297
+ [AuthenticationEvents.REQUEST_LOGIN]: CustomEvent<{
298
+ requestedUrl: string;
299
+ }>;
300
+ [AuthenticationEvents.REQUEST_LOGOUT]: CustomEvent<{
301
+ onLoggedOut: () => void;
302
+ }>;
303
+ [AuthenticationEvents.ON_LOGGED_OUT]: CustomEvent;
304
+ }
305
+ }
306
+ export const listenForAuthenticationRequests: () => void;
307
+
308
+ }
309
+ declare module '@amedia/user/eventHandlers/eventMap' {
310
+ import { State, UserAttributes } from '@amedia/user/types';
311
+ export enum AmediaUserEvents {
312
+ REQUEST_STATE = "amedia-user.request-state",
313
+ REQUEST_USER_ATTRIBUTES = "amedia-user.request-user-attributes",
314
+ REQUEST_STORAGE_NAMESPACES = "amedia-user.request-storage-namespaces",
315
+ SAVE_STORAGE = "amedia-user.save-storage-namespaces",
316
+ UPDATE_STORAGE = "amedia-user.update-storage-namespaces",
317
+ ON_ATTRIBUTES_UPDATED = "amedia-user.on-user-attributes-updated",
318
+ ON_STATE_UPDATED = "amedia-user.on-state-updated",
319
+ ON_STORAGE_UPDATED = "amedia-user.on-storage-updated"
320
+ }
321
+ global {
322
+ interface WindowEventMap {
323
+ [AmediaUserEvents.REQUEST_STATE]: CustomEvent;
324
+ [AmediaUserEvents.REQUEST_USER_ATTRIBUTES]: CustomEvent<Array<keyof UserAttributes>>;
325
+ [AmediaUserEvents.REQUEST_STORAGE_NAMESPACES]: CustomEvent<Array<string>>;
326
+ [AmediaUserEvents.SAVE_STORAGE]: CustomEvent<{
327
+ [namespace: string]: object;
328
+ }>;
329
+ [AmediaUserEvents.UPDATE_STORAGE]: CustomEvent<{
330
+ [namespace: string]: object;
331
+ }>;
332
+ [AmediaUserEvents.ON_ATTRIBUTES_UPDATED]: CustomEvent<UserAttributes>;
333
+ [AmediaUserEvents.ON_STATE_UPDATED]: CustomEvent<State>;
334
+ [AmediaUserEvents.ON_STORAGE_UPDATED]: CustomEvent<{
335
+ [index: string]: unknown;
336
+ }>;
337
+ }
338
+ }
339
+
340
+ }
341
+ declare module '@amedia/user/eventHandlers/state' {
342
+ export const listenForStateRequests: () => void;
343
+
344
+ }
345
+ declare module '@amedia/user/eventHandlers/state.spec' {
346
+ export {};
347
+
348
+ }
349
+ declare module '@amedia/user/eventHandlers/storage' {
350
+ export const listenForStorageRequests: () => void;
351
+
352
+ }
353
+ declare module '@amedia/user/eventHandlers/storage.spec' {
354
+ export {};
355
+
356
+ }
357
+ declare module '@amedia/user/eventHandlers/userAttributes' {
358
+ export const listenForUserAttributeRequests: () => void;
359
+
360
+ }
361
+ declare module '@amedia/user/eventHandlers/userAttributes.spec' {
362
+ export {};
363
+
364
+ }
365
+ declare module '@amedia/user/exceptions/PaywallError' {
366
+ class PaywallError extends Error {
367
+ static ERROR_RELOADED_NO_ACCESS: string;
368
+ static ERROR_ENABLING_ACCESS_FAILED: string;
369
+ static ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES: string;
370
+ code: string;
371
+ constructor(message: string, code: string);
372
+ }
373
+ export default PaywallError;
374
+
375
+ }
376
+ declare module '@amedia/user/index-authentcation.spec' {
377
+ export {};
378
+
379
+ }
380
+ declare module '@amedia/user/index-storage.spec' {
381
+ export {};
382
+
383
+ }
384
+ declare module '@amedia/user/index-subscription.spec' {
385
+ export {};
386
+
387
+ }
388
+ declare module '@amedia/user/index' {
389
+ import { hasAccess } from '@amedia/user/actions/authorization';
390
+ export { default as UserDataRequest } from '@amedia/user/lib/UserDataRequest';
391
+ export { default as PaywallUnlockRequest } from '@amedia/user/lib/PaywallUnlockRequest';
392
+ /**
393
+ * This will, if necessary, trigger a redirect to www.aid.no and return
394
+ * to the requestedUrl if supplied or the current url before redirecting away if not.
395
+ * @param requestedUrl
396
+ */
397
+ export const goToLoginPage: (requestedUrl?: string | undefined) => void;
398
+ export const logout: () => Promise<void>;
399
+ export const tryActivateSubscriptionAccess: (requestedAccessFeatures: string[]) => Promise<{
400
+ hasAccess: boolean;
401
+ accessFeatures: string[];
402
+ }>;
403
+ export const updateStorage: (storage: {
404
+ [index: string]: Object;
405
+ }) => void;
406
+ export const saveStorage: (storage: {
407
+ [index: string]: Object;
408
+ }) => void;
409
+
410
+ }
411
+ declare module '@amedia/user/janitor/index' {
412
+ enum JanitorEvents {
413
+ LOADED = "amedia-user.janitor.loaded"
414
+ }
415
+ global {
416
+ interface WindowEventMap {
417
+ [JanitorEvents.LOADED]: CustomEvent<{}>;
418
+ }
419
+ }
420
+ export const runJanitor: () => Promise<void>;
421
+ export {};
422
+
423
+ }
424
+ declare module '@amedia/user/janitor/index.spec' {
425
+ export {};
426
+
427
+ }
428
+ declare module '@amedia/user/janitor/jobs/accessCookieRefresher' {
429
+ export default function accessCookieRefresher(): Promise<[void, void]>;
430
+
431
+ }
432
+ declare module '@amedia/user/janitor/jobs/accessCookieRefresher.spec' {
433
+ export {};
434
+
435
+ }
436
+ declare module '@amedia/user/janitor/jobs/daxsubCookie' {
437
+ import { UserAttributes } from '@amedia/user/types';
438
+ export function getCookieValue(attributes: UserAttributes): string;
439
+ export default function daxSubCookieHandler(): Promise<void>;
440
+
441
+ }
442
+ declare module '@amedia/user/janitor/jobs/daxsubCookie.spec' {
443
+ export {};
444
+
445
+ }
446
+ declare module '@amedia/user/janitor/jobs/removeUserStorage' {
447
+ export function removeUserStorage(): void;
448
+
449
+ }
450
+ declare module '@amedia/user/janitor/jobs/removeUserStorage.spec' {
451
+ export {};
452
+
453
+ }
454
+ declare module '@amedia/user/lib/PaywallUnlockRequest' {
455
+ export type UnlockResponse = {
456
+ isLoggedIn: boolean;
457
+ hasAccess: boolean;
458
+ accessFeatures: string[];
459
+ };
460
+ class PaywallUnlockRequest {
461
+ private requestedAccessFeatures;
462
+ private reload;
463
+ private requestedUrl;
464
+ withAccessFeatures(accessFeatures: string[]): this;
465
+ reloadOnAccess(): this;
466
+ redirectOnAccess(requestedUrl: string): this;
467
+ tryUnlock(): Promise<UnlockResponse>;
468
+ private setAccessCookiesAndGetAccessFeatures;
469
+ private activateAccess;
470
+ }
471
+ export default PaywallUnlockRequest;
472
+
473
+ }
474
+ declare module '@amedia/user/lib/PaywallUnlockRequest.spec' {
475
+ export {};
476
+
477
+ }
478
+ declare module '@amedia/user/lib/UserDataRequest' {
479
+ import { State, UserAttributes } from '@amedia/user/types';
480
+ class UserDataRequest<UA extends UserAttributes, S extends {
481
+ [index: string]: unknown;
482
+ }, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends Record<string, object> = {
483
+ state: State;
484
+ }> {
485
+ private attributes?;
486
+ private namespaces?;
487
+ constructor(attributes?: Attributes | undefined, namespaces?: Namespaces | undefined);
488
+ withAttributes<NewAttributes extends Array<keyof UA>>(attributes: NewAttributes): UserDataRequest<UA, S, (Attributes[number] & NewAttributes[number])[], Namespaces, SubscribeResponse & {
489
+ attributes: Pick<UA, Attributes[number] & NewAttributes[number]>;
490
+ }>;
491
+ withStorage<NewNamespaces extends Array<string>>(namespaces: NewNamespaces): UserDataRequest<UA, S, Attributes, (Namespaces[number] & NewNamespaces[number])[], SubscribeResponse & {
492
+ storage: Pick<S, Namespaces[number] & NewNamespaces[number]>;
493
+ }>;
494
+ subscribe(onData: (data: SubscribeResponse) => void): void;
495
+ fetch(): Promise<SubscribeResponse>;
496
+ private processUserAttributesEvent;
497
+ private processStorageEvent;
498
+ private setupLocalCache;
499
+ }
500
+ export default UserDataRequest;
501
+
502
+ }
503
+ declare module '@amedia/user/lib/UserDataRequest.spec' {
504
+ export {};
505
+
506
+ }
507
+ declare module '@amedia/user/lib/cookie' {
508
+ export const getCookie: (name: string) => string | {
509
+ [index: string]: unknown;
510
+ } | null | undefined;
511
+ export function setCookie(name: string, value?: unknown, validTimeInDateOrDays?: Date | number, path?: string, secure?: boolean): string;
512
+ export function removeCookie(name: string): void;
513
+ /**
514
+ * This function should only be used in tests, as it will remove all cookies a user has on the domain.
515
+ */
516
+ export function removeAllCookies(): void;
517
+
518
+ }
519
+ declare module '@amedia/user/lib/rpc' {
520
+ import { RPCclient } from '@amedia/frontend-rpc';
521
+ interface LocalRPCclient extends RPCclient {
522
+ userAuthenticated: (isLoggedIn: boolean) => void;
523
+ }
524
+ export const getRPCClient: () => LocalRPCclient;
525
+ export {};
526
+
527
+ }
528
+ declare module '@amedia/user/store/index' {
529
+ import { State, UserAttributes } from '@amedia/user/types';
530
+ type StoreDataMap = {
531
+ userAttributes: UserAttributes;
532
+ state: State;
533
+ storage: {
534
+ [namespace: string]: {
535
+ [index: string]: unknown;
536
+ };
537
+ };
538
+ };
539
+ type Listener<T> = (data: T) => void;
540
+ const _default: {
541
+ merge: <K extends keyof StoreDataMap>(key: K, value: Partial<StoreDataMap[K]>) => void;
542
+ set: (key: keyof StoreDataMap, value: UserAttributes | State | {
543
+ [namespace: string]: {
544
+ [index: string]: unknown;
545
+ };
546
+ }) => void;
547
+ get: <K_1 extends keyof StoreDataMap, T = StoreDataMap[K_1]>(key: K_1) => T | undefined;
548
+ on: <K_2 extends keyof StoreDataMap, T_1 = StoreDataMap[K_2]>(key: K_2, listener: Listener<T_1>) => void;
549
+ clear: () => void;
550
+ };
551
+ export default _default;
552
+
553
+ }
554
+ declare module '@amedia/user/store/index.spec' {
555
+ export {};
556
+
557
+ }
558
+ declare module '@amedia/user/types' {
559
+ export type UserAttributes = {
560
+ uuid?: string | null;
561
+ name?: string | null;
562
+ email?: string | null;
563
+ phone?: string | null;
564
+ trackingKey?: string | null;
565
+ extraData?: {
566
+ [index: string]: unknown;
567
+ };
568
+ access?: string[];
569
+ privacyPreferences?: PrivacyPreferences | null;
570
+ };
571
+ export type State = {
572
+ isLoggedIn: boolean;
573
+ emergencyMode?: string[];
574
+ };
575
+ export type PrivacyPreferences = {
576
+ allowResearchUsage: boolean;
577
+ connectWithSurveys: boolean;
578
+ personalizedAds: boolean;
579
+ personalizedContent: boolean;
580
+ };
581
+
582
+ }
583
+ declare module '@amedia/user/utils/customEventWrapper' {
584
+ let rootElement: Window | Element | typeof globalThis;
585
+ export const setRootElement: (element: typeof rootElement) => void;
586
+ /**
587
+ * This listener MUST be used by all listeners in ../eventHandlers
588
+ * We want to ensure that only _one_ instance of this package actually
589
+ * orchestrates data and performs requests against backends.
590
+ * @param type
591
+ * @param listener
592
+ */
593
+ export const listenWithExclusivity: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
594
+ /**
595
+ * Use this for response listeners. (../index.ts) where we want
596
+ * all updates with data - no matter who sent the actual request
597
+ * @param type
598
+ * @param listener
599
+ */
600
+ export const listenForAllEvents: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
601
+ export const dispatch: <T extends Event>(event: T) => void;
602
+ export {};
603
+
604
+ }
605
+ declare module '@amedia/user/utils/debouncer' {
606
+ /**
607
+ * The Debouncer can be used when we want a clean way to say 'I want to fetch this and that, and once it's done,
608
+ * resolve my promise', but instead of the fetch being performed right away, we want to wait for more users to
609
+ * request other stuff. This will keep us from performing lots of individual fetches to the backend.
610
+ *
611
+ * Our main use case is a standard publication front page where one component on the page requests the euucp namespace
612
+ * from Europa, and then another component requests the privacy_preferences namespace. Instead of the Europa client
613
+ * calling two fetches to the server, one for euucp and another for privacy_preferences, we want the Debouncer to
614
+ * aggregate these calls into one call to the backend, that requests both euucp AND privacy_preferences, so the response
615
+ * to both components will be both namespaces (which the Europa client can filter before it actually reaches the
616
+ * component).
617
+ */
618
+ class Debouncer<ParamsType, ResultType> {
619
+ private timeoutMs;
620
+ private defaultParams;
621
+ private paramAccumulator;
622
+ private workload;
623
+ private timer;
624
+ private params;
625
+ private queue;
626
+ constructor(timeoutMs: number, defaultParams: ParamsType, paramAccumulator: (previousParams: ParamsType, newParams: ParamsType) => ParamsType, workload: (params: ParamsType) => Promise<ResultType>);
627
+ perform(newParams: ParamsType): Promise<ResultType>;
628
+ static stringListParamsAccumulator(accumulatedParams: string[], newParams: string[]): string[];
629
+ static stringMapParamsAccumulator(previousParams: Record<string, any>, newParams: Record<string, any>): Record<string, any>;
630
+ }
631
+ export default Debouncer;
632
+
633
+ }
634
+ declare module '@amedia/user/utils/debouncer.spec' {
635
+ export {};
636
+
637
+ }
638
+ declare module '@amedia/user/utils/deepEquals' {
639
+ export const deepEquals: (a: unknown, b: unknown) => boolean;
640
+
641
+ }
642
+ declare module '@amedia/user/utils/expectBootLogs' {
643
+ const _default: () => void;
644
+ export default _default;
645
+
646
+ }
647
+ declare module '@amedia/user/utils/getOrUpdate' {
648
+ import { Runtype, Static } from 'runtypes';
649
+ export type DataFetcherWithCacheTTL<T extends Runtype> = Promise<{
650
+ ttl: number;
651
+ data: Static<T>;
652
+ }>;
653
+ export default function getOrUpdate<T extends Runtype>(key: string, schema: T, fetch: () => DataFetcherWithCacheTTL<T>, cacheQualifier?: (cacheData: Static<T>) => boolean): Promise<Static<T>>;
654
+
655
+ }
656
+ declare module '@amedia/user/utils/getOrUpdate.spec' {
657
+ export {};
658
+
659
+ }
660
+ declare module '@amedia/user/utils/localhostCheck' {
661
+ export const isRunningOnLocalhost: () => boolean;
662
+
663
+ }
664
+ declare module '@amedia/user/utils/location' {
665
+ export const reload: () => void;
666
+ export const replace: (requestedUrl: string) => void;
667
+ export const navigateTo: (url: string) => void;
668
+
669
+ }
670
+ declare module '@amedia/user/utils/log' {
671
+ export type Logger = {
672
+ debug: (message: string | Error, context?: any) => void;
673
+ info: (message: string | Error, context?: any) => void;
674
+ warn: (message: string | Error, context?: any) => void;
675
+ error: (message: string | Error, context?: any) => void;
676
+ };
677
+ export const setLogger: (engine: Logger) => void;
678
+ const _default: Logger;
679
+ export default _default;
680
+
681
+ }
682
+ declare module '@amedia/user/utils/log.spec' {
683
+ export {};
684
+
685
+ }
686
+ declare module '@amedia/user/utils/loginState' {
687
+ export const whenLoginStateResolved: () => Promise<boolean>;
688
+ export const whenIsLoggedIn: () => Promise<void>;
689
+
690
+ }
691
+ declare module '@amedia/user/utils/networkError' {
692
+ export const isAbortedNetworkError: (message: string) => boolean;
693
+
694
+ }
695
+ declare module '@amedia/user/utils/queue' {
696
+ const _default: {
697
+ add: (key: string, promiseCallbacks: {
698
+ resolve: (arg0?: any) => void;
699
+ reject: (reason?: any) => void;
700
+ }) => void;
701
+ getAll: (key: string) => {
702
+ resolve: (arg0?: any) => void;
703
+ reject: (reason?: any) => void;
704
+ }[];
705
+ peekQueueSize: (key: string) => number;
706
+ };
707
+ export default _default;
708
+
709
+ }
710
+ declare module '@amedia/user/utils/type' {
711
+ export const isFunction: (argument: unknown) => argument is Function;
712
+ export const isRecord: (argument: unknown) => argument is Record<string, unknown>;
713
+ export const isError: (argument: unknown) => argument is Error;
714
+ export const isString: (argument: unknown) => argument is string;
715
+ export const isNumber: (argument: unknown) => argument is number;
716
+ export const isBoolean: (argument: unknown) => argument is boolean;
717
+
718
+ }
719
+ declare module '@amedia/user/utils/url' {
720
+ export const setCurrentHostname: (hostname: string) => void;
721
+ export const getCurrentHostname: () => string;
722
+ export const getCurrentUrl: () => string;
723
+ export const getCurrentEnvironment: () => string | null;
724
+ export const getCurrentPublicationDomain: () => string;
725
+ export const getAidDomain: () => string;
726
+
727
+ }
728
+ declare module '@amedia/user/utils/url.spec' {
729
+ export {};
730
+
731
+ }
732
+ declare module '@amedia/user' {
733
+ import main = require('@amedia/user/src/index');
734
+ export = main;
735
+ }