@amedia/user 0.13.32 → 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.
- package/dist/actions/authentication.spec.d.ts +0 -3
- package/dist/autologin/index.spec.d.ts +0 -3
- package/dist/cache/index.spec.d.ts +0 -3
- package/dist/clients/mercury.spec.d.ts +0 -3
- package/dist/clients/mercuryLog.spec.d.ts +0 -3
- package/dist/eventHandlers/state.spec.d.ts +0 -3
- package/dist/eventHandlers/storage.spec.d.ts +0 -3
- package/dist/eventHandlers/userAttributes.spec.d.ts +0 -3
- package/dist/index-authentcation.spec.d.ts +0 -3
- package/dist/index-storage.spec.d.ts +0 -3
- package/dist/index-subscription.spec.d.ts +0 -3
- package/dist/index.d.ts +13 -42
- 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/index.spec.d.ts +1 -0
- package/dist/janitor/jobs/accessCookieRefresher.spec.d.ts +0 -3
- package/dist/janitor/jobs/daxsubCookie.spec.d.ts +0 -3
- package/dist/lib/PaywallUnlockRequest.spec.d.ts +0 -3
- package/dist/utils/expectBootLogs.d.ts +2 -0
- package/dist/utils/localhostCheck.d.ts +1 -0
- package/eik.json +1 -1
- package/jest.config.js +2 -1
- package/package.json +2 -2
- package/setupJest.js +0 -5
- package/src/actions/authentication.spec.ts +0 -6
- package/src/actions/authorization.spec.ts +0 -4
- package/src/actions/preferences.spec.ts +0 -1
- package/src/actions/userData.spec.ts +0 -6
- package/src/autologin/index.spec.ts +1 -11
- package/src/autologin/thirdPartyCookie.spec.ts +0 -5
- package/src/cache/index.spec.ts +0 -6
- package/src/clients/europa.spec.ts +0 -3
- package/src/clients/jupiter.spec.ts +0 -3
- package/src/clients/mercury.spec.ts +0 -10
- package/src/clients/mercuryLog.spec.ts +0 -10
- package/src/clients/nebula.spec.ts +0 -3
- package/src/clients/pluto.spec.ts +0 -3
- package/src/eventHandlers/activation.ts +5 -1
- package/src/eventHandlers/state.spec.ts +1 -12
- package/src/eventHandlers/storage.spec.ts +1 -12
- package/src/eventHandlers/userAttributes.spec.ts +1 -12
- package/src/index-authentcation.spec.ts +0 -14
- package/src/index-storage.spec.ts +1 -15
- package/src/index-subscription.spec.ts +1 -15
- package/src/index.ts +7 -4
- package/src/janitor/index.spec.ts +18 -0
- package/src/janitor/index.ts +9 -0
- package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -8
- package/src/janitor/jobs/daxsubCookie.spec.ts +1 -15
- package/src/janitor/jobs/removeUserStorage.spec.ts +0 -5
- package/src/lib/PaywallUnlockRequest.spec.ts +17 -14
- package/src/lib/PaywallUnlockRequest.ts +6 -0
- package/src/lib/UserDataRequest.spec.ts +16 -11
- package/src/lib/UserDataRequest.ts +9 -1
- package/src/utils/debouncer.spec.ts +0 -5
- package/src/utils/expectBootLogs.ts +9 -0
- package/src/utils/getOrUpdate.spec.ts +0 -2
- package/src/utils/localhostCheck.ts +9 -0
- package/src/utils/log.spec.ts +0 -5
- package/testSetup.js +18 -0
|
@@ -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
|
|
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', () => {
|
package/src/utils/log.spec.ts
CHANGED
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
|
+
});
|