@amedia/user 0.11.0 → 0.12.1
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/.eik/eik.json +10 -0
- package/.eik/eik.tgz +0 -0
- package/.eik/integrity.json +6 -6
- package/.eik/user.js +2 -0
- package/.eik/user.js.map +1 -0
- package/README.md +67 -22
- package/dist/index.js +1 -1
- package/dist/janitor/index.d.ts +9 -0
- package/eik.json +1 -1
- package/package.json +4 -3
- package/src/actions/authentication.spec.ts +4 -3
- package/src/actions/authentication.ts +3 -1
- package/src/autologin/thirdPartyCookie.spec.ts +1 -1
- package/src/autologin/thirdPartyCookie.ts +1 -0
- package/src/index.ts +3 -0
- package/src/janitor/index.ts +30 -2
- package/src/janitor/jobs/accessCookieRefresher.ts +2 -2
|
@@ -9,6 +9,7 @@ import restoreAllMocks = jest.restoreAllMocks;
|
|
|
9
9
|
|
|
10
10
|
beforeEach(() => {
|
|
11
11
|
restoreAllMocks();
|
|
12
|
+
spyOn(url, 'getCurrentPublicationDomain').and.returnValue('www.telen.no');
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
describe('authentication', () => {
|
|
@@ -18,7 +19,7 @@ describe('authentication', () => {
|
|
|
18
19
|
spyOn(location, 'navigateTo');
|
|
19
20
|
login('current');
|
|
20
21
|
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
21
|
-
'https://www.aid.no.localhost.api.no/aid/logg_inn/?requestedUrl=current'
|
|
22
|
+
'https://www.aid.no.localhost.api.no/aid/logg_inn/www.telen.no/?requestedUrl=current'
|
|
22
23
|
);
|
|
23
24
|
});
|
|
24
25
|
it('should resolve snap5 env', () => {
|
|
@@ -26,7 +27,7 @@ describe('authentication', () => {
|
|
|
26
27
|
spyOn(location, 'navigateTo');
|
|
27
28
|
login('current');
|
|
28
29
|
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
29
|
-
'https://www-snap5.aid.no/aid/logg_inn/?requestedUrl=current'
|
|
30
|
+
'https://www-snap5.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=current'
|
|
30
31
|
);
|
|
31
32
|
});
|
|
32
33
|
it('should resolve prod env', () => {
|
|
@@ -34,7 +35,7 @@ describe('authentication', () => {
|
|
|
34
35
|
spyOn(location, 'navigateTo');
|
|
35
36
|
login('current');
|
|
36
37
|
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
37
|
-
'https://www.aid.no/aid/logg_inn/?requestedUrl=current'
|
|
38
|
+
'https://www.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=current'
|
|
38
39
|
);
|
|
39
40
|
});
|
|
40
41
|
});
|
|
@@ -13,7 +13,9 @@ import store from '../store';
|
|
|
13
13
|
import { navigateTo } from '../utils/location';
|
|
14
14
|
|
|
15
15
|
export const login = (requestedUrl: URL | string) => {
|
|
16
|
-
const url = new URL(
|
|
16
|
+
const url = new URL(
|
|
17
|
+
`https://${getAidDomain()}/aid/logg_inn/${getCurrentPublicationDomain()}/`
|
|
18
|
+
);
|
|
17
19
|
url.searchParams.set(
|
|
18
20
|
'requestedUrl',
|
|
19
21
|
requestedUrl instanceof URL
|
|
@@ -100,7 +100,7 @@ describe('Autologin: Third Party Cookie', () => {
|
|
|
100
100
|
itShouldSetAlreadyTriedCache();
|
|
101
101
|
it('should navigate to auto', async () => {
|
|
102
102
|
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
103
|
-
'https://www.aid.no/logg_inn/auto/?requestedUrl=https%3A%2F%2Favisnavn.no%2Fabo%2F%3Fquery%3Dparam'
|
|
103
|
+
'https://www.aid.no/logg_inn/auto/?context=third_party&requestedUrl=https%3A%2F%2Favisnavn.no%2Fabo%2F%3Fquery%3Dparam'
|
|
104
104
|
);
|
|
105
105
|
});
|
|
106
106
|
});
|
|
@@ -62,6 +62,7 @@ export default async function thirdPartyCookie() {
|
|
|
62
62
|
if (aidSession) {
|
|
63
63
|
// Try to get newspaper cookie
|
|
64
64
|
const url = new URL(`https://${getAidDomain()}/logg_inn/auto/`);
|
|
65
|
+
url.searchParams.set('context', 'third_party');
|
|
65
66
|
url.searchParams.set('requestedUrl', getCurrentUrl());
|
|
66
67
|
navigateTo(url.href);
|
|
67
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import User from './lib/User';
|
|
|
6
6
|
import PaywallUnlocker from './lib/PaywallUnlocker';
|
|
7
7
|
import { AmediaUserEvents } from './eventHandlers/userAttributes';
|
|
8
8
|
import { getCurrentUrl } from './utils/url';
|
|
9
|
+
import { runJanitor } from './janitor';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Enables you to subscribe to the user attributes you care about and
|
|
@@ -43,3 +44,5 @@ export const updateStorage = (storage: { [index: string]: Object }): void =>
|
|
|
43
44
|
dispatch(
|
|
44
45
|
new CustomEvent(AmediaUserEvents.UPDATE_STORAGE, { detail: storage })
|
|
45
46
|
);
|
|
47
|
+
|
|
48
|
+
runJanitor();
|
package/src/janitor/index.ts
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import accessCookieRefresher from './jobs/accessCookieRefresher';
|
|
2
|
+
import { dispatch, listenWithExclusivity } from '../utils/customEventWrapper';
|
|
3
|
+
import { attemptAutologin } from '../autologin';
|
|
2
4
|
|
|
3
|
-
const jobs = [accessCookieRefresher];
|
|
5
|
+
const jobs = [attemptAutologin, accessCookieRefresher];
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
async function performJobs() {
|
|
6
8
|
// eslint-disable-next-line no-restricted-syntax
|
|
7
9
|
for (const job of jobs) {
|
|
8
10
|
// eslint-disable-next-line no-await-in-loop
|
|
9
11
|
await job();
|
|
10
12
|
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
enum JanitorEvents {
|
|
16
|
+
LOADED = 'amedia-user.janitor.loaded',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare global {
|
|
20
|
+
interface WindowEventMap {
|
|
21
|
+
[JanitorEvents.LOADED]: CustomEvent<{}>;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// We want to ensure that the Janitor is started exactly once. The trick here is to
|
|
26
|
+
// listen to an event end if we receive it exclusively, we know that we are the first
|
|
27
|
+
// to load this script and therefore responsible for running the Janitor once.
|
|
28
|
+
export const runJanitor = async () => {
|
|
29
|
+
let janitorStarted = false;
|
|
30
|
+
listenWithExclusivity(JanitorEvents.LOADED, () => {
|
|
31
|
+
if (janitorStarted) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
janitorStarted = true;
|
|
36
|
+
performJobs();
|
|
37
|
+
});
|
|
38
|
+
dispatch(new CustomEvent(JanitorEvents.LOADED));
|
|
11
39
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCookie, removeCookie } from '../../lib/cookie';
|
|
2
|
-
import
|
|
2
|
+
import User from '../../lib/User';
|
|
3
3
|
import {
|
|
4
4
|
setNonUserAccessCookie,
|
|
5
5
|
setUserAccessCookie,
|
|
@@ -11,7 +11,7 @@ async function verifyAndSetUserAccessCookie() {
|
|
|
11
11
|
const cookie = getCookie('VSTOKEN');
|
|
12
12
|
let hasVerifiedVstoken = false;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
new User()
|
|
15
15
|
.withAttributes(['uuid'])
|
|
16
16
|
.subscribe(async ({ attributes, state }) => {
|
|
17
17
|
if (state.isLoggedIn === false) {
|