@amedia/user 0.13.35 → 0.13.37
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.cjs +1 -1
- package/dist/user.cjs.map +3 -3
- package/dist/user.d.ts +15 -1
- package/dist/user.js +1 -1
- package/dist/user.js.map +3 -3
- package/package.json +5 -2
- package/.codeclimate.yml +0 -8
- package/.eslintignore +0 -2
- package/.eslintrc +0 -11
- package/.prettierrc.json +0 -1
- package/@types/amedia-frontend-rpc.d.ts +0 -11
- package/@types/browserid.d.ts +0 -4
- package/build.js +0 -28
- package/checkVersion.cjs +0 -12
- package/cloudbuild.json +0 -29
- package/cop.json +0 -8
- package/dist/actions/authentication.d.ts +0 -4
- package/dist/actions/authentication.spec.d.ts +0 -1
- package/dist/actions/authorization.d.ts +0 -14
- package/dist/actions/authorization.spec.d.ts +0 -4
- package/dist/actions/preferences.d.ts +0 -9
- package/dist/actions/preferences.spec.d.ts +0 -1
- package/dist/actions/storage.d.ts +0 -7
- package/dist/actions/userData.d.ts +0 -2
- package/dist/actions/userData.spec.d.ts +0 -1
- package/dist/autologin/index.d.ts +0 -7
- package/dist/autologin/index.spec.d.ts +0 -1
- package/dist/autologin/thirdPartyCookie.d.ts +0 -3
- package/dist/autologin/thirdPartyCookie.spec.d.ts +0 -1
- package/dist/cache/engines/global.d.ts +0 -24
- package/dist/cache/engines/global.spec.d.ts +0 -1
- package/dist/cache/index.d.ts +0 -11
- package/dist/cache/index.spec.d.ts +0 -1
- package/dist/cache/types.d.ts +0 -11
- package/dist/clients/europa.d.ts +0 -24
- package/dist/clients/europa.spec.d.ts +0 -1
- package/dist/clients/jupiter.d.ts +0 -30
- package/dist/clients/jupiter.spec.d.ts +0 -1
- package/dist/clients/mercury.d.ts +0 -3
- package/dist/clients/mercury.spec.d.ts +0 -1
- package/dist/clients/mercuryLog.d.ts +0 -8
- package/dist/clients/mercuryLog.spec.d.ts +0 -1
- package/dist/clients/nebula.d.ts +0 -2
- package/dist/clients/nebula.spec.d.ts +0 -1
- package/dist/clients/pluto.d.ts +0 -4
- package/dist/clients/pluto.spec.d.ts +0 -1
- package/dist/eventHandlers/activation.d.ts +0 -15
- package/dist/eventHandlers/authentication.d.ts +0 -17
- package/dist/eventHandlers/eventMap.d.ts +0 -29
- package/dist/eventHandlers/state.d.ts +0 -1
- package/dist/eventHandlers/state.spec.d.ts +0 -1
- package/dist/eventHandlers/storage.d.ts +0 -1
- package/dist/eventHandlers/storage.spec.d.ts +0 -1
- package/dist/eventHandlers/userAttributes.d.ts +0 -1
- package/dist/eventHandlers/userAttributes.spec.d.ts +0 -1
- package/dist/exceptions/PaywallError.d.ts +0 -8
- package/dist/index-authentcation.spec.d.ts +0 -1
- package/dist/index-storage.spec.d.ts +0 -1
- package/dist/index-subscription.spec.d.ts +0 -1
- package/dist/index.d.ts +0 -20
- package/dist/janitor/index.d.ts +0 -10
- package/dist/janitor/index.spec.d.ts +0 -1
- package/dist/janitor/jobs/accessCookieRefresher.d.ts +0 -1
- package/dist/janitor/jobs/accessCookieRefresher.spec.d.ts +0 -1
- package/dist/janitor/jobs/daxsubCookie.d.ts +0 -3
- package/dist/janitor/jobs/daxsubCookie.spec.d.ts +0 -1
- package/dist/janitor/jobs/removeUserStorage.d.ts +0 -1
- package/dist/janitor/jobs/removeUserStorage.spec.d.ts +0 -1
- package/dist/lib/PaywallUnlockRequest.d.ts +0 -17
- package/dist/lib/PaywallUnlockRequest.spec.d.ts +0 -1
- package/dist/lib/UserDataRequest.d.ts +0 -22
- package/dist/lib/UserDataRequest.spec.d.ts +0 -1
- package/dist/lib/cookie.d.ts +0 -9
- package/dist/lib/rpc.d.ts +0 -6
- package/dist/store/index.d.ts +0 -23
- package/dist/store/index.spec.d.ts +0 -1
- package/dist/types.d.ts +0 -22
- package/dist/utils/customEventWrapper.d.ts +0 -19
- package/dist/utils/debouncer.d.ts +0 -26
- package/dist/utils/debouncer.spec.d.ts +0 -1
- package/dist/utils/deepEquals.d.ts +0 -1
- package/dist/utils/expectBootLogs.d.ts +0 -2
- package/dist/utils/getOrUpdate.d.ts +0 -6
- package/dist/utils/getOrUpdate.spec.d.ts +0 -1
- package/dist/utils/localhostCheck.d.ts +0 -1
- package/dist/utils/location.d.ts +0 -3
- package/dist/utils/log.d.ts +0 -9
- package/dist/utils/log.spec.d.ts +0 -1
- package/dist/utils/loginState.d.ts +0 -2
- package/dist/utils/networkError.d.ts +0 -1
- package/dist/utils/queue.d.ts +0 -12
- package/dist/utils/type.d.ts +0 -6
- package/dist/utils/url.d.ts +0 -6
- package/dist/utils/url.spec.d.ts +0 -1
- package/eik.json +0 -10
- package/global.d.ts +0 -1
- package/jest.config.js +0 -7
- package/setupJest.js +0 -1
- package/src/actions/authentication.spec.ts +0 -51
- package/src/actions/authentication.ts +0 -43
- package/src/actions/authorization.spec.ts +0 -369
- package/src/actions/authorization.ts +0 -117
- package/src/actions/preferences.spec.ts +0 -41
- package/src/actions/preferences.ts +0 -41
- package/src/actions/storage.ts +0 -22
- package/src/actions/userData.spec.ts +0 -133
- package/src/actions/userData.ts +0 -68
- package/src/autologin/index.spec.ts +0 -239
- package/src/autologin/index.ts +0 -92
- package/src/autologin/thirdPartyCookie.spec.ts +0 -95
- package/src/autologin/thirdPartyCookie.ts +0 -55
- package/src/cache/engines/global.spec.ts +0 -62
- package/src/cache/engines/global.ts +0 -48
- package/src/cache/index.spec.ts +0 -130
- package/src/cache/index.ts +0 -48
- package/src/cache/types.ts +0 -12
- package/src/clients/europa.spec.ts +0 -209
- package/src/clients/europa.ts +0 -183
- package/src/clients/jupiter.spec.ts +0 -179
- package/src/clients/jupiter.ts +0 -119
- package/src/clients/mercury.spec.ts +0 -59
- package/src/clients/mercury.ts +0 -48
- package/src/clients/mercuryLog.spec.ts +0 -20
- package/src/clients/mercuryLog.ts +0 -67
- package/src/clients/nebula.spec.ts +0 -70
- package/src/clients/nebula.ts +0 -83
- package/src/clients/pluto.spec.ts +0 -165
- package/src/clients/pluto.ts +0 -118
- package/src/eventHandlers/activation.ts +0 -35
- package/src/eventHandlers/authentication.ts +0 -34
- package/src/eventHandlers/eventMap.ts +0 -34
- package/src/eventHandlers/state.spec.ts +0 -48
- package/src/eventHandlers/state.ts +0 -23
- package/src/eventHandlers/storage.spec.ts +0 -114
- package/src/eventHandlers/storage.ts +0 -45
- package/src/eventHandlers/userAttributes.spec.ts +0 -93
- package/src/eventHandlers/userAttributes.ts +0 -31
- package/src/exceptions/PaywallError.ts +0 -16
- package/src/index-authentcation.spec.ts +0 -26
- package/src/index-storage.spec.ts +0 -144
- package/src/index-subscription.spec.ts +0 -213
- package/src/index.ts +0 -59
- package/src/janitor/index.spec.ts +0 -18
- package/src/janitor/index.ts +0 -59
- package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -213
- package/src/janitor/jobs/accessCookieRefresher.ts +0 -98
- package/src/janitor/jobs/daxsubCookie.spec.ts +0 -109
- package/src/janitor/jobs/daxsubCookie.ts +0 -38
- package/src/janitor/jobs/removeUserStorage.spec.ts +0 -34
- package/src/janitor/jobs/removeUserStorage.ts +0 -12
- package/src/lib/PaywallUnlockRequest.spec.ts +0 -363
- package/src/lib/PaywallUnlockRequest.ts +0 -143
- package/src/lib/UserDataRequest.spec.ts +0 -77
- package/src/lib/UserDataRequest.ts +0 -213
- package/src/lib/cookie.ts +0 -121
- package/src/lib/rpc.ts +0 -19
- package/src/store/index.spec.ts +0 -49
- package/src/store/index.ts +0 -64
- package/src/types.ts +0 -22
- package/src/utils/customEventWrapper.ts +0 -58
- package/src/utils/debouncer.spec.ts +0 -252
- package/src/utils/debouncer.ts +0 -123
- package/src/utils/deepEquals.ts +0 -42
- package/src/utils/expectBootLogs.ts +0 -9
- package/src/utils/getOrUpdate.spec.ts +0 -166
- package/src/utils/getOrUpdate.ts +0 -66
- package/src/utils/localhostCheck.ts +0 -9
- package/src/utils/location.ts +0 -31
- package/src/utils/log.spec.ts +0 -148
- package/src/utils/log.ts +0 -124
- package/src/utils/loginState.ts +0 -24
- package/src/utils/networkError.ts +0 -11
- package/src/utils/queue.ts +0 -32
- package/src/utils/type.ts +0 -19
- package/src/utils/url.spec.ts +0 -33
- package/src/utils/url.ts +0 -35
- package/testSetup.js +0 -19
- package/tsconfig.eslint.json +0 -24
- package/tsconfig.json +0 -18
package/dist/store/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { State, UserAttributes } from '../types';
|
|
2
|
-
declare type StoreDataMap = {
|
|
3
|
-
userAttributes: UserAttributes;
|
|
4
|
-
state: State;
|
|
5
|
-
storage: {
|
|
6
|
-
[namespace: string]: {
|
|
7
|
-
[index: string]: unknown;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
declare type Listener<T> = (data: T) => void;
|
|
12
|
-
declare const _default: {
|
|
13
|
-
merge: <K extends keyof StoreDataMap>(key: K, value: Partial<StoreDataMap[K]>) => void;
|
|
14
|
-
set: (key: keyof StoreDataMap, value: UserAttributes | State | {
|
|
15
|
-
[namespace: string]: {
|
|
16
|
-
[index: string]: unknown;
|
|
17
|
-
};
|
|
18
|
-
}) => void;
|
|
19
|
-
get: <K_1 extends keyof StoreDataMap, T = StoreDataMap[K_1]>(key: K_1) => T | undefined;
|
|
20
|
-
on: <K_2 extends keyof StoreDataMap, T_1 = StoreDataMap[K_2]>(key: K_2, listener: Listener<T_1>) => void;
|
|
21
|
-
clear: () => void;
|
|
22
|
-
};
|
|
23
|
-
export default _default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export declare type UserAttributes = {
|
|
2
|
-
uuid?: string | null;
|
|
3
|
-
name?: string | null;
|
|
4
|
-
email?: string | null;
|
|
5
|
-
phone?: string | null;
|
|
6
|
-
trackingKey?: string | null;
|
|
7
|
-
extraData?: {
|
|
8
|
-
[index: string]: unknown;
|
|
9
|
-
};
|
|
10
|
-
access?: string[];
|
|
11
|
-
privacyPreferences?: PrivacyPreferences | null;
|
|
12
|
-
};
|
|
13
|
-
export declare type State = {
|
|
14
|
-
isLoggedIn: boolean;
|
|
15
|
-
emergencyMode?: string[];
|
|
16
|
-
};
|
|
17
|
-
export declare type PrivacyPreferences = {
|
|
18
|
-
allowResearchUsage: boolean;
|
|
19
|
-
connectWithSurveys: boolean;
|
|
20
|
-
personalizedAds: boolean;
|
|
21
|
-
personalizedContent: boolean;
|
|
22
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
declare let rootElement: Window | Element | typeof globalThis;
|
|
2
|
-
export declare const setRootElement: (element: typeof rootElement) => void;
|
|
3
|
-
/**
|
|
4
|
-
* This listener MUST be used by all listeners in ../eventHandlers
|
|
5
|
-
* We want to ensure that only _one_ instance of this package actually
|
|
6
|
-
* orchestrates data and performs requests against backends.
|
|
7
|
-
* @param type
|
|
8
|
-
* @param listener
|
|
9
|
-
*/
|
|
10
|
-
export declare const listenWithExclusivity: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
|
|
11
|
-
/**
|
|
12
|
-
* Use this for response listeners. (../index.ts) where we want
|
|
13
|
-
* all updates with data - no matter who sent the actual request
|
|
14
|
-
* @param type
|
|
15
|
-
* @param listener
|
|
16
|
-
*/
|
|
17
|
-
export declare const listenForAllEvents: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
|
|
18
|
-
export declare const dispatch: <T extends Event>(event: T) => void;
|
|
19
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 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,
|
|
3
|
-
* resolve my promise', but instead of the fetch being performed right away, we want to wait for more users to
|
|
4
|
-
* request other stuff. This will keep us from performing lots of individual fetches to the backend.
|
|
5
|
-
*
|
|
6
|
-
* Our main use case is a standard publication front page where one component on the page requests the euucp namespace
|
|
7
|
-
* from Europa, and then another component requests the privacy_preferences namespace. Instead of the Europa client
|
|
8
|
-
* calling two fetches to the server, one for euucp and another for privacy_preferences, we want the Debouncer to
|
|
9
|
-
* aggregate these calls into one call to the backend, that requests both euucp AND privacy_preferences, so the response
|
|
10
|
-
* to both components will be both namespaces (which the Europa client can filter before it actually reaches the
|
|
11
|
-
* component).
|
|
12
|
-
*/
|
|
13
|
-
declare class Debouncer<ParamsType, ResultType> {
|
|
14
|
-
private timeoutMs;
|
|
15
|
-
private defaultParams;
|
|
16
|
-
private paramAccumulator;
|
|
17
|
-
private workload;
|
|
18
|
-
private timer;
|
|
19
|
-
private params;
|
|
20
|
-
private queue;
|
|
21
|
-
constructor(timeoutMs: number, defaultParams: ParamsType, paramAccumulator: (previousParams: ParamsType, newParams: ParamsType) => ParamsType, workload: (params: ParamsType) => Promise<ResultType>);
|
|
22
|
-
perform(newParams: ParamsType): Promise<ResultType>;
|
|
23
|
-
static stringListParamsAccumulator(accumulatedParams: string[], newParams: string[]): string[];
|
|
24
|
-
static stringMapParamsAccumulator(previousParams: Record<string, any>, newParams: Record<string, any>): Record<string, any>;
|
|
25
|
-
}
|
|
26
|
-
export default Debouncer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const deepEquals: (a: unknown, b: unknown) => boolean;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Runtype, Static } from 'runtypes';
|
|
2
|
-
export declare type DataFetcherWithCacheTTL<T extends Runtype> = Promise<{
|
|
3
|
-
ttl: number;
|
|
4
|
-
data: Static<T>;
|
|
5
|
-
}>;
|
|
6
|
-
export default function getOrUpdate<T extends Runtype>(key: string, schema: T, fetch: () => DataFetcherWithCacheTTL<T>, cacheQualifier?: (cacheData: Static<T>) => boolean): Promise<Static<T>>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isRunningOnLocalhost: () => boolean;
|
package/dist/utils/location.d.ts
DELETED
package/dist/utils/log.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare type Logger = {
|
|
2
|
-
debug: (message: string | Error, context?: any) => void;
|
|
3
|
-
info: (message: string | Error, context?: any) => void;
|
|
4
|
-
warn: (message: string | Error, context?: any) => void;
|
|
5
|
-
error: (message: string | Error, context?: any) => void;
|
|
6
|
-
};
|
|
7
|
-
export declare const setLogger: (engine: Logger) => void;
|
|
8
|
-
declare const _default: Logger;
|
|
9
|
-
export default _default;
|
package/dist/utils/log.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isAbortedNetworkError: (message: string) => boolean;
|
package/dist/utils/queue.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
add: (key: string, promiseCallbacks: {
|
|
3
|
-
resolve: (arg0?: any) => void;
|
|
4
|
-
reject: (reason?: any) => void;
|
|
5
|
-
}) => void;
|
|
6
|
-
getAll: (key: string) => {
|
|
7
|
-
resolve: (arg0?: any) => void;
|
|
8
|
-
reject: (reason?: any) => void;
|
|
9
|
-
}[];
|
|
10
|
-
peekQueueSize: (key: string) => number;
|
|
11
|
-
};
|
|
12
|
-
export default _default;
|
package/dist/utils/type.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const isFunction: (argument: unknown) => argument is Function;
|
|
2
|
-
export declare const isRecord: (argument: unknown) => argument is Record<string, unknown>;
|
|
3
|
-
export declare const isError: (argument: unknown) => argument is Error;
|
|
4
|
-
export declare const isString: (argument: unknown) => argument is string;
|
|
5
|
-
export declare const isNumber: (argument: unknown) => argument is number;
|
|
6
|
-
export declare const isBoolean: (argument: unknown) => argument is boolean;
|
package/dist/utils/url.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const setCurrentHostname: (hostname: string) => void;
|
|
2
|
-
export declare const getCurrentHostname: () => string;
|
|
3
|
-
export declare const getCurrentUrl: () => string;
|
|
4
|
-
export declare const getCurrentEnvironment: () => string | null;
|
|
5
|
-
export declare const getCurrentPublicationDomain: () => string;
|
|
6
|
-
export declare const getAidDomain: () => string;
|
package/dist/utils/url.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/eik.json
DELETED
package/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'jest-extended';
|
package/jest.config.js
DELETED
package/setupJest.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
self = global || window;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import * as url from '../utils/url';
|
|
2
|
-
import * as location from '../utils/location';
|
|
3
|
-
import { login } from './authentication';
|
|
4
|
-
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
spyOn(url, 'getCurrentUrl').and.returnValue('https://www.telen.no/artikkel/');
|
|
7
|
-
spyOn(url, 'getCurrentPublicationDomain').and.returnValue('www.telen.no');
|
|
8
|
-
spyOn(location, 'navigateTo');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
describe('authentication', () => {
|
|
12
|
-
describe('goToLoginPage', () => {
|
|
13
|
-
describe('when using URL or string for param', () => {
|
|
14
|
-
it('should return expected url for string', () => {
|
|
15
|
-
login('https://my.url/');
|
|
16
|
-
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
17
|
-
'https://www.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=https%3A%2F%2Fmy.url%2F'
|
|
18
|
-
);
|
|
19
|
-
});
|
|
20
|
-
it('should return expected url for URL', () => {
|
|
21
|
-
login(new URL('https://my.url'));
|
|
22
|
-
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
23
|
-
'https://www.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=https%3A%2F%2Fmy.url%2F'
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
describe('when changing environment', () => {
|
|
28
|
-
it('should resolve dev env', () => {
|
|
29
|
-
spyOn(url, 'getCurrentEnvironment').and.returnValue('localhost');
|
|
30
|
-
login('current');
|
|
31
|
-
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
32
|
-
'https://www.aid.no.localhost.api.no/aid/logg_inn/www.telen.no/?requestedUrl=current'
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
it('should resolve snap5 env', () => {
|
|
36
|
-
spyOn(url, 'getCurrentEnvironment').and.returnValue('snap5');
|
|
37
|
-
login('current');
|
|
38
|
-
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
39
|
-
'https://www-snap5.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=current'
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
it('should resolve prod env', () => {
|
|
43
|
-
spyOn(url, 'getCurrentEnvironment').and.returnValue('');
|
|
44
|
-
login('current');
|
|
45
|
-
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
46
|
-
'https://www.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=current'
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { getCurrentSession, removeSession } from '../clients/pluto';
|
|
2
|
-
import cache from '../cache';
|
|
3
|
-
import { getRPCClient } from '../lib/rpc';
|
|
4
|
-
import { removeCookie } from '../lib/cookie';
|
|
5
|
-
import { getAidDomain, getCurrentPublicationDomain } from '../utils/url';
|
|
6
|
-
import log from '../utils/log';
|
|
7
|
-
import { UserAttributes } from '../types';
|
|
8
|
-
import { navigateTo } from '../utils/location';
|
|
9
|
-
|
|
10
|
-
export const login = (requestedUrl: URL | string) => {
|
|
11
|
-
const url = new URL(
|
|
12
|
-
`https://${getAidDomain()}/aid/logg_inn/${getCurrentPublicationDomain()}/`
|
|
13
|
-
);
|
|
14
|
-
url.searchParams.set(
|
|
15
|
-
'requestedUrl',
|
|
16
|
-
requestedUrl instanceof URL ? requestedUrl.href : requestedUrl
|
|
17
|
-
);
|
|
18
|
-
navigateTo(url.href);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function clearCookies() {
|
|
22
|
-
removeCookie('VSTOKEN');
|
|
23
|
-
removeCookie('aid.session');
|
|
24
|
-
removeCookie('aid_invitation_code');
|
|
25
|
-
removeCookie('aid-reload-article');
|
|
26
|
-
removeCookie('daxsub');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const logout = async () =>
|
|
30
|
-
// TODO: It now clears the entire cache. Might be too aggressive.
|
|
31
|
-
Promise.all([removeSession(getCurrentPublicationDomain()), cache.clear()])
|
|
32
|
-
.then(() => {
|
|
33
|
-
// TODO This should be separated from logout and instead be setup to listen on state changes on storage
|
|
34
|
-
getRPCClient().userAuthenticated(false);
|
|
35
|
-
clearCookies();
|
|
36
|
-
// In addition to removing the regular cookies we also want to remove VSTOKEN2 on explicit logout
|
|
37
|
-
removeCookie('VSTOKEN2');
|
|
38
|
-
})
|
|
39
|
-
.catch((reason) => {
|
|
40
|
-
log.error('Failure while logging out', reason);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
export const getSession = (): Promise<UserAttributes> => getCurrentSession();
|
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
activate,
|
|
7
|
-
getAccess,
|
|
8
|
-
hasAccess,
|
|
9
|
-
hasRecentlyPerformedPaywallReload,
|
|
10
|
-
setAccessCookies,
|
|
11
|
-
setHasPerformedPaywallReload,
|
|
12
|
-
setNonUserAccessCookie,
|
|
13
|
-
setUserAccessCookie,
|
|
14
|
-
} from './authorization';
|
|
15
|
-
import * as jupiter from '../clients/jupiter';
|
|
16
|
-
import * as cookie from '../lib/cookie';
|
|
17
|
-
import * as url from '../utils/url';
|
|
18
|
-
import * as mercury from '../clients/mercury';
|
|
19
|
-
import * as authentication from './authentication';
|
|
20
|
-
import { removeAllCookies } from '../lib/cookie';
|
|
21
|
-
import { AccessFeatures } from '../clients/jupiter';
|
|
22
|
-
|
|
23
|
-
const publicationDomain = 'www.avisnavn.no';
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
removeAllCookies();
|
|
27
|
-
jest.spyOn(cookie, 'setCookie');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('getAccess', () => {
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
url.setCurrentHostname('www.avisnavn.no');
|
|
33
|
-
jest
|
|
34
|
-
.spyOn(jupiter, 'checkForAccess')
|
|
35
|
-
.mockResolvedValue({ access: ['newspaper', 'plussalt'] });
|
|
36
|
-
});
|
|
37
|
-
it('returns list of access', async () => {
|
|
38
|
-
expect(await getAccess()).toEqual({
|
|
39
|
-
access: ['newspaper', 'plussalt'],
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('activate', () => {
|
|
45
|
-
describe('when all is ok', () => {
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
jest
|
|
48
|
-
.spyOn(mercury, 'activateSubscription')
|
|
49
|
-
.mockResolvedValue(['whatever']);
|
|
50
|
-
});
|
|
51
|
-
it('Returns whatever mercury returns', async () => {
|
|
52
|
-
expect(await activate(['newspaper'])).toEqual(['whatever']);
|
|
53
|
-
expect(mercury.activateSubscription).toHaveBeenCalledWith(['newspaper']);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('when user is deactivated', () => {
|
|
58
|
-
beforeEach(() => {
|
|
59
|
-
jest
|
|
60
|
-
.spyOn(mercury, 'activateSubscription')
|
|
61
|
-
.mockRejectedValue(new mercury.UserDeactivatedError());
|
|
62
|
-
jest.spyOn(authentication, 'logout').mockResolvedValue(undefined);
|
|
63
|
-
});
|
|
64
|
-
it('Returns whatever mercury returns', async () => {
|
|
65
|
-
expect(await activate([])).toEqual([]);
|
|
66
|
-
expect(mercury.activateSubscription).toHaveBeenCalledWith([]);
|
|
67
|
-
expect(authentication.logout).toHaveBeenCalled();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('hasAccess', () => {
|
|
73
|
-
let access = false;
|
|
74
|
-
function itReturnsTrue() {
|
|
75
|
-
it('returns true', () => {
|
|
76
|
-
expect(access).toBeTruthy();
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
function itReturnsFalse() {
|
|
80
|
-
it('returns false', () => {
|
|
81
|
-
expect(access).not.toBeTruthy();
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
describe('with no access requested', () => {
|
|
85
|
-
beforeEach(() => {
|
|
86
|
-
access = hasAccess(['newspaper'], []);
|
|
87
|
-
});
|
|
88
|
-
itReturnsTrue();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('with access requested without access', () => {
|
|
92
|
-
beforeEach(() => {
|
|
93
|
-
access = hasAccess([], ['newspaper']);
|
|
94
|
-
});
|
|
95
|
-
itReturnsFalse();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('with access to some requested access feature', () => {
|
|
99
|
-
beforeEach(() => {
|
|
100
|
-
access = hasAccess(['newspaper'], ['all', 'plussalt', 'newspaper']);
|
|
101
|
-
});
|
|
102
|
-
itReturnsTrue();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('with access to other access features than requested requested access feature', () => {
|
|
106
|
-
beforeEach(() => {
|
|
107
|
-
access = hasAccess(['pluss', 'sport'], ['all', 'plussalt', 'newspaper']);
|
|
108
|
-
});
|
|
109
|
-
itReturnsFalse();
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
let cookieResponse: any;
|
|
114
|
-
|
|
115
|
-
function itReturnsCookieResponse(success: any, accessFeatures: AccessFeatures) {
|
|
116
|
-
it(`returns cookie response with success = ${success}`, () => {
|
|
117
|
-
expect(cookieResponse.success).toEqual(success);
|
|
118
|
-
});
|
|
119
|
-
it(`returns cookie response with accessFeatures = ${accessFeatures}`, () => {
|
|
120
|
-
expect(cookieResponse.accessFeatures).toEqual(accessFeatures);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function itSetsNoCookies() {
|
|
125
|
-
it('does not set any cookies', () => {
|
|
126
|
-
expect(cookie.setCookie).not.toHaveBeenCalled();
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function itDoesNotSetVstokenCookie() {
|
|
131
|
-
it('does not set VSTOKEN cookie', () => {
|
|
132
|
-
expect(cookie.setCookie).not.toHaveBeenCalledWith('VSTOKEN');
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function itSetsVstokenCookie() {
|
|
137
|
-
it('sets VSTOKEN cookie', () => {
|
|
138
|
-
expect(cookie.setCookie).toHaveBeenCalledWith(
|
|
139
|
-
'VSTOKEN',
|
|
140
|
-
'COOKIE_VALUE',
|
|
141
|
-
365,
|
|
142
|
-
'/'
|
|
143
|
-
);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function itDoesNotSetVstoken2Cookie() {
|
|
148
|
-
it('does not set VSTOKEN2 cookie', () => {
|
|
149
|
-
expect(cookie.setCookie).not.toHaveBeenCalledWith('VSTOKEN2');
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function itSetsVstoken2Cookie() {
|
|
154
|
-
it('sets VSTOKEN2 cookie', () => {
|
|
155
|
-
expect(cookie.setCookie).toHaveBeenCalledWith(
|
|
156
|
-
'VSTOKEN2',
|
|
157
|
-
'COOKIE2_VALUE',
|
|
158
|
-
1,
|
|
159
|
-
'/'
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function mockGetUserAccess(status: any, accessFeatures: AccessFeatures) {
|
|
165
|
-
beforeEach(async () => {
|
|
166
|
-
jest.spyOn(jupiter, 'getUserAccess').mockResolvedValue({
|
|
167
|
-
status,
|
|
168
|
-
cookie: 'COOKIE_VALUE',
|
|
169
|
-
access_features: accessFeatures,
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function getUserAccessSucceeds(accessFeatures: AccessFeatures) {
|
|
175
|
-
mockGetUserAccess('success', accessFeatures);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function getUserAccessFails(accessFeatures: AccessFeatures) {
|
|
179
|
-
mockGetUserAccess('failure', accessFeatures);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function mockGetNonUserAccessSucceeds(
|
|
183
|
-
status: any,
|
|
184
|
-
accessFeatures: AccessFeatures
|
|
185
|
-
) {
|
|
186
|
-
beforeEach(async () => {
|
|
187
|
-
jest.spyOn(jupiter, 'getNonUserAccess').mockResolvedValue({
|
|
188
|
-
status,
|
|
189
|
-
uuid: 'mycompany',
|
|
190
|
-
vstoken_cookie: 'COOKIE2_VALUE',
|
|
191
|
-
access_features: accessFeatures,
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function getNonUserAccessSucceeds(accessFeatures: AccessFeatures) {
|
|
197
|
-
mockGetNonUserAccessSucceeds('success', accessFeatures);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function getNonUserAccessFails(accessFeatures: AccessFeatures) {
|
|
201
|
-
mockGetNonUserAccessSucceeds('failure', accessFeatures);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
describe('setUserAccessCookie', () => {
|
|
205
|
-
describe('when getUserAccess is successful', () => {
|
|
206
|
-
getUserAccessSucceeds(['newspaper', 'plussalt']);
|
|
207
|
-
beforeEach(async () => {
|
|
208
|
-
cookieResponse = await setUserAccessCookie(publicationDomain);
|
|
209
|
-
});
|
|
210
|
-
itReturnsCookieResponse(true, ['newspaper', 'plussalt']);
|
|
211
|
-
itSetsVstokenCookie();
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe('when getUserAccess is not successful', () => {
|
|
215
|
-
getUserAccessFails(['newspaper', 'plussalt']);
|
|
216
|
-
beforeEach(async () => {
|
|
217
|
-
cookieResponse = await setUserAccessCookie(publicationDomain);
|
|
218
|
-
});
|
|
219
|
-
itReturnsCookieResponse(false, ['newspaper', 'plussalt']);
|
|
220
|
-
itSetsNoCookies();
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe('setNonUserAccessCookie', () => {
|
|
225
|
-
describe('when getNonUserAccess is successful', () => {
|
|
226
|
-
getNonUserAccessSucceeds(['newspaper', 'plussalt']);
|
|
227
|
-
beforeEach(async () => {
|
|
228
|
-
cookieResponse = await setNonUserAccessCookie(publicationDomain);
|
|
229
|
-
});
|
|
230
|
-
itReturnsCookieResponse(true, ['newspaper', 'plussalt']);
|
|
231
|
-
itSetsVstoken2Cookie();
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
describe('when getNonUserAccess is not successful', () => {
|
|
235
|
-
getNonUserAccessFails(['newspaper', 'plussalt']);
|
|
236
|
-
beforeEach(async () => {
|
|
237
|
-
cookieResponse = await setNonUserAccessCookie(publicationDomain);
|
|
238
|
-
});
|
|
239
|
-
itReturnsCookieResponse(false, ['newspaper', 'plussalt']);
|
|
240
|
-
itSetsNoCookies();
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
describe('setAccessCookies', () => {
|
|
245
|
-
describe('when both VSTOKEN and VSTOKEN2 requests succeed', () => {
|
|
246
|
-
getUserAccessSucceeds(['newspaper', 'plussalt']);
|
|
247
|
-
getNonUserAccessSucceeds(['sport', 'pluss', 'newspaper']);
|
|
248
|
-
beforeEach(async () => {
|
|
249
|
-
cookieResponse = await setAccessCookies(publicationDomain);
|
|
250
|
-
});
|
|
251
|
-
itReturnsCookieResponse(true, ['newspaper', 'pluss', 'plussalt', 'sport']);
|
|
252
|
-
itSetsVstokenCookie();
|
|
253
|
-
itSetsVstoken2Cookie();
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
describe('when VSTOKEN fails and VSTOKEN2 succeeds', () => {
|
|
257
|
-
getUserAccessFails(['newspaper']);
|
|
258
|
-
getNonUserAccessSucceeds(['sport', 'pluss', 'newspaper']);
|
|
259
|
-
beforeEach(async () => {
|
|
260
|
-
cookieResponse = await setAccessCookies(publicationDomain);
|
|
261
|
-
});
|
|
262
|
-
itReturnsCookieResponse(false, ['newspaper', 'pluss', 'sport']);
|
|
263
|
-
itDoesNotSetVstokenCookie();
|
|
264
|
-
itSetsVstoken2Cookie();
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
describe('when VSTOKEN succeeds and VSTOKEN2 fails', () => {
|
|
268
|
-
getUserAccessSucceeds(['newspaper', 'plussalt']);
|
|
269
|
-
getNonUserAccessFails(['newspaper']);
|
|
270
|
-
beforeEach(async () => {
|
|
271
|
-
cookieResponse = await setAccessCookies(publicationDomain);
|
|
272
|
-
});
|
|
273
|
-
itReturnsCookieResponse(false, ['newspaper', 'plussalt']);
|
|
274
|
-
itSetsVstokenCookie();
|
|
275
|
-
itDoesNotSetVstoken2Cookie();
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
describe('when both VSTOKEN and VSTOKEN2 fails', () => {
|
|
279
|
-
getUserAccessFails(['newspaper', 'plussalt']);
|
|
280
|
-
getNonUserAccessFails(['newspaper']);
|
|
281
|
-
beforeEach(async () => {
|
|
282
|
-
cookieResponse = await setAccessCookies(publicationDomain);
|
|
283
|
-
});
|
|
284
|
-
itReturnsCookieResponse(false, ['newspaper', 'plussalt']);
|
|
285
|
-
itSetsNoCookies();
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
describe('reload loop protection', () => {
|
|
290
|
-
const currentUrl = 'http://www.avisnavn.no/myAwesomeArticle';
|
|
291
|
-
const otherUrl = 'https://www.avisnavn.no/someBoringArticle';
|
|
292
|
-
|
|
293
|
-
beforeEach(() => {
|
|
294
|
-
jest.spyOn(url, 'getCurrentUrl').mockReturnValue(currentUrl);
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
describe('setHasPerformedPaywallReload', () => {
|
|
298
|
-
describe('without requestedUrl', () => {
|
|
299
|
-
beforeEach(() => {
|
|
300
|
-
setHasPerformedPaywallReload();
|
|
301
|
-
});
|
|
302
|
-
it('sets aid-paywall-reload-performed with current URL as value', () => {
|
|
303
|
-
const twoMinutesFromNow = new Date().getTime() + 2 * 60 * 1000;
|
|
304
|
-
expect(cookie.setCookie).toHaveBeenCalledWith(
|
|
305
|
-
'aid-paywall-reload-performed',
|
|
306
|
-
currentUrl,
|
|
307
|
-
expect.toBeWithin(twoMinutesFromNow - 5000, twoMinutesFromNow + 5000)
|
|
308
|
-
);
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
describe('with requestedUrl', () => {
|
|
312
|
-
beforeEach(() => {
|
|
313
|
-
setHasPerformedPaywallReload(otherUrl);
|
|
314
|
-
});
|
|
315
|
-
it('sets aid-paywall-reload-performed with current URL as value', () => {
|
|
316
|
-
const twoMinutesFromNow = new Date().getTime() + 2 * 60 * 1000;
|
|
317
|
-
expect(cookie.setCookie).toHaveBeenCalledWith(
|
|
318
|
-
'aid-paywall-reload-performed',
|
|
319
|
-
otherUrl,
|
|
320
|
-
expect.toBeWithin(twoMinutesFromNow - 5000, twoMinutesFromNow + 5000)
|
|
321
|
-
);
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
describe('hasRecentlyPerformedPaywallReload', () => {
|
|
327
|
-
function itReturnsTrue() {
|
|
328
|
-
it('returns true', () => {
|
|
329
|
-
expect(hasRecentlyPerformedPaywallReload()).toBeTruthy();
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
function itReturnsFalse() {
|
|
333
|
-
it('returns false', () => {
|
|
334
|
-
expect(hasRecentlyPerformedPaywallReload()).toBeFalsy();
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
describe('when has recently tried to unlock paywall on same URL', () => {
|
|
338
|
-
beforeEach(() => {
|
|
339
|
-
setHasPerformedPaywallReload();
|
|
340
|
-
});
|
|
341
|
-
itReturnsTrue();
|
|
342
|
-
});
|
|
343
|
-
describe('when has recently tried to unlock paywall on different URL', () => {
|
|
344
|
-
beforeEach(() => {
|
|
345
|
-
jest
|
|
346
|
-
.spyOn(url, 'getCurrentUrl')
|
|
347
|
-
.mockReturnValueOnce(otherUrl)
|
|
348
|
-
.mockReturnValue(currentUrl);
|
|
349
|
-
setHasPerformedPaywallReload();
|
|
350
|
-
});
|
|
351
|
-
itReturnsFalse();
|
|
352
|
-
});
|
|
353
|
-
describe('when has recently tried to unlock paywall on different URL, and this URL is specified', () => {
|
|
354
|
-
beforeEach(() => {
|
|
355
|
-
jest
|
|
356
|
-
.spyOn(url, 'getCurrentUrl')
|
|
357
|
-
.mockReturnValueOnce(otherUrl) // This will be the value in our cookie
|
|
358
|
-
.mockReturnValue(currentUrl);
|
|
359
|
-
setHasPerformedPaywallReload();
|
|
360
|
-
});
|
|
361
|
-
it('returns true', () => {
|
|
362
|
-
expect(hasRecentlyPerformedPaywallReload(otherUrl)).toBeTruthy();
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
describe('when aid-paywall-reload-performed is not present', () => {
|
|
366
|
-
itReturnsFalse();
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
});
|