@amedia/user 0.13.31 → 0.13.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.
Files changed (129) hide show
  1. package/README.md +2 -1
  2. package/dist/actions/authentication.spec.d.ts +0 -3
  3. package/dist/autologin/index.spec.d.ts +0 -3
  4. package/dist/cache/engines/global.d.ts +17 -0
  5. package/dist/cache/index.spec.d.ts +0 -3
  6. package/dist/clients/mercury.spec.d.ts +0 -3
  7. package/dist/clients/mercuryLog.spec.d.ts +0 -3
  8. package/dist/eventHandlers/state.spec.d.ts +0 -3
  9. package/dist/eventHandlers/storage.spec.d.ts +0 -3
  10. package/dist/eventHandlers/userAttributes.spec.d.ts +0 -3
  11. package/dist/index-authentcation.spec.d.ts +0 -3
  12. package/dist/index-storage.spec.d.ts +0 -3
  13. package/dist/index-subscription.spec.d.ts +0 -3
  14. package/dist/index.d.ts +30 -42
  15. package/dist/index.esm.js +1 -1
  16. package/dist/index.esm.js.map +3 -3
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +3 -3
  19. package/dist/janitor/index.spec.d.ts +0 -3
  20. package/dist/janitor/jobs/accessCookieRefresher.spec.d.ts +0 -3
  21. package/dist/janitor/jobs/daxsubCookie.spec.d.ts +0 -3
  22. package/dist/lib/PaywallUnlockRequest.spec.d.ts +0 -3
  23. package/dist/utils/expectBootLogs.d.ts +2 -0
  24. package/dist/utils/localhostCheck.d.ts +1 -0
  25. package/eik.json +1 -1
  26. package/jest.config.js +2 -1
  27. package/package.json +2 -2
  28. package/setupJest.js +0 -5
  29. package/src/actions/authentication.spec.ts +0 -6
  30. package/src/actions/authorization.spec.ts +0 -4
  31. package/src/actions/preferences.spec.ts +0 -1
  32. package/src/actions/userData.spec.ts +0 -6
  33. package/src/autologin/index.spec.ts +1 -11
  34. package/src/autologin/thirdPartyCookie.spec.ts +0 -5
  35. package/src/cache/engines/global.ts +15 -0
  36. package/src/cache/index.spec.ts +0 -6
  37. package/src/clients/europa.spec.ts +0 -3
  38. package/src/clients/jupiter.spec.ts +0 -3
  39. package/src/clients/mercury.spec.ts +0 -10
  40. package/src/clients/mercuryLog.spec.ts +0 -10
  41. package/src/clients/nebula.spec.ts +0 -3
  42. package/src/clients/pluto.spec.ts +0 -3
  43. package/src/eventHandlers/activation.ts +5 -1
  44. package/src/eventHandlers/state.spec.ts +1 -12
  45. package/src/eventHandlers/storage.spec.ts +1 -12
  46. package/src/eventHandlers/userAttributes.spec.ts +1 -12
  47. package/src/index-authentcation.spec.ts +0 -14
  48. package/src/index-storage.spec.ts +1 -15
  49. package/src/index-subscription.spec.ts +1 -15
  50. package/src/index.ts +7 -4
  51. package/src/janitor/index.spec.ts +18 -0
  52. package/src/janitor/index.ts +9 -0
  53. package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -8
  54. package/src/janitor/jobs/daxsubCookie.spec.ts +1 -15
  55. package/src/janitor/jobs/removeUserStorage.spec.ts +0 -5
  56. package/src/lib/PaywallUnlockRequest.spec.ts +17 -14
  57. package/src/lib/PaywallUnlockRequest.ts +6 -0
  58. package/src/lib/UserDataRequest.spec.ts +16 -11
  59. package/src/lib/UserDataRequest.ts +9 -1
  60. package/src/utils/debouncer.spec.ts +0 -5
  61. package/src/utils/expectBootLogs.ts +9 -0
  62. package/src/utils/getOrUpdate.spec.ts +0 -2
  63. package/src/utils/localhostCheck.ts +9 -0
  64. package/src/utils/log.spec.ts +0 -5
  65. package/testSetup.js +18 -0
  66. package/@types/global.d.ts +0 -15
  67. package/amedia-user-js.iml +0 -9
  68. package/dist/cache/engines/indexeddb.d.ts +0 -7
  69. package/dist/index.js.LICENSE.txt +0 -14
  70. package/dist/lib/PaywallUnlocker.d.ts +0 -16
  71. package/dist/lib/PaywallUnlocker.spec.d.ts +0 -4
  72. package/dist/lib/User.d.ts +0 -21
  73. package/dist/utils/logValidationError.d.ts +0 -1
  74. package/esm/actions/authentication.d.ts +0 -5
  75. package/esm/actions/authentication.spec.d.ts +0 -4
  76. package/esm/actions/authorization.d.ts +0 -9
  77. package/esm/actions/preferences.d.ts +0 -9
  78. package/esm/actions/preferences.spec.d.ts +0 -1
  79. package/esm/actions/storage.d.ts +0 -4
  80. package/esm/actions/userData.d.ts +0 -2
  81. package/esm/autologin/index.d.ts +0 -1
  82. package/esm/autologin/thirdPartyCookie.d.ts +0 -3
  83. package/esm/autologin/thirdPartyCookie.spec.d.ts +0 -1
  84. package/esm/cache/engines/global.d.ts +0 -21
  85. package/esm/cache/engines/global.spec.d.ts +0 -1
  86. package/esm/cache/engines/indexeddb.d.ts +0 -7
  87. package/esm/cache/index.d.ts +0 -11
  88. package/esm/cache/index.spec.d.ts +0 -4
  89. package/esm/cache/types.d.ts +0 -11
  90. package/esm/clients/europa.d.ts +0 -28
  91. package/esm/clients/europa.spec.d.ts +0 -1
  92. package/esm/clients/jupiter.d.ts +0 -30
  93. package/esm/clients/jupiter.spec.d.ts +0 -1
  94. package/esm/clients/mercury.d.ts +0 -18
  95. package/esm/clients/mercury.spec.d.ts +0 -4
  96. package/esm/clients/nebula.d.ts +0 -2
  97. package/esm/clients/nebula.spec.d.ts +0 -1
  98. package/esm/clients/pluto.d.ts +0 -3
  99. package/esm/clients/pluto.spec.d.ts +0 -1
  100. package/esm/eventHandlers/activation.d.ts +0 -15
  101. package/esm/eventHandlers/authentication.d.ts +0 -17
  102. package/esm/eventHandlers/userAttributes.d.ts +0 -24
  103. package/esm/exceptions/PaywallError.d.ts +0 -7
  104. package/esm/index-authentcation.spec.d.ts +0 -4
  105. package/esm/index-storage.spec.d.ts +0 -4
  106. package/esm/index-subscription.spec.d.ts +0 -4
  107. package/esm/index.d.ts +0 -26
  108. package/esm/janitor/index.d.ts +0 -10
  109. package/esm/janitor/jobs/accessCookieRefresher.d.ts +0 -1
  110. package/esm/janitor/jobs/accessCookieRefresher.spec.d.ts +0 -4
  111. package/esm/lib/PaywallUnlocker.d.ts +0 -16
  112. package/esm/lib/PaywallUnlocker.spec.d.ts +0 -4
  113. package/esm/lib/User.d.ts +0 -21
  114. package/esm/lib/cookie.d.ts +0 -5
  115. package/esm/lib/rpc.d.ts +0 -6
  116. package/esm/store/index.d.ts +0 -22
  117. package/esm/store/index.spec.d.ts +0 -1
  118. package/esm/types.d.ts +0 -22
  119. package/esm/user.js +0 -2
  120. package/esm/user.js.map +0 -1
  121. package/esm/utils/customEventWrapper.d.ts +0 -17
  122. package/esm/utils/deepEquals.d.ts +0 -4
  123. package/esm/utils/getOrUpdate.d.ts +0 -6
  124. package/esm/utils/getOrUpdate.spec.d.ts +0 -1
  125. package/esm/utils/location.d.ts +0 -3
  126. package/esm/utils/log.d.ts +0 -26
  127. package/esm/utils/queue.d.ts +0 -12
  128. package/esm/utils/url.d.ts +0 -6
  129. package/esm/utils/url.spec.d.ts +0 -1
