@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.
Files changed (61) hide show
  1. package/@types/amedia-frontend-rpc.d.ts +11 -0
  2. package/@types/browserid.d.ts +4 -0
  3. package/checkVersion.js +12 -0
  4. package/dist/actions/authorization.d.ts +5 -5
  5. package/dist/autologin/index.d.ts +4 -0
  6. package/dist/clients/europa.d.ts +3 -7
  7. package/dist/clients/mercuryLog.d.ts +5 -4
  8. package/dist/index.d.ts +78 -35
  9. package/dist/index.esm.js +1 -1
  10. package/dist/index.esm.js.map +3 -3
  11. package/dist/index.js +1 -1
  12. package/dist/index.js.map +3 -3
  13. package/dist/janitor/jobs/daxsubCookie.d.ts +2 -1
  14. package/dist/lib/PaywallUnlockRequest.d.ts +1 -1
  15. package/dist/lib/UserDataRequest.d.ts +1 -1
  16. package/dist/lib/rpc.d.ts +5 -5
  17. package/dist/utils/customEventWrapper.d.ts +5 -3
  18. package/dist/utils/debouncer.d.ts +26 -0
  19. package/dist/utils/debouncer.spec.d.ts +1 -0
  20. package/dist/utils/deepEquals.d.ts +0 -3
  21. package/dist/utils/log.d.ts +4 -4
  22. package/dist/utils/queue.d.ts +2 -2
  23. package/dist/utils/type.d.ts +6 -0
  24. package/eik.json +1 -1
  25. package/package.json +4 -3
  26. package/src/actions/authorization.spec.ts +13 -9
  27. package/src/actions/authorization.ts +7 -5
  28. package/src/autologin/index.spec.ts +3 -3
  29. package/src/autologin/index.ts +6 -1
  30. package/src/cache/index.spec.ts +2 -2
  31. package/src/cache/index.ts +1 -2
  32. package/src/clients/europa.spec.ts +11 -16
  33. package/src/clients/europa.ts +47 -41
  34. package/src/clients/mercuryLog.ts +22 -12
  35. package/src/clients/pluto.spec.ts +4 -3
  36. package/src/eventHandlers/state.spec.ts +2 -2
  37. package/src/eventHandlers/storage.spec.ts +2 -2
  38. package/src/eventHandlers/userAttributes.spec.ts +2 -2
  39. package/src/index-authentcation.spec.ts +1 -1
  40. package/src/index-storage.spec.ts +3 -3
  41. package/src/index-subscription.spec.ts +1 -1
  42. package/src/janitor/jobs/accessCookieRefresher.spec.ts +8 -2
  43. package/src/janitor/jobs/daxsubCookie.spec.ts +8 -2
  44. package/src/janitor/jobs/daxsubCookie.ts +4 -3
  45. package/src/lib/PaywallUnlockRequest.spec.ts +12 -12
  46. package/src/lib/PaywallUnlockRequest.ts +6 -3
  47. package/src/lib/UserDataRequest.spec.ts +3 -2
  48. package/src/lib/UserDataRequest.ts +4 -4
  49. package/src/lib/rpc.ts +7 -9
  50. package/src/store/index.ts +2 -0
  51. package/src/utils/customEventWrapper.ts +6 -6
  52. package/src/utils/debouncer.spec.ts +257 -0
  53. package/src/utils/debouncer.ts +103 -0
  54. package/src/utils/deepEquals.ts +12 -11
  55. package/src/utils/getOrUpdate.ts +1 -1
  56. package/src/utils/log.spec.ts +4 -4
  57. package/src/utils/log.ts +24 -13
  58. package/src/utils/queue.ts +4 -4
  59. package/src/utils/type.ts +19 -0
  60. package/tsconfig.eslint.json +2 -0
  61. package/tsconfig.json +2 -1
@@ -0,0 +1,11 @@
1
+ declare module '@amedia/frontend-rpc' {
2
+ class RPCclient {
3
+ constructor(config: {
4
+ version: string;
5
+ component: string;
6
+ methods?: string[];
7
+ });
8
+
9
+ addMethod(method: string): void;
10
+ }
11
+ }
@@ -0,0 +1,4 @@
1
+ declare module "@amedia/browserid" {
2
+ // Not complete
3
+ export function getBrowserId(): Promise<string>;
4
+ }
@@ -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: any) => Promise<SetCookieResponse>;
10
- export declare const setNonUserAccessCookie: (publicationDomain: any) => Promise<SetCookieResponse>;
11
- export declare const setAccessCookies: (publicationDomain: any) => Promise<SetCookieResponse>;
12
- export declare const setHasPerformedPaywallReload: (requestedUrl?: any) => void;
13
- export declare const hasRecentlyPerformedPaywallReload: (requestedUrl?: any) => boolean;
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>;
@@ -1,7 +1,5 @@
1
- import { Record, Unknown, Dictionary } from 'runtypes';
2
- export declare const EuropaSchema: Record<{
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
- namespaces: {
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: Object) => void;
3
- warn: (message: string, context: Object) => void;
4
- info: (message: string, context: Object) => void;
5
- debug: (message: string, context: Object) => void;
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: any) => Promise<SetCookieResponse>;
25
- export const setNonUserAccessCookie: (publicationDomain: any) => Promise<SetCookieResponse>;
26
- export const setAccessCookies: (publicationDomain: any) => Promise<SetCookieResponse>;
27
- export const setHasPerformedPaywallReload: (requestedUrl?: any) => void;
28
- export const hasRecentlyPerformedPaywallReload: (requestedUrl?: any) => boolean;
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 { Record, Unknown, Dictionary } from 'runtypes';
159
- export const EuropaSchema: Record<{
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
- namespaces: {
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: Object) => void;
245
- warn: (message: string, context: Object) => void;
246
- info: (message: string, context: Object) => void;
247
- debug: (message: string, context: Object) => void;
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
- export function getCookieValue(attributes: any): string;
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
- let rpcSessionClient: {
544
- addMethod: (methodName: string) => void;
545
- userAuthenticated: (boolean: any) => void;
546
- };
547
- export const getRPCClient: () => Pick<typeof rpcSessionClient, 'userAuthenticated'>;
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
- export const setRootElement: (element: any) => void;
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: Window, ev: WindowEventMap[T]) => void) => void;
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: Window, ev: WindowEventMap[T]) => void) => void;
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/deepEquals' {
630
+ declare module '@amedia/user/utils/debouncer' {
627
631
  /**
628
- * @see https://dev.to/sanderdebr/deep-equality-checking-of-objects-in-vanilla-javascript-5592
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?: Object) => void;
655
- info: (message: string | Error, context?: Object) => void;
656
- warn: (message: string | Error, context?: Object) => void;
657
- error: (message: string | Error, context?: Object) => void;
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: (PromiseLike: any) => void;
714
+ resolve: (arg0?: any) => void;
681
715
  reject: (reason?: any) => void;
682
716
  }) => void;
683
717
  getAll: (key: string) => {
684
- resolve: (PromiseLike: any) => void;
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;