@amedia/user 0.13.24 → 0.13.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/amedia-frontend-rpc.d.ts +11 -0
- package/@types/browserid.d.ts +4 -0
- package/dist/actions/authorization.d.ts +5 -5
- package/dist/autologin/index.d.ts +4 -0
- package/dist/clients/mercuryLog.d.ts +5 -4
- package/dist/index.d.ts +43 -29
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/janitor/jobs/daxsubCookie.d.ts +2 -1
- package/dist/lib/PaywallUnlockRequest.d.ts +1 -1
- package/dist/lib/UserDataRequest.d.ts +1 -1
- package/dist/lib/rpc.d.ts +5 -5
- package/dist/utils/customEventWrapper.d.ts +5 -3
- package/dist/utils/deepEquals.d.ts +0 -3
- package/dist/utils/log.d.ts +4 -4
- package/dist/utils/queue.d.ts +2 -2
- package/dist/utils/type.d.ts +6 -0
- package/eik.json +1 -1
- package/package.json +1 -2
- package/src/actions/authorization.spec.ts +13 -9
- package/src/actions/authorization.ts +7 -5
- package/src/autologin/index.spec.ts +3 -3
- package/src/autologin/index.ts +6 -1
- package/src/cache/index.spec.ts +2 -2
- package/src/cache/index.ts +1 -2
- package/src/clients/europa.spec.ts +3 -3
- package/src/clients/europa.ts +9 -4
- package/src/clients/mercuryLog.ts +19 -11
- package/src/clients/pluto.spec.ts +4 -3
- package/src/eventHandlers/state.spec.ts +2 -2
- package/src/eventHandlers/storage.spec.ts +2 -2
- package/src/eventHandlers/userAttributes.spec.ts +2 -2
- package/src/index-authentcation.spec.ts +1 -1
- package/src/index-storage.spec.ts +3 -3
- package/src/index-subscription.spec.ts +1 -1
- package/src/index.ts +4 -8
- package/src/janitor/jobs/accessCookieRefresher.spec.ts +8 -2
- package/src/janitor/jobs/daxsubCookie.spec.ts +8 -2
- package/src/janitor/jobs/daxsubCookie.ts +4 -3
- package/src/lib/PaywallUnlockRequest.spec.ts +12 -12
- package/src/lib/PaywallUnlockRequest.ts +6 -3
- package/src/lib/UserDataRequest.spec.ts +3 -2
- package/src/lib/UserDataRequest.ts +4 -4
- package/src/lib/rpc.ts +7 -9
- package/src/store/index.ts +2 -0
- package/src/utils/customEventWrapper.ts +6 -6
- package/src/utils/deepEquals.ts +12 -11
- package/src/utils/getOrUpdate.ts +1 -1
- package/src/utils/log.spec.ts +4 -4
- package/src/utils/log.ts +24 -13
- package/src/utils/queue.ts +4 -4
- package/src/utils/type.ts +19 -0
- package/tsconfig.eslint.json +2 -0
- package/tsconfig.json +2 -1
- package/amedia-user-js.iml +0 -9
- package/dist/cache/engines/indexeddb.d.ts +0 -7
- package/dist/index.js.LICENSE.txt +0 -14
- package/dist/janitor/index.spec.d.ts +0 -4
- package/dist/lib/PaywallUnlocker.d.ts +0 -16
- package/dist/lib/PaywallUnlocker.spec.d.ts +0 -4
- package/dist/lib/User.d.ts +0 -21
- package/dist/utils/logValidationError.d.ts +0 -1
- package/esm/actions/authentication.d.ts +0 -5
- package/esm/actions/authentication.spec.d.ts +0 -4
- package/esm/actions/authorization.d.ts +0 -9
- package/esm/actions/preferences.d.ts +0 -9
- package/esm/actions/preferences.spec.d.ts +0 -1
- package/esm/actions/storage.d.ts +0 -4
- package/esm/actions/userData.d.ts +0 -2
- package/esm/autologin/index.d.ts +0 -1
- package/esm/autologin/thirdPartyCookie.d.ts +0 -3
- package/esm/autologin/thirdPartyCookie.spec.d.ts +0 -1
- package/esm/cache/engines/global.d.ts +0 -21
- package/esm/cache/engines/global.spec.d.ts +0 -1
- package/esm/cache/engines/indexeddb.d.ts +0 -7
- package/esm/cache/index.d.ts +0 -11
- package/esm/cache/index.spec.d.ts +0 -4
- package/esm/cache/types.d.ts +0 -11
- package/esm/clients/europa.d.ts +0 -28
- package/esm/clients/europa.spec.d.ts +0 -1
- package/esm/clients/jupiter.d.ts +0 -30
- package/esm/clients/jupiter.spec.d.ts +0 -1
- package/esm/clients/mercury.d.ts +0 -18
- package/esm/clients/mercury.spec.d.ts +0 -4
- package/esm/clients/nebula.d.ts +0 -2
- package/esm/clients/nebula.spec.d.ts +0 -1
- package/esm/clients/pluto.d.ts +0 -3
- package/esm/clients/pluto.spec.d.ts +0 -1
- package/esm/eventHandlers/activation.d.ts +0 -15
- package/esm/eventHandlers/authentication.d.ts +0 -17
- package/esm/eventHandlers/userAttributes.d.ts +0 -24
- package/esm/exceptions/PaywallError.d.ts +0 -7
- package/esm/index-authentcation.spec.d.ts +0 -4
- package/esm/index-storage.spec.d.ts +0 -4
- package/esm/index-subscription.spec.d.ts +0 -4
- package/esm/index.d.ts +0 -26
- package/esm/janitor/index.d.ts +0 -10
- package/esm/janitor/jobs/accessCookieRefresher.d.ts +0 -1
- package/esm/janitor/jobs/accessCookieRefresher.spec.d.ts +0 -4
- package/esm/lib/PaywallUnlocker.d.ts +0 -16
- package/esm/lib/PaywallUnlocker.spec.d.ts +0 -4
- package/esm/lib/User.d.ts +0 -21
- package/esm/lib/cookie.d.ts +0 -5
- package/esm/lib/rpc.d.ts +0 -6
- package/esm/store/index.d.ts +0 -22
- package/esm/store/index.spec.d.ts +0 -1
- package/esm/types.d.ts +0 -22
- package/esm/user.js +0 -2
- package/esm/user.js.map +0 -1
- package/esm/utils/customEventWrapper.d.ts +0 -17
- package/esm/utils/deepEquals.d.ts +0 -4
- package/esm/utils/getOrUpdate.d.ts +0 -6
- package/esm/utils/getOrUpdate.spec.d.ts +0 -1
- package/esm/utils/location.d.ts +0 -3
- package/esm/utils/log.d.ts +0 -26
- package/esm/utils/queue.d.ts +0 -12
- package/esm/utils/url.d.ts +0 -6
- package/esm/utils/url.spec.d.ts +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { State, UserAttributes } from '../types';
|
|
2
2
|
declare class UserDataRequest<UA extends UserAttributes, S extends {
|
|
3
3
|
[index: string]: unknown;
|
|
4
|
-
}, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends
|
|
4
|
+
}, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends Record<string, object> = {
|
|
5
5
|
state: State;
|
|
6
6
|
}> {
|
|
7
7
|
private attributes?;
|
package/dist/lib/rpc.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
userAuthenticated: (
|
|
4
|
-
}
|
|
5
|
-
export declare const getRPCClient: () =>
|
|
1
|
+
import { RPCclient } from '@amedia/frontend-rpc';
|
|
2
|
+
interface LocalRPCclient extends RPCclient {
|
|
3
|
+
userAuthenticated: (isLoggedIn: boolean) => void;
|
|
4
|
+
}
|
|
5
|
+
export declare const getRPCClient: () => LocalRPCclient;
|
|
6
6
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
declare let rootElement: Window | Element;
|
|
2
|
+
export declare const setRootElement: (element: typeof rootElement) => void;
|
|
2
3
|
/**
|
|
3
4
|
* This listener MUST be used by all listeners in ../eventHandlers
|
|
4
5
|
* We want to ensure that only _one_ instance of this package actually
|
|
@@ -6,12 +7,13 @@ export declare const setRootElement: (element: any) => void;
|
|
|
6
7
|
* @param type
|
|
7
8
|
* @param listener
|
|
8
9
|
*/
|
|
9
|
-
export declare const listenWithExclusivity: <T extends keyof WindowEventMap>(type: T, listener: (this:
|
|
10
|
+
export declare const listenWithExclusivity: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
|
|
10
11
|
/**
|
|
11
12
|
* Use this for response listeners. (../index.ts) where we want
|
|
12
13
|
* all updates with data - no matter who sent the actual request
|
|
13
14
|
* @param type
|
|
14
15
|
* @param listener
|
|
15
16
|
*/
|
|
16
|
-
export declare const listenForAllEvents: <T extends keyof WindowEventMap>(type: T, listener: (this:
|
|
17
|
+
export declare const listenForAllEvents: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
|
|
17
18
|
export declare const dispatch: <T extends Event>(event: T) => void;
|
|
19
|
+
export {};
|
package/dist/utils/log.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare type Logger = {
|
|
2
|
-
debug: (message: string | Error, context?:
|
|
3
|
-
info: (message: string | Error, context?:
|
|
4
|
-
warn: (message: string | Error, context?:
|
|
5
|
-
error: (message: string | Error, context?:
|
|
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
6
|
};
|
|
7
7
|
export declare const setLogger: (engine: Logger) => void;
|
|
8
8
|
declare const _default: Logger;
|
package/dist/utils/queue.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
add: (key: string, promiseCallbacks: {
|
|
3
|
-
resolve: (
|
|
3
|
+
resolve: (arg0?: any) => void;
|
|
4
4
|
reject: (reason?: any) => void;
|
|
5
5
|
}) => void;
|
|
6
6
|
getAll: (key: string) => {
|
|
7
|
-
resolve: (
|
|
7
|
+
resolve: (arg0?: any) => void;
|
|
8
8
|
reject: (reason?: any) => void;
|
|
9
9
|
}[];
|
|
10
10
|
peekQueueSize: (key: string) => number;
|
|
@@ -0,0 +1,6 @@
|
|
|
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/eik.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amedia/user",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.26",
|
|
4
4
|
"description": "Client lib for working with aID user and associated data",
|
|
5
5
|
"repository": "https://github.com/amedia/amedia-user-js",
|
|
6
6
|
"author": "Amedia Utvikling (ID og data)",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"@types/convict": "^6.1.1",
|
|
29
29
|
"@types/dexie": "^1.3.1",
|
|
30
30
|
"@types/jest": "^26.0.24",
|
|
31
|
-
"@types/lodash": "^4.14.172",
|
|
32
31
|
"@typescript-eslint/eslint-plugin": "^4.29.1",
|
|
33
32
|
"esbuild": "^0.12.19",
|
|
34
33
|
"eslint": "^7.32.0",
|
|
@@ -20,11 +20,12 @@ import * as authentication from './authentication';
|
|
|
20
20
|
import { setRootElement } from '../utils/customEventWrapper';
|
|
21
21
|
import { removeAllCookies } from '../lib/cookie';
|
|
22
22
|
import restoreAllMocks = jest.restoreAllMocks;
|
|
23
|
+
import { AccessFeatures } from '../clients/jupiter';
|
|
23
24
|
|
|
24
25
|
const publicationDomain = 'www.avisnavn.no';
|
|
25
26
|
|
|
26
27
|
beforeEach(() => {
|
|
27
|
-
setRootElement(new Document());
|
|
28
|
+
setRootElement(new Document().createElement('div'));
|
|
28
29
|
restoreAllMocks();
|
|
29
30
|
removeAllCookies();
|
|
30
31
|
jest.spyOn(cookie, 'setCookie');
|
|
@@ -113,9 +114,9 @@ describe('hasAccess', () => {
|
|
|
113
114
|
});
|
|
114
115
|
});
|
|
115
116
|
|
|
116
|
-
let cookieResponse;
|
|
117
|
+
let cookieResponse: any;
|
|
117
118
|
|
|
118
|
-
function itReturnsCookieResponse(success, accessFeatures) {
|
|
119
|
+
function itReturnsCookieResponse(success: any, accessFeatures: AccessFeatures) {
|
|
119
120
|
it(`returns cookie response with success = ${success}`, () => {
|
|
120
121
|
expect(cookieResponse.success).toEqual(success);
|
|
121
122
|
});
|
|
@@ -164,7 +165,7 @@ function itSetsVstoken2Cookie() {
|
|
|
164
165
|
});
|
|
165
166
|
}
|
|
166
167
|
|
|
167
|
-
function mockGetUserAccess(status, accessFeatures) {
|
|
168
|
+
function mockGetUserAccess(status: any, accessFeatures: AccessFeatures) {
|
|
168
169
|
beforeEach(async () => {
|
|
169
170
|
jest.spyOn(jupiter, 'getUserAccess').mockResolvedValue({
|
|
170
171
|
status,
|
|
@@ -174,15 +175,18 @@ function mockGetUserAccess(status, accessFeatures) {
|
|
|
174
175
|
});
|
|
175
176
|
}
|
|
176
177
|
|
|
177
|
-
function getUserAccessSucceeds(accessFeatures) {
|
|
178
|
+
function getUserAccessSucceeds(accessFeatures: AccessFeatures) {
|
|
178
179
|
mockGetUserAccess('success', accessFeatures);
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
function getUserAccessFails(accessFeatures) {
|
|
182
|
+
function getUserAccessFails(accessFeatures: AccessFeatures) {
|
|
182
183
|
mockGetUserAccess('failure', accessFeatures);
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
function mockGetNonUserAccessSucceeds(
|
|
186
|
+
function mockGetNonUserAccessSucceeds(
|
|
187
|
+
status: any,
|
|
188
|
+
accessFeatures: AccessFeatures
|
|
189
|
+
) {
|
|
186
190
|
beforeEach(async () => {
|
|
187
191
|
jest.spyOn(jupiter, 'getNonUserAccess').mockResolvedValue({
|
|
188
192
|
status,
|
|
@@ -193,11 +197,11 @@ function mockGetNonUserAccessSucceeds(status, accessFeatures) {
|
|
|
193
197
|
});
|
|
194
198
|
}
|
|
195
199
|
|
|
196
|
-
function getNonUserAccessSucceeds(accessFeatures) {
|
|
200
|
+
function getNonUserAccessSucceeds(accessFeatures: AccessFeatures) {
|
|
197
201
|
mockGetNonUserAccessSucceeds('success', accessFeatures);
|
|
198
202
|
}
|
|
199
203
|
|
|
200
|
-
function getNonUserAccessFails(accessFeatures) {
|
|
204
|
+
function getNonUserAccessFails(accessFeatures: AccessFeatures) {
|
|
201
205
|
mockGetNonUserAccessSucceeds('failure', accessFeatures);
|
|
202
206
|
}
|
|
203
207
|
|
|
@@ -38,7 +38,7 @@ export const hasAccess = (
|
|
|
38
38
|
).length > 0;
|
|
39
39
|
|
|
40
40
|
export const setUserAccessCookie = async (
|
|
41
|
-
publicationDomain
|
|
41
|
+
publicationDomain: string
|
|
42
42
|
): Promise<SetCookieResponse> => {
|
|
43
43
|
const vstoken = await getUserAccess(publicationDomain);
|
|
44
44
|
if (vstoken.status === 'success') {
|
|
@@ -56,7 +56,7 @@ export const setUserAccessCookie = async (
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
export const setNonUserAccessCookie = async (
|
|
59
|
-
publicationDomain
|
|
59
|
+
publicationDomain: string
|
|
60
60
|
): Promise<SetCookieResponse> => {
|
|
61
61
|
const vstoken2 = await getNonUserAccess(publicationDomain);
|
|
62
62
|
if (vstoken2.status === 'success') {
|
|
@@ -69,7 +69,7 @@ export const setNonUserAccessCookie = async (
|
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
export const setAccessCookies = async (
|
|
72
|
-
publicationDomain
|
|
72
|
+
publicationDomain: string
|
|
73
73
|
): Promise<SetCookieResponse> => {
|
|
74
74
|
const setters: Array<Promise<SetCookieResponse>> = [];
|
|
75
75
|
setters.push(
|
|
@@ -99,7 +99,7 @@ export const setAccessCookies = async (
|
|
|
99
99
|
);
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
export const setHasPerformedPaywallReload = (requestedUrl
|
|
102
|
+
export const setHasPerformedPaywallReload = (requestedUrl?: string): void => {
|
|
103
103
|
const expires = new Date();
|
|
104
104
|
expires.setTime(expires.getTime() + 2 * 60 * 1000); // Add two minutes
|
|
105
105
|
|
|
@@ -110,6 +110,8 @@ export const setHasPerformedPaywallReload = (requestedUrl?): void => {
|
|
|
110
110
|
);
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
export const hasRecentlyPerformedPaywallReload = (
|
|
113
|
+
export const hasRecentlyPerformedPaywallReload = (
|
|
114
|
+
requestedUrl?: string
|
|
115
|
+
): boolean =>
|
|
114
116
|
getCookie('aid-paywall-reload-performed') ===
|
|
115
117
|
(requestedUrl || getCurrentUrl());
|
|
@@ -31,7 +31,7 @@ function itShouldCallThirdPartyCookieStrategy() {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function itShouldNavigateToAutoLogin(context) {
|
|
34
|
+
function itShouldNavigateToAutoLogin(context: string) {
|
|
35
35
|
it(`should navigate to auto with context ${context}`, async () => {
|
|
36
36
|
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
37
37
|
`https://www.aid.no/aid/logg_inn/auto?context=auto_login_${context}&requestedUrl=https%3A%2F%2Fwww.avisnavn.no%2Fabo%2F%3Fquery%3Dparam`
|
|
@@ -102,7 +102,7 @@ describe('attemptAutoLoginJob', () => {
|
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
describe('when in iframe (Dr. Edition)', () => {
|
|
105
|
-
let originalTop;
|
|
105
|
+
let originalTop: Window;
|
|
106
106
|
beforeEach(async () => {
|
|
107
107
|
originalTop = global.top;
|
|
108
108
|
// @ts-ignore
|
|
@@ -199,7 +199,7 @@ describe('attemptPaywallAutoLogin', () => {
|
|
|
199
199
|
});
|
|
200
200
|
|
|
201
201
|
describe('when in iframe (Dr. Edition)', () => {
|
|
202
|
-
let originalTop;
|
|
202
|
+
let originalTop: Window;
|
|
203
203
|
beforeEach(async () => {
|
|
204
204
|
originalTop = global.top;
|
|
205
205
|
// @ts-ignore
|
package/src/autologin/index.ts
CHANGED
|
@@ -4,6 +4,11 @@ import { navigateTo } from '../utils/location';
|
|
|
4
4
|
import { getCookie, removeCookie, setCookie } from '../lib/cookie';
|
|
5
5
|
import UserDataRequest from '../lib/UserDataRequest';
|
|
6
6
|
|
|
7
|
+
export type Strategies = Array<{
|
|
8
|
+
name: string;
|
|
9
|
+
handler: () => Promise<boolean>;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
7
12
|
const AUTOLOGIN_COOKIE = 'has-tried-autologin';
|
|
8
13
|
export const AUTOLOGIN_COOKIE_TTL = 60000; // One minute
|
|
9
14
|
|
|
@@ -30,7 +35,7 @@ function hasAlreadyAttemptedAutoLogin() {
|
|
|
30
35
|
return false;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
const attemptAutologin = async (strategies) => {
|
|
38
|
+
const attemptAutologin = async (strategies: Strategies) => {
|
|
34
39
|
if (inIframe()) {
|
|
35
40
|
// Avoid auto-login on preview for dr edition.
|
|
36
41
|
return;
|
package/src/cache/index.spec.ts
CHANGED
package/src/cache/index.ts
CHANGED
|
@@ -30,8 +30,7 @@ const get = async <T extends RuntypeBase>(
|
|
|
30
30
|
return Promise.resolve();
|
|
31
31
|
}
|
|
32
32
|
try {
|
|
33
|
-
|
|
34
|
-
return typedData as T;
|
|
33
|
+
return validator.check(cacheEntry.data);
|
|
35
34
|
} catch (error) {
|
|
36
35
|
log.error(error, { cacheData: cacheEntry.data });
|
|
37
36
|
remove(key);
|
|
@@ -98,7 +98,7 @@ describe('Europa', () => {
|
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
describe('getNamespaces', () => {
|
|
101
|
-
let response;
|
|
101
|
+
let response: any;
|
|
102
102
|
describe('with cold cache', () => {
|
|
103
103
|
describe('with one namespace', () => {
|
|
104
104
|
const data = { euucp: { x: 'x' } };
|
|
@@ -125,7 +125,7 @@ describe('getNamespaces', () => {
|
|
|
125
125
|
describe('when doing sequence of calls for different namespaces', () => {
|
|
126
126
|
const data = { euucp: { x: 'x' } };
|
|
127
127
|
const data2 = { user_info: { a: 'a' } };
|
|
128
|
-
let response2;
|
|
128
|
+
let response2: any;
|
|
129
129
|
beforeEach(async () => {
|
|
130
130
|
fetch.mockResponseOnce(JSON.stringify({ namespaces: data }));
|
|
131
131
|
fetch.mockResponseOnce(JSON.stringify({ namespaces: data2 }));
|
|
@@ -141,7 +141,7 @@ describe('getNamespaces', () => {
|
|
|
141
141
|
describe('when doing sequence of calls for different namespaces before first response returns', () => {
|
|
142
142
|
const data = { euucp: { x: 'x' } };
|
|
143
143
|
const data2 = { user_info: { a: 'a' } };
|
|
144
|
-
let response2;
|
|
144
|
+
let response2: any;
|
|
145
145
|
beforeEach(async () => {
|
|
146
146
|
fetch.mockResponseOnce(JSON.stringify({ namespaces: data }));
|
|
147
147
|
fetch.mockResponseOnce(JSON.stringify({ namespaces: data2 }));
|
package/src/clients/europa.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Record, Unknown, Dictionary, String } from 'runtypes';
|
|
1
|
+
import { Record, Unknown, Dictionary, String, Static } from 'runtypes';
|
|
2
2
|
|
|
3
3
|
import cache from '../cache';
|
|
4
4
|
import getOrUpdate from '../utils/getOrUpdate';
|
|
@@ -20,7 +20,10 @@ const doFetch = (url: string, method: string = 'GET', body?: Object) =>
|
|
|
20
20
|
},
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
function mergeCache(
|
|
23
|
+
function mergeCache(
|
|
24
|
+
cachedData: Static<typeof EuropaSchema>,
|
|
25
|
+
newData: Static<typeof EuropaSchema>
|
|
26
|
+
) {
|
|
24
27
|
return {
|
|
25
28
|
namespaces: Object.entries(newData.namespaces).reduce(
|
|
26
29
|
(mergedNamespaces, [namespace, data]) => ({
|
|
@@ -34,7 +37,7 @@ function mergeCache(cachedData, newData) {
|
|
|
34
37
|
|
|
35
38
|
const updateNamespaceInCache = async (namespace: string, data: Object) => {
|
|
36
39
|
const cachedData = await cache.get('europa', EuropaSchema);
|
|
37
|
-
const updatedData = mergeCache(cachedData, {
|
|
40
|
+
const updatedData = mergeCache(cachedData || { namespaces: {} }, {
|
|
38
41
|
namespaces: { [namespace]: data },
|
|
39
42
|
});
|
|
40
43
|
return cache.set('europa', updatedData, Date.now() + CACHE_DURATION);
|
|
@@ -64,7 +67,9 @@ export const getNamespaces = async <
|
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
let missingNamespaces = namespaces as string[];
|
|
67
|
-
const cachedData = await cache.get('europa', EuropaSchema)
|
|
70
|
+
const cachedData = (await cache.get('europa', EuropaSchema)) || {
|
|
71
|
+
namespaces: {},
|
|
72
|
+
};
|
|
68
73
|
if (!options.ignoreCache) {
|
|
69
74
|
missingNamespaces = (
|
|
70
75
|
cachedData
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { getCurrentHostname, getCurrentUrl } from '../utils/url';
|
|
2
|
+
import { isBoolean, isNumber, isString } from '../utils/type';
|
|
3
|
+
|
|
4
|
+
type Context = Record<string, unknown>;
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* Extracted from mercury.tsx so other calls to mercury can log properly
|
|
@@ -20,17 +23,22 @@ function postLog(url: string, query: { [index: string]: any }) {
|
|
|
20
23
|
});
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
const backendLog = (level: string, message: string, context:
|
|
24
|
-
const internalContext = {};
|
|
26
|
+
const backendLog = (level: string, message: string, context: Context) => {
|
|
27
|
+
const internalContext: Context = {};
|
|
25
28
|
Object.keys(context).forEach((key) => {
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
const currentContext = context[key];
|
|
30
|
+
if (
|
|
31
|
+
isString(currentContext) ||
|
|
32
|
+
isNumber(currentContext) ||
|
|
33
|
+
isBoolean(currentContext)
|
|
34
|
+
) {
|
|
35
|
+
internalContext[key] = currentContext;
|
|
28
36
|
return;
|
|
29
37
|
}
|
|
30
38
|
try {
|
|
31
|
-
internalContext[key] = JSON.stringify(
|
|
32
|
-
} catch
|
|
33
|
-
internalContext[key] =
|
|
39
|
+
internalContext[key] = JSON.stringify(currentContext);
|
|
40
|
+
} catch {
|
|
41
|
+
internalContext[key] = currentContext;
|
|
34
42
|
}
|
|
35
43
|
});
|
|
36
44
|
const extendedContext = {
|
|
@@ -43,13 +51,13 @@ const backendLog = (level: string, message: string, context: Object) => {
|
|
|
43
51
|
};
|
|
44
52
|
|
|
45
53
|
const log = {
|
|
46
|
-
error: (message: string, context:
|
|
54
|
+
error: (message: string, context: Context) =>
|
|
47
55
|
backendLog('error', message, context),
|
|
48
|
-
warn: (message: string, context:
|
|
56
|
+
warn: (message: string, context: Context) =>
|
|
49
57
|
backendLog('warn', message, context),
|
|
50
|
-
info: (message: string, context:
|
|
58
|
+
info: (message: string, context: Context) =>
|
|
51
59
|
backendLog('info', message, context),
|
|
52
|
-
debug: (message: string, context:
|
|
60
|
+
debug: (message: string, context: Context) =>
|
|
53
61
|
backendLog('debug', message, context),
|
|
54
62
|
};
|
|
55
63
|
|
|
@@ -2,8 +2,9 @@ import fetch from 'jest-fetch-mock';
|
|
|
2
2
|
import cache from '../cache';
|
|
3
3
|
import store from '../store';
|
|
4
4
|
import { getCurrentSession, removeSession } from './pluto';
|
|
5
|
-
import { setLogger } from '../utils/log';
|
|
5
|
+
import { Logger, setLogger } from '../utils/log';
|
|
6
6
|
import restoreAllMocks = jest.restoreAllMocks;
|
|
7
|
+
import { UserAttributes } from '../types';
|
|
7
8
|
|
|
8
9
|
beforeEach(async () => {
|
|
9
10
|
restoreAllMocks();
|
|
@@ -24,7 +25,7 @@ const plutoLoggedInResponse = {
|
|
|
24
25
|
tracking_key: userTrackingKey,
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
let log;
|
|
28
|
+
let log: Logger;
|
|
28
29
|
beforeEach(() => {
|
|
29
30
|
log = {
|
|
30
31
|
debug: jest.fn(),
|
|
@@ -49,7 +50,7 @@ describe('Pluto service', () => {
|
|
|
49
50
|
beforeEach(() => {
|
|
50
51
|
jest.spyOn(store, 'merge');
|
|
51
52
|
});
|
|
52
|
-
let currentSession;
|
|
53
|
+
let currentSession: UserAttributes;
|
|
53
54
|
function itShouldReturnSessionData() {
|
|
54
55
|
it('should return session data', async () => {
|
|
55
56
|
expect(currentSession).toEqual({
|
|
@@ -13,13 +13,13 @@ import { listenForStateRequests } from './state';
|
|
|
13
13
|
import restoreAllMocks = jest.restoreAllMocks;
|
|
14
14
|
|
|
15
15
|
beforeEach(() => {
|
|
16
|
-
setRootElement(new Document());
|
|
16
|
+
setRootElement(new Document().createElement('div'));
|
|
17
17
|
restoreAllMocks();
|
|
18
18
|
store.clear();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
describe('listenForUserAttributeRequests', () => {
|
|
22
|
-
let currentState;
|
|
22
|
+
let currentState: any;
|
|
23
23
|
beforeEach(() => {
|
|
24
24
|
listenForAllEvents(AmediaUserEvents.ON_STATE_UPDATED, (evt) => {
|
|
25
25
|
currentState = evt.detail;
|
|
@@ -15,13 +15,13 @@ import { AmediaUserEvents } from './eventMap';
|
|
|
15
15
|
import restoreAllMocks = jest.restoreAllMocks;
|
|
16
16
|
|
|
17
17
|
beforeEach(() => {
|
|
18
|
-
setRootElement(new Document());
|
|
18
|
+
setRootElement(new Document().createElement('div'));
|
|
19
19
|
restoreAllMocks();
|
|
20
20
|
store.clear();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
describe('listenForStorageRequests', () => {
|
|
24
|
-
let currentStorage;
|
|
24
|
+
let currentStorage: any;
|
|
25
25
|
beforeEach(() => {
|
|
26
26
|
listenForAllEvents(AmediaUserEvents.ON_STORAGE_UPDATED, (evt) => {
|
|
27
27
|
currentStorage = evt.detail;
|
|
@@ -14,13 +14,13 @@ import { AmediaUserEvents } from './eventMap';
|
|
|
14
14
|
import restoreAllMocks = jest.restoreAllMocks;
|
|
15
15
|
|
|
16
16
|
beforeEach(() => {
|
|
17
|
-
setRootElement(new Document());
|
|
17
|
+
setRootElement(new Document().createElement('div'));
|
|
18
18
|
restoreAllMocks();
|
|
19
19
|
store.clear();
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
describe('listenForUserAttributeRequests', () => {
|
|
23
|
-
let currentAttributes;
|
|
23
|
+
let currentAttributes: any;
|
|
24
24
|
beforeEach(() => {
|
|
25
25
|
listenForAllEvents(AmediaUserEvents.ON_ATTRIBUTES_UPDATED, (evt) => {
|
|
26
26
|
currentAttributes = evt.detail;
|
|
@@ -13,7 +13,7 @@ beforeEach(() => {
|
|
|
13
13
|
|
|
14
14
|
// We cannot use window as our event root during testing
|
|
15
15
|
// since tests are executed in parallel.
|
|
16
|
-
setRootElement(new Document());
|
|
16
|
+
setRootElement(new Document().createElement('div'));
|
|
17
17
|
|
|
18
18
|
// Also, since we keep creating new root elements, we also
|
|
19
19
|
// need to attach to these new roots.
|
|
@@ -16,7 +16,7 @@ beforeEach(() => {
|
|
|
16
16
|
|
|
17
17
|
// We cannot use window as our event root during testing
|
|
18
18
|
// since tests are executed in parallel.
|
|
19
|
-
setRootElement(new Document());
|
|
19
|
+
setRootElement(new Document().createElement('div'));
|
|
20
20
|
|
|
21
21
|
// Store must be cleared before we re-listen for user attribute requests
|
|
22
22
|
store.clear();
|
|
@@ -53,7 +53,7 @@ describe('Storage', () => {
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
describe('when getting storage namespaces', () => {
|
|
56
|
-
let onUpdate;
|
|
56
|
+
let onUpdate: any;
|
|
57
57
|
beforeEach(() => {
|
|
58
58
|
store.set('storage', {
|
|
59
59
|
one: { key1: 'value1' },
|
|
@@ -102,7 +102,7 @@ describe('Storage', () => {
|
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
describe('when getting storage namespaces', () => {
|
|
105
|
-
let onUpdate;
|
|
105
|
+
let onUpdate: any;
|
|
106
106
|
beforeEach(() => {
|
|
107
107
|
store.set('storage', {
|
|
108
108
|
one: { key1: 'value1' },
|
|
@@ -15,7 +15,7 @@ beforeEach(() => {
|
|
|
15
15
|
|
|
16
16
|
// We cannot use window as our event root during testing
|
|
17
17
|
// since tests are executed in parallel.
|
|
18
|
-
setRootElement(new Document());
|
|
18
|
+
setRootElement(new Document().createElement('div'));
|
|
19
19
|
|
|
20
20
|
// Store must be cleared before we re-listen for user attribute requests
|
|
21
21
|
store.clear();
|
package/src/index.ts
CHANGED
|
@@ -46,11 +46,7 @@ export const updateStorage = (storage: { [index: string]: Object }) => {
|
|
|
46
46
|
);
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
listenForUserAttributeRequests();
|
|
54
|
-
listenForStorageRequests();
|
|
55
|
-
runJanitor();
|
|
56
|
-
}
|
|
49
|
+
listenForStateRequests();
|
|
50
|
+
listenForUserAttributeRequests();
|
|
51
|
+
listenForStorageRequests();
|
|
52
|
+
runJanitor();
|
|
@@ -11,11 +11,12 @@ import { setRootElement } from '../../utils/customEventWrapper';
|
|
|
11
11
|
import store from '../../store';
|
|
12
12
|
import restoreAllMocks = jest.restoreAllMocks;
|
|
13
13
|
import spyOn = jest.spyOn;
|
|
14
|
+
import { AccessFeatures } from '../../clients/jupiter';
|
|
14
15
|
|
|
15
16
|
const mockUuid = '3-1-33-7';
|
|
16
17
|
|
|
17
18
|
beforeEach(() => {
|
|
18
|
-
setRootElement(new Document());
|
|
19
|
+
setRootElement(new Document().createElement('div'));
|
|
19
20
|
restoreAllMocks();
|
|
20
21
|
spyOn(url, 'getCurrentPublicationDomain').mockReturnValue('www.avisnavn.no');
|
|
21
22
|
url.setCurrentHostname('www.avisnavn.no');
|
|
@@ -31,7 +32,12 @@ beforeEach(() => {
|
|
|
31
32
|
);
|
|
32
33
|
});
|
|
33
34
|
|
|
34
|
-
function mockAccessCookie(
|
|
35
|
+
function mockAccessCookie(
|
|
36
|
+
validHours: number,
|
|
37
|
+
uuid: string,
|
|
38
|
+
accessFeatures: AccessFeatures,
|
|
39
|
+
domain: string
|
|
40
|
+
) {
|
|
35
41
|
const validTo = new Date();
|
|
36
42
|
validTo.setHours(validTo.getHours() + validHours);
|
|
37
43
|
return `signature:${Math.round(
|
|
@@ -22,7 +22,7 @@ describe('daxSubCookieHandler', () => {
|
|
|
22
22
|
|
|
23
23
|
// We cannot use window as our event root during testing
|
|
24
24
|
// since tests are executed in parallel.
|
|
25
|
-
setRootElement(new Document());
|
|
25
|
+
setRootElement(new Document().createElement('div'));
|
|
26
26
|
|
|
27
27
|
// Also, since we keep creating new root elements, we also
|
|
28
28
|
// need to attach to these new roots.
|
|
@@ -50,7 +50,11 @@ describe('daxSubCookieHandler', () => {
|
|
|
50
50
|
describe('when user is not logged in', () => {
|
|
51
51
|
beforeEach(async () => {
|
|
52
52
|
store.set('state', { isLoggedIn: false });
|
|
53
|
-
store.set('userAttributes', {
|
|
53
|
+
store.set('userAttributes', {
|
|
54
|
+
uuid: null,
|
|
55
|
+
trackingKey: null,
|
|
56
|
+
extraData: {},
|
|
57
|
+
});
|
|
54
58
|
await daxSubCookieHandler();
|
|
55
59
|
});
|
|
56
60
|
|
|
@@ -71,6 +75,7 @@ describe('daxSubCookieHandler', () => {
|
|
|
71
75
|
describe('when has subscription', () => {
|
|
72
76
|
beforeEach(async () => {
|
|
73
77
|
store.set('userAttributes', {
|
|
78
|
+
uuid: 'uuid',
|
|
74
79
|
extraData: {
|
|
75
80
|
customer_keys: 'someString',
|
|
76
81
|
},
|
|
@@ -95,6 +100,7 @@ describe('daxSubCookieHandler', () => {
|
|
|
95
100
|
describe('when has no subscription', () => {
|
|
96
101
|
beforeEach(async () => {
|
|
97
102
|
store.set('userAttributes', {
|
|
103
|
+
uuid: 'uuid',
|
|
98
104
|
extraData: {},
|
|
99
105
|
trackingKey: '148d24b2-f28e-4b1c-9958-8abd5066fc59',
|
|
100
106
|
});
|