@amedia/user 0.14.18 → 0.14.19
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/package.json +2 -3
- package/src/actions/authentication.spec.ts +0 -51
- package/src/actions/authentication.ts +0 -49
- package/src/actions/authorization.spec.ts +0 -377
- package/src/actions/authorization.ts +0 -120
- 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 -264
- package/src/autologin/index.ts +0 -113
- 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 -49
- package/src/cache/index.spec.ts +0 -132
- 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 -178
- package/src/clients/jupiter.ts +0 -119
- package/src/clients/mercury.spec.ts +0 -126
- package/src/clients/mercury.ts +0 -105
- 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 -262
- package/src/clients/pluto.ts +0 -126
- package/src/eventHandlers/activation.ts +0 -40
- package/src/eventHandlers/authentication.ts +0 -34
- package/src/eventHandlers/eventMap.ts +0 -40
- package/src/eventHandlers/navigation.spec.ts +0 -189
- package/src/eventHandlers/navigation.ts +0 -58
- 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/FetchTimeoutError.ts +0 -8
- 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 -46
- package/src/janitor/index.spec.ts +0 -18
- package/src/janitor/index.ts +0 -60
- package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -213
- package/src/janitor/jobs/accessCookieRefresher.ts +0 -96
- 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 -446
- package/src/lib/PaywallUnlockRequest.ts +0 -161
- package/src/lib/UserDataRequest.spec.ts +0 -231
- package/src/lib/UserDataRequest.ts +0 -267
- 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 -66
- package/src/types.ts +0 -22
- package/src/utils/customEventWrapper.spec.ts +0 -237
- package/src/utils/customEventWrapper.ts +0 -77
- 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/getGlobalThis.ts +0 -17
- package/src/utils/getOrUpdate.spec.ts +0 -166
- package/src/utils/getOrUpdate.ts +0 -66
- package/src/utils/localhostCheck.ts +0 -10
- package/src/utils/location.spec.ts +0 -61
- package/src/utils/location.ts +0 -16
- package/src/utils/log.spec.ts +0 -177
- package/src/utils/log.ts +0 -112
- 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 -37
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import accessCookieRefresher from './accessCookieRefresher';
|
|
2
|
-
import * as url from '../../utils/url';
|
|
3
|
-
import UserDataRequest from '../../lib/UserDataRequest';
|
|
4
|
-
import * as cookie from '../../lib/cookie';
|
|
5
|
-
import * as authorization from '../../actions/authorization';
|
|
6
|
-
import store from '../../store';
|
|
7
|
-
import spyOn = jest.spyOn;
|
|
8
|
-
import { AccessFeatures } from '../../clients/jupiter';
|
|
9
|
-
|
|
10
|
-
const mockUuid = '3-1-33-7';
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
spyOn(url, 'getCurrentSiteDomain').mockReturnValue('www.avisnavn.no');
|
|
14
|
-
url.setCurrentHostname('www.avisnavn.no');
|
|
15
|
-
jest
|
|
16
|
-
.spyOn(authorization, 'setUserAccessCookie')
|
|
17
|
-
.mockImplementation(() =>
|
|
18
|
-
Promise.resolve({ success: true, accessFeatures: ['newspaper'] })
|
|
19
|
-
);
|
|
20
|
-
jest
|
|
21
|
-
.spyOn(authorization, 'setNonUserAccessCookie')
|
|
22
|
-
.mockImplementation(() =>
|
|
23
|
-
Promise.resolve({ success: true, accessFeatures: ['newspaper'] })
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
function mockAccessCookie(
|
|
28
|
-
validHours: number,
|
|
29
|
-
uuid: string,
|
|
30
|
-
accessFeatures: AccessFeatures,
|
|
31
|
-
domain: string
|
|
32
|
-
) {
|
|
33
|
-
const validTo = new Date();
|
|
34
|
-
validTo.setHours(validTo.getHours() + validHours);
|
|
35
|
-
return `signature:${Math.round(
|
|
36
|
-
validTo.getTime() / 1000
|
|
37
|
-
)}:${accessFeatures.join(',')}:${uuid}:${domain}:jupiter`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
describe('accessCookieRefresher', () => {
|
|
41
|
-
describe('User is logged in', () => {
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
jest
|
|
44
|
-
.spyOn(UserDataRequest.prototype, 'subscribe')
|
|
45
|
-
.mockImplementation((callback) => {
|
|
46
|
-
callback({
|
|
47
|
-
attributes: {
|
|
48
|
-
uuid: mockUuid,
|
|
49
|
-
},
|
|
50
|
-
state: {
|
|
51
|
-
isLoggedIn: true,
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
store.set('state', { isLoggedIn: true });
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('without any cookies', () => {
|
|
59
|
-
beforeEach(() => {
|
|
60
|
-
jest.spyOn(cookie, 'getCookie').mockReturnValue(null);
|
|
61
|
-
});
|
|
62
|
-
it('Should set user access cookie and non user access cookie', async () => {
|
|
63
|
-
expect(await accessCookieRefresher()).toEqual([undefined, undefined]);
|
|
64
|
-
expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(1);
|
|
65
|
-
expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(1);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('with only user access cookie', () => {
|
|
70
|
-
beforeEach(() => {
|
|
71
|
-
jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
|
|
72
|
-
if (name === 'VSTOKEN') {
|
|
73
|
-
return mockAccessCookie(25, mockUuid, ['newspaper'], 'avisnavn.no');
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
it('Should set user access cookie and non user access cookie', async () => {
|
|
79
|
-
expect(await accessCookieRefresher()).toEqual([undefined, undefined]);
|
|
80
|
-
expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(0);
|
|
81
|
-
expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(1);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('with only non user access cookie', () => {
|
|
86
|
-
beforeEach(() => {
|
|
87
|
-
jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
|
|
88
|
-
if (name === 'VSTOKEN2') {
|
|
89
|
-
return mockAccessCookie(1, mockUuid, ['newspaper'], 'avisnavn.no');
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
it('Should set user access cookie and non user access cookie', async () => {
|
|
95
|
-
expect(await accessCookieRefresher()).toEqual([undefined, undefined]);
|
|
96
|
-
expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(1);
|
|
97
|
-
expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(0);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('with user access cookie set for another domain', () => {
|
|
102
|
-
beforeEach(() => {
|
|
103
|
-
jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
|
|
104
|
-
if (name === 'VSTOKEN') {
|
|
105
|
-
return mockAccessCookie(
|
|
106
|
-
25,
|
|
107
|
-
mockUuid,
|
|
108
|
-
['newspaper'],
|
|
109
|
-
'evildomain.no'
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return null;
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
it('Should set user access cookie and non user access cookie', async () => {
|
|
116
|
-
expect(await accessCookieRefresher()).toEqual([undefined, undefined]);
|
|
117
|
-
expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(1);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('with user access cookie valid for less than 24 hours', () => {
|
|
122
|
-
beforeEach(() => {
|
|
123
|
-
jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
|
|
124
|
-
if (name === 'VSTOKEN') {
|
|
125
|
-
return mockAccessCookie(23, mockUuid, ['newspaper'], 'avisnavn.no');
|
|
126
|
-
}
|
|
127
|
-
return null;
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
it('Should set user access cookie and non user access cookie', async () => {
|
|
131
|
-
expect(await accessCookieRefresher()).toEqual([undefined, undefined]);
|
|
132
|
-
expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(1);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe('with non user access cookie set for another domain', () => {
|
|
137
|
-
beforeEach(() => {
|
|
138
|
-
jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
|
|
139
|
-
if (name === 'VSTOKEN2') {
|
|
140
|
-
return mockAccessCookie(
|
|
141
|
-
25,
|
|
142
|
-
mockUuid,
|
|
143
|
-
['newspaper'],
|
|
144
|
-
'evildomain.no'
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
return null;
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
it('Should set user access cookie and non user access cookie', async () => {
|
|
151
|
-
expect(await accessCookieRefresher()).toEqual([undefined, undefined]);
|
|
152
|
-
expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(1);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('with non user access cookie valid for less than 30 minutes', () => {
|
|
157
|
-
beforeEach(() => {
|
|
158
|
-
jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
|
|
159
|
-
if (name === 'VSTOKEN2') {
|
|
160
|
-
return mockAccessCookie(0, mockUuid, ['newspaper'], 'avisnavn.no');
|
|
161
|
-
}
|
|
162
|
-
return null;
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
it('Should set user access cookie and non user access cookie', async () => {
|
|
166
|
-
expect(await accessCookieRefresher()).toEqual([undefined, undefined]);
|
|
167
|
-
expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(1);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
describe('User is not logged in', () => {
|
|
172
|
-
beforeEach(() => {
|
|
173
|
-
jest
|
|
174
|
-
.spyOn(UserDataRequest.prototype, 'subscribe')
|
|
175
|
-
.mockImplementation((callback) => {
|
|
176
|
-
callback({
|
|
177
|
-
attributes: {},
|
|
178
|
-
state: {
|
|
179
|
-
isLoggedIn: false,
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
store.set('state', { isLoggedIn: false });
|
|
184
|
-
});
|
|
185
|
-
describe('without any cookies', () => {
|
|
186
|
-
beforeEach(() => {
|
|
187
|
-
jest.spyOn(cookie, 'getCookie').mockReturnValue(null);
|
|
188
|
-
});
|
|
189
|
-
it('Should not set any access cookies', async () => {
|
|
190
|
-
expect(await accessCookieRefresher()).toEqual([undefined, undefined]);
|
|
191
|
-
expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(0);
|
|
192
|
-
expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(0);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
describe('User has both access cookies', () => {
|
|
196
|
-
beforeEach(() => {
|
|
197
|
-
jest
|
|
198
|
-
.spyOn(cookie, 'getCookie')
|
|
199
|
-
.mockImplementation(() =>
|
|
200
|
-
mockAccessCookie(25, mockUuid, ['newspaper'], 'avisnavn.no')
|
|
201
|
-
);
|
|
202
|
-
jest.spyOn(cookie, 'removeCookie').mockImplementation();
|
|
203
|
-
});
|
|
204
|
-
it('Should remove user access cookie, but not VSTOKEN2 (keep for Nasjonal avisuke)', async () => {
|
|
205
|
-
expect(await accessCookieRefresher()).toEqual([undefined, undefined]);
|
|
206
|
-
expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(0);
|
|
207
|
-
expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(0);
|
|
208
|
-
expect(cookie.removeCookie).toHaveBeenCalledTimes(1);
|
|
209
|
-
expect(cookie.removeCookie).toHaveBeenNthCalledWith(1, 'VSTOKEN');
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
});
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { getCookie, removeCookie } from '../../lib/cookie';
|
|
2
|
-
import UserDataRequest from '../../lib/UserDataRequest';
|
|
3
|
-
import {
|
|
4
|
-
setNonUserAccessCookie,
|
|
5
|
-
setUserAccessCookie,
|
|
6
|
-
} from '../../actions/authorization';
|
|
7
|
-
import { getCurrentSiteDomain } from '../../utils/url';
|
|
8
|
-
|
|
9
|
-
const validCookieGenerator = 'jupiter';
|
|
10
|
-
|
|
11
|
-
async function verifyAndSetUserAccessCookie() {
|
|
12
|
-
const cookieName = 'VSTOKEN';
|
|
13
|
-
const siteDomain = getCurrentSiteDomain();
|
|
14
|
-
const cookie = getCookie(cookieName);
|
|
15
|
-
|
|
16
|
-
new UserDataRequest()
|
|
17
|
-
.withAttributes(['uuid'])
|
|
18
|
-
.fetch()
|
|
19
|
-
.then(async ({ attributes, state }) => {
|
|
20
|
-
if (state.isLoggedIn === false) {
|
|
21
|
-
if (typeof cookie === 'string') {
|
|
22
|
-
// We don't want logged out users to have lingering VSTOKEN cookies
|
|
23
|
-
removeCookie(cookieName);
|
|
24
|
-
}
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (typeof cookie !== 'string') {
|
|
29
|
-
// We want to set a VSTOKEN cookie for the user so it's ready upon next page load
|
|
30
|
-
await setUserAccessCookie(siteDomain);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/* The format of the cookie is:
|
|
35
|
-
* <0 - signature>:<1 - timestamp when cookie stops being valid>:<2 - access_features>:<3 - user_id>:<4 - second level domain>:<5 - generator name (jupiter)> */
|
|
36
|
-
const cookieParts = cookie.split(':');
|
|
37
|
-
|
|
38
|
-
const validTo = new Date(parseInt(cookieParts[1], 10) * 1000);
|
|
39
|
-
validTo.setDate(
|
|
40
|
-
validTo.getDate() - 1
|
|
41
|
-
); /* Set the time one day back so we can update it if it's only valid for one more day */
|
|
42
|
-
|
|
43
|
-
// Make sure that current cookie is not too old, is created for logged in user for this domain by jupiter
|
|
44
|
-
if (
|
|
45
|
-
validTo.getTime() > Date.now() &&
|
|
46
|
-
cookieParts[3] === attributes.uuid &&
|
|
47
|
-
siteDomain.includes(cookieParts[4]) &&
|
|
48
|
-
cookieParts[5] === validCookieGenerator
|
|
49
|
-
) {
|
|
50
|
-
return; // Cookie is valid for more than 24 hours, keep it as it is
|
|
51
|
-
}
|
|
52
|
-
await setUserAccessCookie(siteDomain);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function verifyAndSetNonUserAccessCookie() {
|
|
57
|
-
const cookieName = 'VSTOKEN2';
|
|
58
|
-
const siteDomain = getCurrentSiteDomain();
|
|
59
|
-
const cookie = getCookie(cookieName);
|
|
60
|
-
|
|
61
|
-
new UserDataRequest()
|
|
62
|
-
.fetch()
|
|
63
|
-
.then(async ({ state: { isLoggedIn } }) => {
|
|
64
|
-
if (isLoggedIn) {
|
|
65
|
-
if (typeof cookie !== 'string') {
|
|
66
|
-
await setNonUserAccessCookie(siteDomain);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
/* The format of the cookie is:
|
|
70
|
-
* <0 - signature>:<1 - timestamp when cookie stops being valid>:<2 - access_features>:<3 - uuid>:<4 - second level domain>:<5 - generator name (jupiter)>
|
|
71
|
-
*/
|
|
72
|
-
const cookieParts = cookie.split(':');
|
|
73
|
-
const validTo = new Date(parseInt(cookieParts[1], 10) * 1000);
|
|
74
|
-
// // Check that token is valid for the next 30 minutes otherwise we need to update it
|
|
75
|
-
validTo.setMinutes(validTo.getMinutes() - 30);
|
|
76
|
-
|
|
77
|
-
// Make sure that current cookie is not too old and is created for this domain by jupiter
|
|
78
|
-
if (
|
|
79
|
-
validTo.getTime() > Date.now() &&
|
|
80
|
-
siteDomain.includes(cookieParts[4]) &&
|
|
81
|
-
cookieParts[5] === validCookieGenerator
|
|
82
|
-
) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
await setNonUserAccessCookie(siteDomain);
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
.then(() => {});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export default function accessCookieRefresher() {
|
|
92
|
-
return Promise.all([
|
|
93
|
-
verifyAndSetUserAccessCookie(),
|
|
94
|
-
verifyAndSetNonUserAccessCookie(),
|
|
95
|
-
]);
|
|
96
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import daxSubCookieHandler from './daxsubCookie';
|
|
2
|
-
import * as cookie from '../../lib/cookie';
|
|
3
|
-
import store from '../../store';
|
|
4
|
-
import { listenForStateRequests } from '../../eventHandlers/state';
|
|
5
|
-
import { listenForUserAttributeRequests } from '../../eventHandlers/userAttributes';
|
|
6
|
-
import UserDataRequest from '../../lib/UserDataRequest';
|
|
7
|
-
import log from '../../utils/log';
|
|
8
|
-
|
|
9
|
-
describe('daxSubCookieHandler', () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
store.clear();
|
|
12
|
-
spyOn(cookie, 'setCookie');
|
|
13
|
-
spyOn(cookie, 'removeCookie');
|
|
14
|
-
|
|
15
|
-
listenForStateRequests();
|
|
16
|
-
listenForUserAttributeRequests();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('when fetching user data fails', () => {
|
|
20
|
-
beforeEach(async () => {
|
|
21
|
-
spyOn(UserDataRequest.prototype, 'fetch').and.returnValue(
|
|
22
|
-
Promise.reject(new Error('Could not fetch'))
|
|
23
|
-
);
|
|
24
|
-
spyOn(log, 'warn');
|
|
25
|
-
await daxSubCookieHandler();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should log error when fetch fails', () => {
|
|
29
|
-
expect(log.warn).toHaveBeenCalledWith(
|
|
30
|
-
`Setting daxsub cookie failed. Error: Could not fetch`,
|
|
31
|
-
new Error('Could not fetch')
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('when user is not logged in', () => {
|
|
37
|
-
beforeEach(async () => {
|
|
38
|
-
store.set('state', { isLoggedIn: false });
|
|
39
|
-
store.set('userAttributes', {
|
|
40
|
-
uuid: null,
|
|
41
|
-
trackingKey: null,
|
|
42
|
-
extraData: {},
|
|
43
|
-
});
|
|
44
|
-
await daxSubCookieHandler();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('Should call removeCookie', () => {
|
|
48
|
-
expect(cookie.removeCookie).toHaveBeenCalled();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should not call setCookie', () => {
|
|
52
|
-
expect(cookie.setCookie).not.toHaveBeenCalled();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('when user is logged in', () => {
|
|
57
|
-
beforeEach(async () => {
|
|
58
|
-
store.set('state', { isLoggedIn: true });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('when has subscription', () => {
|
|
62
|
-
beforeEach(async () => {
|
|
63
|
-
store.set('userAttributes', {
|
|
64
|
-
uuid: 'uuid',
|
|
65
|
-
extraData: {
|
|
66
|
-
customer_keys: 'someString',
|
|
67
|
-
},
|
|
68
|
-
trackingKey: '148d24b2-f28e-4b1c-9958-8abd5066fc59',
|
|
69
|
-
});
|
|
70
|
-
await daxSubCookieHandler();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('Should not call removeCookie', () => {
|
|
74
|
-
expect(cookie.removeCookie).not.toHaveBeenCalled();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('Should set cookie with a_sub_status active', () => {
|
|
78
|
-
expect(cookie.setCookie).toHaveBeenCalledWith(
|
|
79
|
-
'daxsub',
|
|
80
|
-
'a_sub_status%3Dactive%26a_user_key%3D148d24b2-f28e-4b1c-9958-8abd5066fc59',
|
|
81
|
-
1
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('when has no subscription', () => {
|
|
87
|
-
beforeEach(async () => {
|
|
88
|
-
store.set('userAttributes', {
|
|
89
|
-
uuid: 'uuid',
|
|
90
|
-
extraData: {},
|
|
91
|
-
trackingKey: '148d24b2-f28e-4b1c-9958-8abd5066fc59',
|
|
92
|
-
});
|
|
93
|
-
await daxSubCookieHandler();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('Should not call removeCookie', () => {
|
|
97
|
-
expect(cookie.removeCookie).not.toHaveBeenCalled();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('Should set cookie with a_sub_status null', () => {
|
|
101
|
-
expect(cookie.setCookie).toHaveBeenCalledWith(
|
|
102
|
-
'daxsub',
|
|
103
|
-
'a_sub_status%3Dnull%26a_user_key%3D148d24b2-f28e-4b1c-9958-8abd5066fc59',
|
|
104
|
-
1
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { setCookie, removeCookie } from '../../lib/cookie';
|
|
2
|
-
import UserDataRequest from '../../lib/UserDataRequest';
|
|
3
|
-
import log from '../../utils/log';
|
|
4
|
-
import { UserAttributes } from '../../types';
|
|
5
|
-
|
|
6
|
-
export function getCookieValue(attributes: UserAttributes) {
|
|
7
|
-
// If user has the customer_keys field set, assume its a paying subscriber and set subscriptionStatus = active.
|
|
8
|
-
const subscriptionStatus = attributes.extraData?.customer_keys
|
|
9
|
-
? 'active'
|
|
10
|
-
: 'null';
|
|
11
|
-
|
|
12
|
-
const cookieValue = `a_sub_status=${subscriptionStatus}&a_user_key=${attributes.trackingKey}`;
|
|
13
|
-
return cookieValue;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function setDaxsubCookie(attributes: UserAttributes) {
|
|
17
|
-
const name = 'daxsub';
|
|
18
|
-
const cookieValue = getCookieValue(attributes);
|
|
19
|
-
const cookieValueEncoded = encodeURIComponent(cookieValue);
|
|
20
|
-
const validTime = 1; // 1 day (24 hours);
|
|
21
|
-
setCookie(name, cookieValueEncoded, validTime);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default function daxSubCookieHandler() {
|
|
25
|
-
return new UserDataRequest()
|
|
26
|
-
.withAttributes(['trackingKey', 'extraData'])
|
|
27
|
-
.fetch({ timeout: 60000 }) // One minute timeout
|
|
28
|
-
.then(({ attributes, state }) => {
|
|
29
|
-
if (!state.isLoggedIn) {
|
|
30
|
-
removeCookie('daxsub');
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
setDaxsubCookie(attributes);
|
|
34
|
-
})
|
|
35
|
-
.catch((e) => {
|
|
36
|
-
log.warn(`Setting daxsub cookie failed. Error: ${e.message}`, e);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import store from '../../store';
|
|
2
|
-
import { removeUserStorage } from './removeUserStorage';
|
|
3
|
-
import { listenForStateRequests } from '../../eventHandlers/state';
|
|
4
|
-
|
|
5
|
-
describe('removeUserStorage', () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
store.clear();
|
|
8
|
-
spyOn(store, 'set').and.callThrough();
|
|
9
|
-
listenForStateRequests();
|
|
10
|
-
removeUserStorage();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe('when logged in', () => {
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
store.set('state', { isLoggedIn: true });
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should not reset stores', () => {
|
|
19
|
-
expect(store.set).not.toHaveBeenCalledWith('userAttributes', {});
|
|
20
|
-
expect(store.set).not.toHaveBeenCalledWith('storage', {});
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('when not logged in', () => {
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
store.set('state', { isLoggedIn: false });
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should reset stores', () => {
|
|
30
|
-
expect(store.set).toHaveBeenCalledWith('userAttributes', {});
|
|
31
|
-
expect(store.set).toHaveBeenCalledWith('storage', {});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import UserDataRequest from '../../lib/UserDataRequest';
|
|
2
|
-
import store from '../../store';
|
|
3
|
-
|
|
4
|
-
export function removeUserStorage() {
|
|
5
|
-
new UserDataRequest().subscribe(({ state }) => {
|
|
6
|
-
// Need to explicitly check for false here until we have then()
|
|
7
|
-
if (state.isLoggedIn === false) {
|
|
8
|
-
store.set('userAttributes', {});
|
|
9
|
-
store.set('storage', {});
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
}
|