@amedia/user 0.13.19 → 0.13.21
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/index.d.ts +6 -6
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/types.d.ts +6 -6
- package/package.json +1 -1
- package/src/actions/userData.ts +11 -2
- package/src/clients/pluto.spec.ts +10 -16
- package/src/clients/pluto.ts +4 -9
- package/src/eventHandlers/eventMap.ts +1 -0
- package/src/janitor/jobs/accessCookieRefresher.ts +2 -13
- package/src/types.ts +6 -6
package/dist/types.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export declare type UserAttributes = {
|
|
2
|
-
uuid?: string;
|
|
3
|
-
name?: string;
|
|
4
|
-
email?: string;
|
|
5
|
-
phone?: string;
|
|
6
|
-
trackingKey?: string;
|
|
2
|
+
uuid?: string | null;
|
|
3
|
+
name?: string | null;
|
|
4
|
+
email?: string | null;
|
|
5
|
+
phone?: string | null;
|
|
6
|
+
trackingKey?: string | null;
|
|
7
7
|
extraData?: {
|
|
8
8
|
[index: string]: unknown;
|
|
9
9
|
};
|
|
10
10
|
access?: string[];
|
|
11
|
-
privacyPreferences?: PrivacyPreferences;
|
|
11
|
+
privacyPreferences?: PrivacyPreferences | null;
|
|
12
12
|
};
|
|
13
13
|
export declare type State = {
|
|
14
14
|
isLoggedIn: boolean;
|
package/package.json
CHANGED
package/src/actions/userData.ts
CHANGED
|
@@ -7,14 +7,17 @@ import { getPrivacyPreferences } from './preferences';
|
|
|
7
7
|
import store from '../store';
|
|
8
8
|
import { getInfo } from '../clients/nebula';
|
|
9
9
|
import { whenIsLoggedIn, whenLoginStateResolved } from '../utils/loginState';
|
|
10
|
+
import { getCurrentPublicationDomain } from '../utils/url';
|
|
10
11
|
|
|
11
12
|
const getExtraData = () =>
|
|
12
13
|
Promise.all([getBrowserId(), whenLoginStateResolved()]).then(
|
|
13
14
|
([browserId, isLoggedIn]) =>
|
|
14
15
|
getInfo(
|
|
15
|
-
|
|
16
|
+
getCurrentPublicationDomain(),
|
|
16
17
|
browserId,
|
|
17
|
-
isLoggedIn
|
|
18
|
+
isLoggedIn
|
|
19
|
+
? store.get('userAttributes')?.trackingKey || undefined
|
|
20
|
+
: undefined
|
|
18
21
|
)
|
|
19
22
|
);
|
|
20
23
|
|
|
@@ -49,6 +52,12 @@ export const requestAttributes = (attributes: Array<keyof UserAttributes>) => {
|
|
|
49
52
|
service()
|
|
50
53
|
.then((data) => {
|
|
51
54
|
store.merge('userAttributes', data);
|
|
55
|
+
if (data.uuid !== undefined) {
|
|
56
|
+
// We have tried to fetch uuid, so we now know if the user is logged in or not
|
|
57
|
+
store.merge('state', {
|
|
58
|
+
isLoggedIn: data.uuid !== null,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
52
61
|
})
|
|
53
62
|
.catch((error) => {
|
|
54
63
|
log.warn(`User attribute call failed (${service.toString()})`, error);
|
|
@@ -50,7 +50,7 @@ describe('Pluto service', () => {
|
|
|
50
50
|
jest.spyOn(store, 'merge');
|
|
51
51
|
});
|
|
52
52
|
let currentSession;
|
|
53
|
-
function
|
|
53
|
+
function itShouldReturnSessionData() {
|
|
54
54
|
it('should return session data', async () => {
|
|
55
55
|
expect(currentSession).toEqual({
|
|
56
56
|
uuid: userUUID,
|
|
@@ -58,19 +58,13 @@ describe('Pluto service', () => {
|
|
|
58
58
|
trackingKey: userTrackingKey,
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
|
-
it('should merge isLoggedIn:true to state in store', () => {
|
|
62
|
-
expect(store.merge).toHaveBeenCalledWith('state', {
|
|
63
|
-
isLoggedIn: true,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
61
|
}
|
|
67
|
-
function
|
|
62
|
+
function itShouldReturnNoSessionData() {
|
|
68
63
|
it('should return session data', async () => {
|
|
69
|
-
expect(currentSession).toEqual({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
isLoggedIn: false,
|
|
64
|
+
expect(currentSession).toEqual({
|
|
65
|
+
uuid: null,
|
|
66
|
+
name: null,
|
|
67
|
+
trackingKey: null,
|
|
74
68
|
});
|
|
75
69
|
});
|
|
76
70
|
}
|
|
@@ -84,7 +78,7 @@ describe('Pluto service', () => {
|
|
|
84
78
|
it('should call Pluto', () => {
|
|
85
79
|
expect(fetch).toHaveBeenCalledTimes(1);
|
|
86
80
|
});
|
|
87
|
-
|
|
81
|
+
itShouldReturnSessionData();
|
|
88
82
|
});
|
|
89
83
|
describe('When cache is not empty', () => {
|
|
90
84
|
beforeEach(async () => {
|
|
@@ -94,7 +88,7 @@ describe('Pluto service', () => {
|
|
|
94
88
|
it('should not call Pluto', () => {
|
|
95
89
|
expect(fetch).toHaveBeenCalledTimes(0);
|
|
96
90
|
});
|
|
97
|
-
|
|
91
|
+
itShouldReturnSessionData();
|
|
98
92
|
});
|
|
99
93
|
});
|
|
100
94
|
describe('when user is not logged in', () => {
|
|
@@ -112,7 +106,7 @@ describe('Pluto service', () => {
|
|
|
112
106
|
expect(fetch).toHaveBeenCalledTimes(1);
|
|
113
107
|
});
|
|
114
108
|
itShouldNotHaveLoggedAnything();
|
|
115
|
-
|
|
109
|
+
itShouldReturnNoSessionData();
|
|
116
110
|
});
|
|
117
111
|
describe('When cache is not empty', () => {
|
|
118
112
|
beforeEach(async () => {
|
|
@@ -123,7 +117,7 @@ describe('Pluto service', () => {
|
|
|
123
117
|
expect(fetch).toHaveBeenCalledTimes(0);
|
|
124
118
|
});
|
|
125
119
|
itShouldNotHaveLoggedAnything();
|
|
126
|
-
|
|
120
|
+
itShouldReturnNoSessionData();
|
|
127
121
|
});
|
|
128
122
|
describe('when session is invalid for domain', () => {
|
|
129
123
|
beforeEach(async () => {
|
package/src/clients/pluto.ts
CHANGED
|
@@ -14,9 +14,9 @@ const ServiceSessionSchema = Partial({
|
|
|
14
14
|
const mapSessionToUserAttributes = (
|
|
15
15
|
session: Static<typeof ServiceSessionSchema>
|
|
16
16
|
): UserAttributes => ({
|
|
17
|
-
uuid: session.user_uuid,
|
|
18
|
-
name: session.user_name,
|
|
19
|
-
trackingKey: session.tracking_key,
|
|
17
|
+
uuid: session.user_uuid || null,
|
|
18
|
+
name: session.user_name || null,
|
|
19
|
+
trackingKey: session.tracking_key || null,
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
const PlutoErrorSchema = Record({
|
|
@@ -99,12 +99,7 @@ export const getCurrentSession = async (): Promise<UserAttributes> =>
|
|
|
99
99
|
'getCurrentSession',
|
|
100
100
|
ServiceSessionSchema,
|
|
101
101
|
fetchCurrentSession
|
|
102
|
-
).then((currentSession) =>
|
|
103
|
-
store.merge('state', {
|
|
104
|
-
isLoggedIn: currentSession.user_uuid !== undefined,
|
|
105
|
-
});
|
|
106
|
-
return mapSessionToUserAttributes(currentSession);
|
|
107
|
-
});
|
|
102
|
+
).then((currentSession) => mapSessionToUserAttributes(currentSession));
|
|
108
103
|
|
|
109
104
|
export const removeSession = async (domain: string) =>
|
|
110
105
|
fetch(`/api/pluto/v1/sessions/current?publication_domain=${domain}`, {
|
|
@@ -20,6 +20,7 @@ declare global {
|
|
|
20
20
|
[AmediaUserEvents.UPDATE_STORAGE]: CustomEvent<{
|
|
21
21
|
[namespace: string]: object;
|
|
22
22
|
}>;
|
|
23
|
+
// @ts-ignore
|
|
23
24
|
[AmediaUserEvents.ON_ATTRIBUTES_UPDATED]: CustomEvent<UserAttributes>;
|
|
24
25
|
[AmediaUserEvents.ON_STATE_UPDATED]: CustomEvent<State>;
|
|
25
26
|
[AmediaUserEvents.ON_STORAGE_UPDATED]: CustomEvent<{
|
|
@@ -12,11 +12,11 @@ async function verifyAndSetUserAccessCookie() {
|
|
|
12
12
|
const cookieName = 'VSTOKEN';
|
|
13
13
|
const publicationDomain = getCurrentPublicationDomain();
|
|
14
14
|
const cookie = getCookie(cookieName);
|
|
15
|
-
let hasVerifiedVstoken = false;
|
|
16
15
|
|
|
17
16
|
new UserDataRequest()
|
|
18
17
|
.withAttributes(['uuid'])
|
|
19
|
-
.
|
|
18
|
+
.fetch()
|
|
19
|
+
.then(async ({ attributes, state }) => {
|
|
20
20
|
if (state.isLoggedIn === false) {
|
|
21
21
|
if (typeof cookie === 'string') {
|
|
22
22
|
// We don't want logged out users to have lingering VSTOKEN cookies
|
|
@@ -25,17 +25,6 @@ async function verifyAndSetUserAccessCookie() {
|
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
if (
|
|
29
|
-
!attributes.uuid ||
|
|
30
|
-
state.isLoggedIn === undefined ||
|
|
31
|
-
hasVerifiedVstoken
|
|
32
|
-
) {
|
|
33
|
-
// We only want to perform this job once, so we wait until we have all the data we need.
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
hasVerifiedVstoken = true; // Make sure we do this only once!
|
|
38
|
-
|
|
39
28
|
if (typeof cookie !== 'string') {
|
|
40
29
|
// We want to set a VSTOKEN cookie for the user so it's ready upon next page load
|
|
41
30
|
await setUserAccessCookie(publicationDomain);
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export type UserAttributes = {
|
|
2
|
-
uuid?: string;
|
|
3
|
-
name?: string;
|
|
4
|
-
email?: string;
|
|
5
|
-
phone?: string;
|
|
6
|
-
trackingKey?: string;
|
|
2
|
+
uuid?: string | null;
|
|
3
|
+
name?: string | null;
|
|
4
|
+
email?: string | null;
|
|
5
|
+
phone?: string | null;
|
|
6
|
+
trackingKey?: string | null;
|
|
7
7
|
extraData?: { [index: string]: unknown };
|
|
8
8
|
access?: string[];
|
|
9
|
-
privacyPreferences?: PrivacyPreferences;
|
|
9
|
+
privacyPreferences?: PrivacyPreferences | null;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export type State = {
|