@@ -1,33 +1,20 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
- import fetch from 'jest-fetch-mock';
6
1
  import PaywallUnlockRequest, { UnlockResponse } from './PaywallUnlockRequest';
7
2
  import * as authorization from '../actions/authorization';
8
3
  import * as location from '../utils/location';
9
4
  import * as autologin from '../autologin';
5
+ import * as localhostCheck from '../utils/localhostCheck';
10
6
  import store from '../store';
11
7
  import PaywallError from '../exceptions/PaywallError';
12
- import { setRootElement } from '../utils/customEventWrapper';
13
8
  import { listenForUserAttributeRequests } from '../eventHandlers/userAttributes';
14
9
  import { listenForStateRequests } from '../eventHandlers/state';
15
10
  import { removeAllCookies } from './cookie';
16
- import restoreAllMocks = jest.restoreAllMocks;
17
11
  import spyOn = jest.spyOn;
18
12
 
19
13
  beforeEach(() => {
20
- restoreAllMocks();
21
- fetch.resetMocks();
22
14
  store.clear();
23
15
 
24
- // We cannot use window as our event root during testing
25
- // since tests are executed in parallel.
26
- setRootElement(new Document().createElement('div'));
27
16
  removeAllCookies();
28
17
 
29
- // Also, since we keep creating new root elements, we also
30
- // need to attach to these new roots.
31
18
  listenForStateRequests();
32
19
  listenForUserAttributeRequests();
33
20
  });
