@amedia/user 0.13.25 → 0.13.27
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/@types/amedia-frontend-rpc.d.ts +11 -0
- package/@types/browserid.d.ts +4 -0
- package/checkVersion.js +12 -0
- package/dist/actions/authorization.d.ts +5 -5
- package/dist/autologin/index.d.ts +4 -0
- package/dist/clients/europa.d.ts +3 -7
- package/dist/clients/mercuryLog.d.ts +5 -4
- package/dist/index.d.ts +78 -35
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/janitor/jobs/daxsubCookie.d.ts +2 -1
- package/dist/lib/PaywallUnlockRequest.d.ts +1 -1
- package/dist/lib/UserDataRequest.d.ts +1 -1
- package/dist/lib/rpc.d.ts +5 -5
- package/dist/utils/customEventWrapper.d.ts +5 -3
- package/dist/utils/debouncer.d.ts +26 -0
- package/dist/utils/debouncer.spec.d.ts +1 -0
- package/dist/utils/deepEquals.d.ts +0 -3
- package/dist/utils/log.d.ts +4 -4
- package/dist/utils/queue.d.ts +2 -2
- package/dist/utils/type.d.ts +6 -0
- package/eik.json +1 -1
- package/package.json +4 -3
- package/src/actions/authorization.spec.ts +13 -9
- package/src/actions/authorization.ts +7 -5
- package/src/autologin/index.spec.ts +3 -3
- package/src/autologin/index.ts +6 -1
- package/src/cache/index.spec.ts +2 -2
- package/src/cache/index.ts +1 -2
- package/src/clients/europa.spec.ts +11 -16
- package/src/clients/europa.ts +47 -41
- package/src/clients/mercuryLog.ts +22 -12
- package/src/clients/pluto.spec.ts +4 -3
- package/src/eventHandlers/state.spec.ts +2 -2
- package/src/eventHandlers/storage.spec.ts +2 -2
- package/src/eventHandlers/userAttributes.spec.ts +2 -2
- package/src/index-authentcation.spec.ts +1 -1
- package/src/index-storage.spec.ts +3 -3
- package/src/index-subscription.spec.ts +1 -1
- package/src/janitor/jobs/accessCookieRefresher.spec.ts +8 -2
- package/src/janitor/jobs/daxsubCookie.spec.ts +8 -2
- package/src/janitor/jobs/daxsubCookie.ts +4 -3
- package/src/lib/PaywallUnlockRequest.spec.ts +12 -12
- package/src/lib/PaywallUnlockRequest.ts +6 -3
- package/src/lib/UserDataRequest.spec.ts +3 -2
- package/src/lib/UserDataRequest.ts +4 -4
- package/src/lib/rpc.ts +7 -9
- package/src/store/index.ts +2 -0
- package/src/utils/customEventWrapper.ts +6 -6
- package/src/utils/debouncer.spec.ts +257 -0
- package/src/utils/debouncer.ts +103 -0
- package/src/utils/deepEquals.ts +12 -11
- package/src/utils/getOrUpdate.ts +1 -1
- package/src/utils/log.spec.ts +4 -4
- package/src/utils/log.ts +24 -13
- package/src/utils/queue.ts +4 -4
- package/src/utils/type.ts +19 -0
- package/tsconfig.eslint.json +2 -0
- package/tsconfig.json +2 -1
package/checkVersion.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const pkg = require('./package.json');
|
|
2
|
+
const eik = require('./eik.json');
|
|
3
|
+
|
|
4
|
+
const FgRed = '\x1b[31m';
|
|
5
|
+
|
|
6
|
+
if (pkg.version !== eik.version) {
|
|
7
|
+
console.warn(`NPM: ${pkg.version} vs. ${eik.version} :EIK`);
|
|
8
|
+
console.error(
|
|
9
|
+
`${FgRed}NPM and EIK package versions must be identical. Exiting\n`
|
|
10
|
+
);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
@@ -6,9 +6,9 @@ declare type SetCookieResponse = {
|
|
|
6
6
|
export declare const getAccess: (accessFeatures?: string[]) => Promise<Pick<UserAttributes, 'access'>>;
|
|
7
7
|
export declare const activate: (accessFeatures: string[]) => Promise<string[]>;
|
|
8
8
|
export declare const hasAccess: (currentAccessFeatures: string[], requestedAccessFeatures: string[]) => boolean;
|
|
9
|
-
export declare const setUserAccessCookie: (publicationDomain:
|
|
10
|
-
export declare const setNonUserAccessCookie: (publicationDomain:
|
|
11
|
-
export declare const setAccessCookies: (publicationDomain:
|
|
12
|
-
export declare const setHasPerformedPaywallReload: (requestedUrl?:
|
|
13
|
-
export declare const hasRecentlyPerformedPaywallReload: (requestedUrl?:
|
|
9
|
+
export declare const setUserAccessCookie: (publicationDomain: string) => Promise<SetCookieResponse>;
|
|
10
|
+
export declare const setNonUserAccessCookie: (publicationDomain: string) => Promise<SetCookieResponse>;
|
|
11
|
+
export declare const setAccessCookies: (publicationDomain: string) => Promise<SetCookieResponse>;
|
|
12
|
+
export declare const setHasPerformedPaywallReload: (requestedUrl?: string | undefined) => void;
|
|
13
|
+
export declare const hasRecentlyPerformedPaywallReload: (requestedUrl?: string | undefined) => boolean;
|
|
14
14
|
export {};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export declare type Strategies = Array<{
|
|
2
|
+
name: string;
|
|
3
|
+
handler: () => Promise<boolean>;
|
|
4
|
+
}>;
|
|
1
5
|
export declare const AUTOLOGIN_COOKIE_TTL = 60000;
|
|
2
6
|
export declare const attemptAutoLoginJob: () => Promise<void>;
|
|
3
7
|
export declare const attemptPaywallAutoLogin: () => Promise<void>;
|
package/dist/clients/europa.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const EuropaSchema:
|
|
3
|
-
namespaces: Dictionary<Unknown, string>;
|
|
4
|
-
}, false>;
|
|
1
|
+
import { Unknown, Dictionary } from 'runtypes';
|
|
2
|
+
export declare const EuropaSchema: Dictionary<Unknown, string>;
|
|
5
3
|
export declare const clearLocalCache: () => Promise<void>;
|
|
6
4
|
export declare const updateNamespace: (namespace: string, data: Object) => Promise<void | {}>;
|
|
7
5
|
export declare const getNamespaces: <S extends {
|
|
@@ -17,9 +15,7 @@ export declare const saveNamespace: (namespace: string, data: Object) => Promise
|
|
|
17
15
|
};
|
|
18
16
|
}, string>>;
|
|
19
17
|
export declare const getAllNamespaces: () => Promise<{
|
|
20
|
-
|
|
21
|
-
[x: string]: unknown;
|
|
22
|
-
};
|
|
18
|
+
[x: string]: unknown;
|
|
23
19
|
}>;
|
|
24
20
|
export declare const deleteNamespaceKey: (namespace: string, key: string) => Promise<Pick<{
|
|
25
21
|
[namespace: string]: {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
declare type Context = Record<string, unknown>;
|
|
1
2
|
declare const log: {
|
|
2
|
-
error: (message: string, context:
|
|
3
|
-
warn: (message: string, context:
|
|
4
|
-
info: (message: string, context:
|
|
5
|
-
debug: (message: string, context:
|
|
3
|
+
error: (message: string, context: Context) => void;
|
|
4
|
+
warn: (message: string, context: Context) => void;
|
|
5
|
+
info: (message: string, context: Context) => void;
|
|
6
|
+
debug: (message: string, context: Context) => void;
|
|
6
7
|
};
|
|
7
8
|
export default log;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,11 +21,11 @@ declare module '@amedia/user/actions/authorization' {
|
|
|
21
21
|
export const getAccess: (accessFeatures?: string[]) => Promise<Pick<UserAttributes, 'access'>>;
|
|
22
22
|
export const activate: (accessFeatures: string[]) => Promise<string[]>;
|
|
23
23
|
export const hasAccess: (currentAccessFeatures: string[], requestedAccessFeatures: string[]) => boolean;
|
|
24
|
-
export const setUserAccessCookie: (publicationDomain:
|
|
25
|
-
export const setNonUserAccessCookie: (publicationDomain:
|
|
26
|
-
export const setAccessCookies: (publicationDomain:
|
|
27
|
-
export const setHasPerformedPaywallReload: (requestedUrl?:
|
|
28
|
-
export const hasRecentlyPerformedPaywallReload: (requestedUrl?:
|
|
24
|
+
export const setUserAccessCookie: (publicationDomain: string) => Promise<SetCookieResponse>;
|
|
25
|
+
export const setNonUserAccessCookie: (publicationDomain: string) => Promise<SetCookieResponse>;
|
|
26
|
+
export const setAccessCookies: (publicationDomain: string) => Promise<SetCookieResponse>;
|
|
27
|
+
export const setHasPerformedPaywallReload: (requestedUrl?: string | undefined) => void;
|
|
28
|
+
export const hasRecentlyPerformedPaywallReload: (requestedUrl?: string | undefined) => boolean;
|
|
29
29
|
export {};
|
|
30
30
|
|
|
31
31
|
}
|
|
@@ -69,6 +69,10 @@ declare module '@amedia/user/actions/userData.spec' {
|
|
|
69
69
|
|
|
70
70
|
}
|
|
71
71
|
declare module '@amedia/user/autologin/index' {
|
|
72
|
+
export type Strategies = Array<{
|
|
73
|
+
name: string;
|
|
74
|
+
handler: () => Promise<boolean>;
|
|
75
|
+
}>;
|
|
72
76
|
export const AUTOLOGIN_COOKIE_TTL = 60000;
|
|
73
77
|
export const attemptAutoLoginJob: () => Promise<void>;
|
|
74
78
|
export const attemptPaywallAutoLogin: () => Promise<void>;
|
|
@@ -155,10 +159,8 @@ declare module '@amedia/user/cache/types' {
|
|
|
155
159
|
|
|
156
160
|
}
|
|
157
161
|
declare module '@amedia/user/clients/europa' {
|
|
158
|
-
import {
|
|
159
|
-
export const EuropaSchema:
|
|
160
|
-
namespaces: Dictionary<Unknown, string>;
|
|
161
|
-
}, false>;
|
|
162
|
+
import { Unknown, Dictionary } from 'runtypes';
|
|
163
|
+
export const EuropaSchema: Dictionary<Unknown, string>;
|
|
162
164
|
export const clearLocalCache: () => Promise<void>;
|
|
163
165
|
export const updateNamespace: (namespace: string, data: Object) => Promise<void | {}>;
|
|
164
166
|
export const getNamespaces: <S extends {
|
|
@@ -174,9 +176,7 @@ declare module '@amedia/user/clients/europa' {
|
|
|
174
176
|
};
|
|
175
177
|
}, string>>;
|
|
176
178
|
export const getAllNamespaces: () => Promise<{
|
|
177
|
-
|
|
178
|
-
[x: string]: unknown;
|
|
179
|
-
};
|
|
179
|
+
[x: string]: unknown;
|
|
180
180
|
}>;
|
|
181
181
|
export const deleteNamespaceKey: (namespace: string, key: string) => Promise<Pick<{
|
|
182
182
|
[namespace: string]: {
|
|
@@ -240,11 +240,12 @@ declare module '@amedia/user/clients/mercury.spec' {
|
|
|
240
240
|
|
|
241
241
|
}
|
|
242
242
|
declare module '@amedia/user/clients/mercuryLog' {
|
|
243
|
+
type Context = Record<string, unknown>;
|
|
243
244
|
const log: {
|
|
244
|
-
error: (message: string, context:
|
|
245
|
-
warn: (message: string, context:
|
|
246
|
-
info: (message: string, context:
|
|
247
|
-
debug: (message: string, context:
|
|
245
|
+
error: (message: string, context: Context) => void;
|
|
246
|
+
warn: (message: string, context: Context) => void;
|
|
247
|
+
info: (message: string, context: Context) => void;
|
|
248
|
+
debug: (message: string, context: Context) => void;
|
|
248
249
|
};
|
|
249
250
|
export default log;
|
|
250
251
|
|
|
@@ -452,7 +453,8 @@ declare module '@amedia/user/janitor/jobs/accessCookieRefresher.spec' {
|
|
|
452
453
|
|
|
453
454
|
}
|
|
454
455
|
declare module '@amedia/user/janitor/jobs/daxsubCookie' {
|
|
455
|
-
|
|
456
|
+
import { UserAttributes } from '@amedia/user/types';
|
|
457
|
+
export function getCookieValue(attributes: UserAttributes): string;
|
|
456
458
|
export default function daxSubCookieHandler(): Promise<void>;
|
|
457
459
|
|
|
458
460
|
}
|
|
@@ -472,7 +474,7 @@ declare module '@amedia/user/janitor/jobs/removeUserStorage.spec' {
|
|
|
472
474
|
|
|
473
475
|
}
|
|
474
476
|
declare module '@amedia/user/lib/PaywallUnlockRequest' {
|
|
475
|
-
type UnlockResponse = {
|
|
477
|
+
export type UnlockResponse = {
|
|
476
478
|
isLoggedIn: boolean;
|
|
477
479
|
hasAccess: boolean;
|
|
478
480
|
accessFeatures: string[];
|
|
@@ -502,7 +504,7 @@ declare module '@amedia/user/lib/UserDataRequest' {
|
|
|
502
504
|
import { State, UserAttributes } from '@amedia/user/types';
|
|
503
505
|
class UserDataRequest<UA extends UserAttributes, S extends {
|
|
504
506
|
[index: string]: unknown;
|
|
505
|
-
}, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends
|
|
507
|
+
}, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends Record<string, object> = {
|
|
506
508
|
state: State;
|
|
507
509
|
}> {
|
|
508
510
|
private attributes?;
|
|
@@ -540,11 +542,11 @@ declare module '@amedia/user/lib/cookie' {
|
|
|
540
542
|
|
|
541
543
|
}
|
|
542
544
|
declare module '@amedia/user/lib/rpc' {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
userAuthenticated: (
|
|
546
|
-
}
|
|
547
|
-
export const getRPCClient: () =>
|
|
545
|
+
import { RPCclient } from '@amedia/frontend-rpc';
|
|
546
|
+
interface LocalRPCclient extends RPCclient {
|
|
547
|
+
userAuthenticated: (isLoggedIn: boolean) => void;
|
|
548
|
+
}
|
|
549
|
+
export const getRPCClient: () => LocalRPCclient;
|
|
548
550
|
export {};
|
|
549
551
|
|
|
550
552
|
}
|
|
@@ -604,7 +606,8 @@ declare module '@amedia/user/types' {
|
|
|
604
606
|
|
|
605
607
|
}
|
|
606
608
|
declare module '@amedia/user/utils/customEventWrapper' {
|
|
607
|
-
|
|
609
|
+
let rootElement: Window | Element;
|
|
610
|
+
export const setRootElement: (element: typeof rootElement) => void;
|
|
608
611
|
/**
|
|
609
612
|
* This listener MUST be used by all listeners in ../eventHandlers
|
|
610
613
|
* We want to ensure that only _one_ instance of this package actually
|
|
@@ -612,21 +615,52 @@ declare module '@amedia/user/utils/customEventWrapper' {
|
|
|
612
615
|
* @param type
|
|
613
616
|
* @param listener
|
|
614
617
|
*/
|
|
615
|
-
export const listenWithExclusivity: <T extends keyof WindowEventMap>(type: T, listener: (this:
|
|
618
|
+
export const listenWithExclusivity: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
|
|
616
619
|
/**
|
|
617
620
|
* Use this for response listeners. (../index.ts) where we want
|
|
618
621
|
* all updates with data - no matter who sent the actual request
|
|
619
622
|
* @param type
|
|
620
623
|
* @param listener
|
|
621
624
|
*/
|
|
622
|
-
export const listenForAllEvents: <T extends keyof WindowEventMap>(type: T, listener: (this:
|
|
625
|
+
export const listenForAllEvents: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
|
|
623
626
|
export const dispatch: <T extends Event>(event: T) => void;
|
|
627
|
+
export {};
|
|
624
628
|
|
|
625
629
|
}
|
|
626
|
-
declare module '@amedia/user/utils/
|
|
630
|
+
declare module '@amedia/user/utils/debouncer' {
|
|
627
631
|
/**
|
|
628
|
-
*
|
|
632
|
+
* 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,
|
|
633
|
+
* resolve my promise', but instead of the fetch being performed right away, we want to wait for more users to
|
|
634
|
+
* request other stuff. This will keep us from performing lots of individual fetches to the backend.
|
|
635
|
+
*
|
|
636
|
+
* Our main use case is a standard publication front page where one component on the page requests the euucp namespace
|
|
637
|
+
* from Europa, and then another component requests the privacy_preferences namespace. Instead of the Europa client
|
|
638
|
+
* calling two fetches to the server, one for euucp and another for privacy_preferences, we want the Debouncer to
|
|
639
|
+
* aggregate these calls into one call to the backend, that requests both euucp AND privacy_preferences, so the response
|
|
640
|
+
* to both components will be both namespaces (which the Europa client can filter before it actually reaches the
|
|
641
|
+
* component).
|
|
629
642
|
*/
|
|
643
|
+
class Debouncer<ParamsType, ResultType> {
|
|
644
|
+
private timeoutMs;
|
|
645
|
+
private defaultParams;
|
|
646
|
+
private paramAccumulator;
|
|
647
|
+
private workload;
|
|
648
|
+
private timer;
|
|
649
|
+
private params;
|
|
650
|
+
private queue;
|
|
651
|
+
constructor(timeoutMs: number, defaultParams: ParamsType, paramAccumulator: (previousParams: ParamsType, newParams: ParamsType) => ParamsType, workload: (params: ParamsType) => Promise<ResultType>);
|
|
652
|
+
perform(newParams: ParamsType): Promise<ResultType>;
|
|
653
|
+
static stringListParamsAccumulator(accumulatedParams: string[], newParams: string[]): string[];
|
|
654
|
+
static stringMapParamsAccumulator(previousParams: Record<string, any>, newParams: Record<string, any>): Record<string, any>;
|
|
655
|
+
}
|
|
656
|
+
export default Debouncer;
|
|
657
|
+
|
|
658
|
+
}
|
|
659
|
+
declare module '@amedia/user/utils/debouncer.spec' {
|
|
660
|
+
export {};
|
|
661
|
+
|
|
662
|
+
}
|
|
663
|
+
declare module '@amedia/user/utils/deepEquals' {
|
|
630
664
|
export const deepEquals: (a: unknown, b: unknown) => boolean;
|
|
631
665
|
|
|
632
666
|
}
|
|
@@ -651,10 +685,10 @@ declare module '@amedia/user/utils/location' {
|
|
|
651
685
|
}
|
|
652
686
|
declare module '@amedia/user/utils/log' {
|
|
653
687
|
export type Logger = {
|
|
654
|
-
debug: (message: string | Error, context?:
|
|
655
|
-
info: (message: string | Error, context?:
|
|
656
|
-
warn: (message: string | Error, context?:
|
|
657
|
-
error: (message: string | Error, context?:
|
|
688
|
+
debug: (message: string | Error, context?: any) => void;
|
|
689
|
+
info: (message: string | Error, context?: any) => void;
|
|
690
|
+
warn: (message: string | Error, context?: any) => void;
|
|
691
|
+
error: (message: string | Error, context?: any) => void;
|
|
658
692
|
};
|
|
659
693
|
export const setLogger: (engine: Logger) => void;
|
|
660
694
|
const _default: Logger;
|
|
@@ -677,17 +711,26 @@ declare module '@amedia/user/utils/networkError' {
|
|
|
677
711
|
declare module '@amedia/user/utils/queue' {
|
|
678
712
|
const _default: {
|
|
679
713
|
add: (key: string, promiseCallbacks: {
|
|
680
|
-
resolve: (
|
|
714
|
+
resolve: (arg0?: any) => void;
|
|
681
715
|
reject: (reason?: any) => void;
|
|
682
716
|
}) => void;
|
|
683
717
|
getAll: (key: string) => {
|
|
684
|
-
resolve: (
|
|
718
|
+
resolve: (arg0?: any) => void;
|
|
685
719
|
reject: (reason?: any) => void;
|
|
686
720
|
}[];
|
|
687
721
|
peekQueueSize: (key: string) => number;
|
|
688
722
|
};
|
|
689
723
|
export default _default;
|
|
690
724
|
|
|
725
|
+
}
|
|
726
|
+
declare module '@amedia/user/utils/type' {
|
|
727
|
+
export const isFunction: (argument: unknown) => argument is Function;
|
|
728
|
+
export const isRecord: (argument: unknown) => argument is Record<string, unknown>;
|
|
729
|
+
export const isError: (argument: unknown) => argument is Error;
|
|
730
|
+
export const isString: (argument: unknown) => argument is string;
|
|
731
|
+
export const isNumber: (argument: unknown) => argument is number;
|
|
732
|
+
export const isBoolean: (argument: unknown) => argument is boolean;
|
|
733
|
+
|
|
691
734
|
}
|
|
692
735
|
declare module '@amedia/user/utils/url' {
|
|
693
736
|
export const setCurrentHostname: (hostname: string) => void;
|