@@ -65,6 +52,22 @@ describe('PaywallUnlocker', () => {
65
52
  spyOn(location, 'replace').mockReturnValue();
66
53
  });
67
54
 
55
+ describe('When running on localhost', () => {
56
+ beforeEach(() => {
57
+ jest.spyOn(localhostCheck, 'isRunningOnLocalhost').mockReturnValue(true);
58
+ });
59
+
60
+ it('should fail with expected error', async () => {
61
+ try {
62
+ await new PaywallUnlockRequest().tryUnlock();
63
+ } catch (e) {
64
+ expect(e).toEqual(
65
+ new Error('@amedia/user cannot unlock paywall on localhost')
66
+ );
67
+ }
68
+ });
69
+ });
70
+
68
71
  describe('When not logged in', () => {
69
72
  let unlockResponse: UnlockResponse;
70
73
  beforeEach(async () => {
@@ -11,6 +11,7 @@ import PaywallError from '../exceptions/PaywallError';
11
11
  import UserDataRequest from './UserDataRequest';
12
12
  import { attemptPaywallAutoLogin } from '../autologin';
13
13
  import { AccessFeatures } from '../clients/jupiter';
14
+ import { isRunningOnLocalhost } from '../utils/localhostCheck';
14
15
 
15
16
  export type UnlockResponse = {
16
17
  isLoggedIn: boolean;
@@ -41,6 +42,11 @@ class PaywallUnlockRequest {
41
42
  }
42
43
 
43
44
  public async tryUnlock(): Promise<UnlockResponse> {
45
+ if (isRunningOnLocalhost()) {
46
+ return Promise.reject(
47
+ new Error('@amedia/user cannot unlock paywall on localhost')
48
+ );
49
+ }
44
50
  const {
45
51
  state: { isLoggedIn },
46
52
  } = await new UserDataRequest().withAttributes(['name']).fetch();
@@ -1,29 +1,34 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
1
  import store from '../store';
5
- import { UserDataRequest } from '../index';
2
+ import UserDataRequest from './UserDataRequest';
6
3
  import { listenForUserAttributeRequests } from '../eventHandlers/userAttributes';
7
4
  import { listenForStateRequests } from '../eventHandlers/state';
8
5
  import { listenForStorageRequests } from '../eventHandlers/storage';
9
- import { setRootElement } from '../utils/customEventWrapper';
10
6
  import * as europa from '../clients/europa';
7
+ import * as localhostCheck from '../utils/localhostCheck';
11
8
 
12
9
  beforeEach(() => {
13
- // We cannot use window as our event root during testing
14
- // since tests are executed in parallel.
15
- setRootElement(new Document().createElement('div'));
16
-
17
10
  store.clear();
18
11
 
19
- // Also, since we keep creating new root elements, we also
20
- // need to attach to these new roots.
21
12
  listenForUserAttributeRequests();
22
13
  listenForStateRequests();
23
14
  listenForStorageRequests();
24
15
  });
25
16
 
26
17
  describe('UserDataRequest', () => {
18
+ describe('When running on localhost', () => {
19
+ beforeEach(() => {
20
+ jest.spyOn(localhostCheck, 'isRunningOnLocalhost').mockReturnValue(true);
21
+ });
22
+
23
+ it('should fail with expected error', async () => {
24
+ try {
25
+ await new UserDataRequest().withAttributes(['name']).fetch();
26
+ } catch (e) {
27
+ expect(e).toEqual(new Error('@amedia/user cannot run on localhost'));
28
+ }
29
+ });
30
+ });
31
+
27
32
  describe('when fetching', () => {
28
33
  describe('and is logged in', () => {
29
34
  beforeEach(() => {
@@ -3,6 +3,7 @@ import { State, UserAttributes } from '../types';
3
3
  import { dispatch, listenForAllEvents } from '../utils/customEventWrapper';
4
4
  import { AmediaUserEvents } from '../eventHandlers/eventMap';
5
5
  import { deepEquals } from '../utils/deepEquals';
6
+ import { isRunningOnLocalhost } from '../utils/localhostCheck';
6
7
 
7
8
  function isMissingData(requestedKeys?: string[], data?: Object) {
8
9
  if (requestedKeys && requestedKeys.length > 0) {
@@ -62,6 +63,10 @@ class UserDataRequest<
62
63
 
63
64
  subscribe(onData: (data: SubscribeResponse) => void): void {
64
65
  let previousData = this.setupLocalCache();
66
+ if (isRunningOnLocalhost()) {
67
+ onData(previousData);
68
+ return;
69
+ }
65
70
  listenForAllEvents(AmediaUserEvents.ON_STATE_UPDATED, (evt) => {
66
71
  const state = evt.detail;
67
72
  if (
@@ -122,7 +127,10 @@ class UserDataRequest<
122
127
  }
123
128
 
124
129
  fetch(): Promise<SubscribeResponse> {
125
- return new Promise<SubscribeResponse>((resolve) => {
130
+ return new Promise<SubscribeResponse>((resolve, reject) => {
131
+ if (isRunningOnLocalhost()) {
132
+ reject(new Error('@amedia/user cannot run on localhost'));
133
+ }
126
134
  this.subscribe((data: any) => {
127
135
  // @ts-ignore
128
136
  if (typeof data.state.isLoggedIn === 'undefined') {
@@ -1,10 +1,5 @@
1
- import restoreAllMocks = jest.restoreAllMocks;
2
1
  import Debouncer from './debouncer';
3
2
 
4
- beforeEach(async () => {
5
- restoreAllMocks();
6
- });
7
-
8
3
  describe('Debouncer', () => {
9
4
  describe('when params is list of arrays and response is key value object', () => {
10
5
  let debouncer: Debouncer<string[], Record<string, string>>;
@@ -0,0 +1,9 @@
1
+ import log from './log';
2
+
3
+ jest.spyOn(log, 'warn').mockImplementation();
4
+
5
+ export default () => {
6
+ expect(log.warn).toHaveBeenCalledWith(
7
+ '@amedia/user started on localhost. In this scenario we have no way to resolve any login-, access- or userdata. Expect errors or redirects if you try.'
8
+ );
9
+ };
@@ -3,12 +3,10 @@ import cache from '../cache';
3
3
  import getOrUpdate from './getOrUpdate';
4
4
  import queue from './queue';
5
5
  import spyOn = jest.spyOn;
6
- import restoreAllMocks = jest.restoreAllMocks;
7
6
 
8
7
  const schema = Partial({ field: String, extraField: String });
9
8
 
10
9
  beforeEach(async () => {
11
- restoreAllMocks();
12
10
  await cache.clear();
13
11
  });
14
12
  describe('getOrUpdate', () => {
@@ -0,0 +1,9 @@
1
+ import log from './log';
2
+
3
+ export const isRunningOnLocalhost = (): boolean => {
4
+ if (globalThis.location.hostname === 'localhost') {
5
+ log.error('@amedia/user cannot work on localhost.');
6
+ return true;
7
+ }
8
+ return false;
9
+ };
@@ -1,9 +1,4 @@
1
1
  import log, { Logger, setLogger } from './log';
2
- import restoreAllMocks = jest.restoreAllMocks;
3
-
4
- beforeEach(() => {
5
- restoreAllMocks();
6
- });
7
2
 
8
3
  describe('Log', () => {
9
4
  let logger: Logger;
package/testSetup.js CHANGED
@@ -1 +1,19 @@
1
1
  require('jest-extended');
2
+ const fetchMocker = require('jest-fetch-mock');
3
+ const localhostCheck = require('./src/utils/localhostCheck');
4
+ const { setLogger } = require('./src/utils/log');
5
+ const { setRootElement } = require('./src/utils/customEventWrapper');
6
+
7
+ setLogger(console);
8
+ self.amediaUserTestMode = true;
9
+
10
+ fetchMocker.enableMocks();
11
+
12
+ beforeEach(() => {
13
+ fetchMocker.resetMocks();
14
+ jest.spyOn(localhostCheck, 'isRunningOnLocalhost').mockReturnValue(false);
15
+
16
+ // We cannot use window/globalThis as our event root during testing
17
+ // since tests are executed in parallel.
18
+ setRootElement(new Document().createElement('div'));
19
+ });
@@ -1,15 +0,0 @@
1
- import { CacheEntry } from '../src/cache/types';
2
-
3
- declare global {
4
- interface Window {
5
- amediaUserCache?: { [index: string]: CacheEntry };
6
- }
7
-
8
- namespace NodeJS {
9
- interface Global {
10
- amediaUserCache?: { [index: string]: CacheEntry };
11
- }
12
- }
13
-
14
- export var amediaUserCache: { [index: string]: CacheEntry };
15
- }
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$" />
6
- <orderEntry type="inheritedJdk" />
7
- <orderEntry type="sourceFolder" forTests="false" />
8
- </component>
9
- </module>
@@ -1,7 +0,0 @@
1
- import { CacheEntry, Engine } from '../types';
2
- export declare const get: (key: string) => Promise<CacheEntry>;
3
- export declare const set: (key: string, data: unknown, expires: number) => Promise<void>;
4
- export declare const remove: (key: string) => Promise<void>;
5
- export declare const clear: () => Promise<void>;
6
- declare const _default: Engine;
7
- export default _default;
@@ -1,14 +0,0 @@
1
- /*!
2
- localForage -- Offline Storage, Improved
3
- Version 1.9.0
4
- https://localforage.github.io/localForage
5
- (c) 2013-2017 Mozilla, Apache License 2.0
6
- */
7
-
8
- /*!
9
- * JavaScript Cookie v2.2.1
10
- * https://github.com/js-cookie/js-cookie
11
- *
12
- * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
13
- * Released under the MIT license
14
- */
@@ -1,16 +0,0 @@
1
- declare class PaywallUnlocker {
2
- private requestedAccessFeatures;
3
- private reload;
4
- private requestedUrl;
5
- withAccessFeatures(accessFeatures: string[]): this;
6
- reloadOnAccess(): this;
7
- redirectOnAccess(requestedUrl: string): this;
8
- tryUnlock(): Promise<{
9
- isLoggedIn: boolean;
10
- hasAccess: boolean;
11
- accessFeatures: string[];
12
- }>;
13
- private resolveActualAccessFeatures;
14
- private setAccessCookiesAndPerformRequestedActions;
15
- }
16
- export default PaywallUnlocker;
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};
@@ -1,21 +0,0 @@
1
- import { State, UserAttributes } from '../types';
2
- declare class User<UA extends UserAttributes, S extends {
3
- [index: string]: unknown;
4
- }, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends {} = {
5
- state: State;
6
- }> {
7
- private attributes?;
8
- private namespaces?;
9
- constructor(attributes?: Attributes | undefined, namespaces?: Namespaces | undefined);
10
- withAttributes<NewAttributes extends Array<keyof UA>>(attributes: NewAttributes): User<UA, S, (Attributes[number] & NewAttributes[number])[], Namespaces, SubscribeResponse & {
11
- attributes: Pick<UA, Attributes[number] & NewAttributes[number]>;
12
- }>;
13
- withStorage<NewNamespaces extends Array<string>>(...namespace: NewNamespaces): User<UA, S, Attributes, (Namespaces[number] & NewNamespaces[number])[], SubscribeResponse & {
14
- storage: Pick<S, Namespaces[number] & NewNamespaces[number]>;
15
- }>;
16
- subscribe(onData: (data: SubscribeResponse) => void): void;
17
- private processUserAttributesEvent;
18
- private processStorageEvent;
19
- private setupLocalCache;
20
- }
21
- export default User;
@@ -1 +0,0 @@
1
- export default function logValidationError(name: string, error: Error, extra?: Object): void;
@@ -1,5 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const login: (requestedUrl: URL | string) => void;
3
- export declare const logout: () => Promise<void>;
4
- export declare const getSession: () => Promise<UserAttributes>;
5
- export declare const isLoggedIn: () => boolean;
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};
@@ -1,9 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const getAccess: (accessFeatures?: string[]) => Promise<Pick<UserAttributes, 'access'>>;
3
- export declare const activate: (accessFeatures: string[]) => Promise<boolean>;
4
- export declare const hasAccess: (currentAccessFeatures: string[], requestedAccessFeatures: string[]) => boolean;
5
- export declare const setUserAccessCookie: (publicationDomain: any) => Promise<boolean>;
6
- export declare const setNonUserAccessCookie: (publicationDomain: any) => Promise<boolean>;
7
- export declare const hasRecentlyTriedToUnlockPaywall: () => boolean;
8
- export declare const setAccessCookies: (publicationDomain: any) => Promise<boolean>;
9
- export declare const setHasTriedToUnlockPaywall: () => void;
@@ -1,9 +0,0 @@
1
- import { Record, Boolean } from 'runtypes';
2
- import { UserAttributes } from '../types';
3
- export declare const PrivacyPreferencesSchema: Record<{
4
- allowResearchUsage: Boolean;
5
- connectWithSurveys: Boolean;
6
- personalizedAds: Boolean;
7
- personalizedContent: Boolean;
8
- }, false>;
9
- export declare const getPrivacyPreferences: () => Promise<Pick<UserAttributes, 'privacyPreferences'>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- export declare const requestStorage: (namespaces: string[]) => void;
2
- export declare const updateStorage: (storage: {
3
- [namespace: string]: object;
4
- }) => void;
@@ -1,2 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const requestAttributes: (attributes: Array<keyof UserAttributes>) => void;
@@ -1 +0,0 @@
1
- export declare const attemptAutologin: () => Promise<void>;
@@ -1,3 +0,0 @@
1
- export declare const CACHE_KEY = "haveTriedThirdPartyLoginCheck";
2
- export declare const CACHE_TTL: number;
3
- export default function thirdPartyCookie(): Promise<void>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
1
- import { CacheEntry, Engine } from '../types';
2
- declare global {
3
- interface Window {
4
- amediaUserCache?: {
5
- [index: string]: CacheEntry;
6
- };
7
- }
8
- namespace NodeJS {
9
- interface Global {
10
- amediaUserCache?: {
11
- [index: string]: CacheEntry;
12
- };
13
- }
14
- }
15
- }
16
- export declare const get: (key: string) => Promise<CacheEntry>;
17
- export declare const set: (key: string, data: unknown, expires: number) => Promise<void>;
18
- export declare const remove: (key: string) => Promise<void>;
19
- export declare const clear: () => Promise<void>;
20
- declare const _default: Engine;
21
- export default _default;
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- import { CacheEntry, Engine } from '../types';
2
- export declare const get: (key: string) => Promise<CacheEntry>;
3
- export declare const set: (key: string, data: unknown, expires: number) => Promise<void>;
4
- export declare const remove: (key: string) => Promise<void>;
5
- export declare const clear: () => Promise<void>;
6
- declare const _default: Engine;
7
- export default _default;
@@ -1,11 +0,0 @@
1
- import { Static } from 'runtypes';
2
- import { RuntypeBase } from 'runtypes/lib/runtype';
3
- import { Engine } from './types';
4
- export declare const setCacheEngine: (engine: Engine) => void;
5
- declare const _default: {
6
- get: <T extends RuntypeBase<unknown>>(key: string, validator: T) => Promise<void | Static<T>>;
7
- set: (key: string, value: unknown, expires: number) => Promise<void>;
8
- remove: (key: string) => Promise<void>;
9
- clear: () => Promise<void>;
10
- };
11
- export default _default;
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};
@@ -1,11 +0,0 @@
1
- export declare type CacheEntry = {
2
- key: string;
3
- data: unknown;
4
- expires: number;
5
- };
6
- export declare type Engine = {
7
- get: (key: string) => Promise<CacheEntry | null>;
8
- set: (key: string, data: unknown, expires: number) => Promise<void>;
9
- remove: (key: string) => Promise<void>;
10
- clear: () => Promise<void>;
11
- };
@@ -1,28 +0,0 @@
1
- import { Record, Unknown, Dictionary } from 'runtypes';
2
- export declare const EuropaSchema: Record<{
3
- namespaces: Dictionary<Unknown, string>;
4
- }, false>;
5
- export declare const clearLocalCache: () => Promise<void>;
6
- export declare const updateNamespace: (namespace: string, data: Object) => Promise<void | {}>;
7
- export declare const getNamespaces: <S extends {
8
- [namespace: string]: {
9
- [index: string]: unknown;
10
- };
11
- }, Namespaces extends (keyof S)[]>(namespaces: Namespaces, options?: {
12
- ignoreCache: boolean;
13
- }) => Promise<Pick<S, Namespaces[number]>>;
14
- export declare const saveNamespace: (namespace: string, data: Object) => Promise<Pick<{
15
- [namespace: string]: {
16
- [index: string]: unknown;
17
- };
18
- }, string>>;
19
- export declare const getAllNamespaces: () => Promise<{
20
- namespaces: {
21
- [x: string]: unknown;
22
- };
23
- }>;
24
- export declare const deleteNamespaceKey: (namespace: string, key: string) => Promise<Pick<{
25
- [namespace: string]: {
26
- [index: string]: unknown;
27
- };
28
- }, string>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- import { Array, Literal, Record, Static, String, Number, Union } from 'runtypes';
2
- import { UserAttributes } from '../types';
3
- export declare type AccessFeatures = string[];
4
- export declare const CheckAccessForPaperSchema: Record<{
5
- status: Literal<"success">;
6
- access: Union<[Literal<"granted">, Literal<"denied">]>;
7
- publication: Record<{
8
- id: Number;
9
- domain: String;
10
- }, false>;
11
- access_features: Array<String, false>;
12
- }, false>;
13
- export declare type CheckAccessForPaper = Static<typeof CheckAccessForPaperSchema>;
14
- declare const GetVstokenSchema: Record<{
15
- status: Literal<"success">;
16
- cookie: String;
17
- access_features: Array<String, false>;
18
- }, false>;
19
- export declare type GetVstoken = Static<typeof GetVstokenSchema>;
20
- declare const GetNonUserAccessSchema: Record<{
21
- status: Literal<"success">;
22
- vstoken_cookie: String;
23
- uuid: String;
24
- access_features: Array<String, false>;
25
- }, false>;
26
- export declare type GetNonUserAccess = Static<typeof GetNonUserAccessSchema>;
27
- export declare const checkForAccess: (publicationDomain: string, accessFeatures: AccessFeatures) => Promise<Pick<UserAttributes, 'access'>>;
28
- export declare const getVstoken: (publicationDomain: string) => Promise<GetVstoken>;
29
- export declare const getNonUserAccess: (publicationDomain: string) => Promise<GetNonUserAccess>;
30
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- declare const log: {
2
- error: (message: string, context: {
3
- [index: string]: any;
4
- }) => void;
5
- warn: (message: string, context: {
6
- [index: string]: any;
7
- }) => void;
8
- info: (message: string, context: {
9
- [index: string]: any;
10
- }) => void;
11
- debug: (message: string, context: {
12
- [index: string]: any;
13
- }) => void;
14
- };
15
- export declare class UserDeactivatedError extends Error {
16
- }
17
- export declare const activateSubscription: (accessFeatures: string[]) => Promise<boolean>;
18
- export default log;
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};
@@ -1,2 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const getInfo: (publicationDomain: string, browserId: string, userKey?: string | undefined) => Promise<Pick<UserAttributes, 'extraData'>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const getCurrentSession: () => Promise<UserAttributes>;
3
- export declare const removeSession: (domain: string) => Promise<void>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- export declare enum ActivationEvents {
2
- REQUEST_ACTIVATION = 'amedia-user.activation.request-activation',
3
- ON_ACTIVATION_COMPLETE = 'amedia-user.activation.on-activation-complete',
4
- }
5
- declare global {
6
- interface WindowEventMap {
7
- [ActivationEvents.REQUEST_ACTIVATION]: CustomEvent<{
8
- accessFeatures: string[];
9
- }>;
10
- [ActivationEvents.ON_ACTIVATION_COMPLETE]: CustomEvent<{
11
- accessFeatures: string[];
12
- }>;
13
- }
14
- }
15
- export declare const listenForActivationRequests: () => void;
@@ -1,17 +0,0 @@
1
- export declare enum AuthenticationEvents {
2
- REQUEST_LOGIN = "amedia-user.authentication.request-login",
3
- REQUEST_LOGOUT = "amedia-user.authentication.request-logout",
4
- ON_LOGGED_OUT = "amedia-user.authentication.on-logged-out"
5
- }
6
- declare global {
7
- interface WindowEventMap {
8
- [AuthenticationEvents.REQUEST_LOGIN]: CustomEvent<{
9
- requestedUrl: string;
10
- }>;
11
- [AuthenticationEvents.REQUEST_LOGOUT]: CustomEvent<{
12
- onLoggedOut: () => void;
13
- }>;
14
- [AuthenticationEvents.ON_LOGGED_OUT]: CustomEvent;
15
- }
16
- }
17
- export declare const listenForAuthenticationRequests: () => void;
@@ -1,24 +0,0 @@
1
- import { State, UserAttributes } from '../types';
2
- export declare enum AmediaUserEvents {
3
- REQUEST_USER_ATTRIBUTES = "amedia-user.request-user-attributes",
4
- REQUEST_STORAGE_NAMESPACES = "amedia-user.request-storage-namespaces",
5
- UPDATE_STORAGE = "amedua-user.update-storage-namespaces",
6
- ON_ATTRIBUTES_UPDATED = "amedia-user.on-user-attributes-updated",
7
- ON_STATE_UPDATED = "amedia-user.on-state-updated",
8
- ON_STORAGE_UPDATED = "amedia-user.on-storage-updated"
9
- }
10
- declare global {
11
- interface WindowEventMap {
12
- [AmediaUserEvents.REQUEST_USER_ATTRIBUTES]: CustomEvent<Array<keyof UserAttributes>>;
13
- [AmediaUserEvents.REQUEST_STORAGE_NAMESPACES]: CustomEvent<Array<string>>;
14
- [AmediaUserEvents.UPDATE_STORAGE]: CustomEvent<{
15
- [namespace: string]: object;
16
- }>;
17
- [AmediaUserEvents.ON_ATTRIBUTES_UPDATED]: CustomEvent<UserAttributes>;
18
- [AmediaUserEvents.ON_STATE_UPDATED]: CustomEvent<State>;
19
- [AmediaUserEvents.ON_STORAGE_UPDATED]: CustomEvent<{
20
- [index: string]: unknown;
21
- }>;
22
- }
23
- }
24
- export declare const listenForUserAttributeRequests: () => void;
@@ -1,7 +0,0 @@
1
- declare class PaywallError extends Error {
2
- static ERROR_RELOADED_NO_ACCESS: string;
3
- static ERROR_ENABLING_ACCESS_FAILED: string;
4
- code: string;
5
- constructor(message: string, code: string);
6
- }
7
- export default PaywallError;
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};