@amedia/user 0.14.9 → 0.14.11
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/README.md +4 -4
- package/dist/user.d.ts +16 -14
- package/package.json +1 -1
- package/src/actions/authentication.spec.ts +1 -1
- package/src/actions/authentication.ts +9 -4
- package/src/actions/authorization.spec.ts +9 -9
- package/src/actions/authorization.ts +11 -11
- package/src/actions/userData.ts +2 -2
- package/src/clients/jupiter.spec.ts +20 -22
- package/src/clients/jupiter.ts +6 -6
- package/src/clients/mercury.spec.ts +5 -2
- package/src/clients/mercury.ts +3 -3
- package/src/clients/nebula.spec.ts +9 -9
- package/src/clients/nebula.ts +4 -4
- package/src/eventHandlers/activation.ts +3 -3
- package/src/index.ts +3 -0
- package/src/janitor/jobs/accessCookieRefresher.spec.ts +1 -1
- package/src/janitor/jobs/accessCookieRefresher.ts +9 -9
- package/src/lib/PaywallUnlockRequest.spec.ts +4 -4
- package/src/lib/PaywallUnlockRequest.ts +6 -6
- package/src/utils/debouncer.ts +1 -1
- package/src/utils/url.spec.ts +3 -3
- package/src/utils/url.ts +1 -1
package/README.md
CHANGED
|
@@ -139,7 +139,7 @@ If you're running a background task and don't mind waiting longer than default (
|
|
|
139
139
|
```
|
|
140
140
|
|
|
141
141
|
## Unlocking the paywall
|
|
142
|
-
Amedia's
|
|
142
|
+
Amedia's sites use a Paywall that's based on a cookie called VSTOKEN that is read by Varnish and used by the content system to decide if the content should be shown to the user or not. If not, the content will load what we call an incentive, a dialogue above the content, that will allow the user to log in and buy subscriptions. The incentive will use a `PaywallUnlockRequest` to see if it can somehow grant access to the user. In some cases it makes sense to create a different user interface for a paywall. In these cases we recommend that you use this `PaywallUnlockRequest` in order to get the same functionality.
|
|
143
143
|
|
|
144
144
|
More information about the paywall can be found here: [How the Paywall works](https://amedia.slite.com/app/channels/hOlqx3Miez/notes/UFqOFRV3g1)
|
|
145
145
|
|
|
@@ -151,7 +151,7 @@ To unlock the paywall, you first need to create a new `PaywallUnlockRequest`. On
|
|
|
151
151
|
to `requestedUrl`. (Provides more flexibility than `reloadOnAccess()`)
|
|
152
152
|
- `withAccessFeatures(accessFeatures: string[])`: Specify what access features will give access to the current content.
|
|
153
153
|
The default is [`newspaper`].
|
|
154
|
-
- `
|
|
154
|
+
- `withSiteDomain(domain: string)`: Specify which site we to attempt activation against. The default is the current domain. This is mostly useful for direktesport.no which often knows what domain the user came from.
|
|
155
155
|
|
|
156
156
|
More details about the access model can be found here: [Access model](https://amedia.slite.com/app/channels/hOlqx3Miez/notes/nhG2Ok39BN)
|
|
157
157
|
|
|
@@ -204,12 +204,12 @@ Note that this *might result in redirects/reloads* if the user is not already lo
|
|
|
204
204
|
The following methods are actions that the user needs to be able to perform in an environment using logged in users.
|
|
205
205
|
|
|
206
206
|
### `goToLoginPage(requestedUrl: string)`
|
|
207
|
-
This action will send the user to the aID login page. It will take care of building the correct URL, including your current
|
|
207
|
+
This action will send the user to the aID login page. It will take care of building the correct URL, including your current site domain, so the login page is skinned correctly.
|
|
208
208
|
|
|
209
209
|
You may include a requestedUrl if you need to control where the user should end up after logging in. The default is to send the user back to the current URL where this action was called.
|
|
210
210
|
|
|
211
211
|
### `logout()`
|
|
212
|
-
This action will log the user out of aID. The logout is global, meaning it will log the session out of all
|
|
212
|
+
This action will log the user out of aID. The logout is global, meaning it will log the session out of all sites and aid.no.
|
|
213
213
|
|
|
214
214
|
## Updating storage
|
|
215
215
|
If you need to store preferences, favourite teams etc for the user, you can choose between two methods. One will update only the attributes of a namespace that you specify, the other will update everything. The main difference is that if you opt for updating everything, attributes that are present on the backend, but not in the update, will be deleted.
|
package/dist/user.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare module '@amedia/user/actions/authentication' {
|
|
2
2
|
import { UserAttributes } from '@amedia/user/types';
|
|
3
|
+
export const loginUrl: (requestedUrl: URL | string) => URL;
|
|
3
4
|
export const login: (requestedUrl: URL | string) => void;
|
|
4
5
|
export const logout: () => Promise<void>;
|
|
5
6
|
export const getSession: () => Promise<UserAttributes>;
|
|
@@ -16,11 +17,11 @@ declare module '@amedia/user/actions/authorization' {
|
|
|
16
17
|
accessFeatures: string[];
|
|
17
18
|
};
|
|
18
19
|
export const getAccess: (accessFeatures?: string[]) => Promise<Pick<UserAttributes, 'access'>>;
|
|
19
|
-
export const activate: (accessFeatures: string[],
|
|
20
|
+
export const activate: (accessFeatures: string[], siteDomain: string) => Promise<string[]>;
|
|
20
21
|
export const hasAccess: (currentAccessFeatures: string[], requestedAccessFeatures: string[]) => boolean;
|
|
21
|
-
export const setUserAccessCookie: (
|
|
22
|
-
export const setNonUserAccessCookie: (
|
|
23
|
-
export const setAccessCookies: (
|
|
22
|
+
export const setUserAccessCookie: (siteDomain: string) => Promise<SetCookieResponse>;
|
|
23
|
+
export const setNonUserAccessCookie: (siteDomain: string) => Promise<SetCookieResponse>;
|
|
24
|
+
export const setAccessCookies: (siteDomain: string) => Promise<SetCookieResponse>;
|
|
24
25
|
export const setHasPerformedPaywallReload: (requestedUrl?: string | undefined) => void;
|
|
25
26
|
export const hasRecentlyPerformedPaywallReload: (requestedUrl?: string | undefined) => boolean;
|
|
26
27
|
export {};
|
|
@@ -222,14 +223,14 @@ declare module '@amedia/user/clients/jupiter' {
|
|
|
222
223
|
access_features: Array<String, false>;
|
|
223
224
|
}, false>;
|
|
224
225
|
export type GetNonUserAccess = Static<typeof GetNonUserAccessSchema>;
|
|
225
|
-
export const checkForAccess: (
|
|
226
|
-
export const getUserAccess: (
|
|
226
|
+
export const checkForAccess: (siteDomain: string, accessFeatures: AccessFeatures) => Promise<Pick<UserAttributes, 'access'>>;
|
|
227
|
+
export const getUserAccess: (siteDomain: string) => Promise<GetVstoken>;
|
|
227
228
|
export const getSitesWithAccessFeatures: ({ accessFeatures, excludeBundles, sortBy, }: {
|
|
228
229
|
accessFeatures: string[];
|
|
229
230
|
excludeBundles?: boolean | undefined;
|
|
230
231
|
sortBy?: "domain" | "veiklasse" | undefined;
|
|
231
232
|
}) => Promise<Sites>;
|
|
232
|
-
export const getNonUserAccess: (
|
|
233
|
+
export const getNonUserAccess: (siteDomain: string) => Promise<GetNonUserAccess>;
|
|
233
234
|
export {};
|
|
234
235
|
|
|
235
236
|
}
|
|
@@ -240,7 +241,7 @@ declare module '@amedia/user/clients/jupiter.spec' {
|
|
|
240
241
|
declare module '@amedia/user/clients/mercury' {
|
|
241
242
|
export class UserDeactivatedError extends Error {
|
|
242
243
|
}
|
|
243
|
-
export const activateSubscription: (accessFeatures: string[],
|
|
244
|
+
export const activateSubscription: (accessFeatures: string[], siteDomain: string) => Promise<string[]>;
|
|
244
245
|
|
|
245
246
|
}
|
|
246
247
|
declare module '@amedia/user/clients/mercury.spec' {
|
|
@@ -264,7 +265,7 @@ declare module '@amedia/user/clients/mercuryLog.spec' {
|
|
|
264
265
|
}
|
|
265
266
|
declare module '@amedia/user/clients/nebula' {
|
|
266
267
|
import { UserAttributes } from '@amedia/user/types';
|
|
267
|
-
export const getInfo: (
|
|
268
|
+
export const getInfo: (siteDomain: string, browserId: string, trackingKey?: string | undefined) => Promise<Pick<UserAttributes, 'extraData'>>;
|
|
268
269
|
|
|
269
270
|
}
|
|
270
271
|
declare module '@amedia/user/clients/nebula.spec' {
|
|
@@ -291,7 +292,7 @@ declare module '@amedia/user/eventHandlers/activation' {
|
|
|
291
292
|
interface WindowEventMap {
|
|
292
293
|
[ActivationEvents.REQUEST_ACTIVATION]: CustomEvent<{
|
|
293
294
|
accessFeatures: string[];
|
|
294
|
-
|
|
295
|
+
siteDomain?: string;
|
|
295
296
|
}>;
|
|
296
297
|
[ActivationEvents.ON_ACTIVATION_COMPLETE]: CustomEvent<{
|
|
297
298
|
accessFeatures: string[];
|
|
@@ -418,6 +419,7 @@ declare module '@amedia/user/index' {
|
|
|
418
419
|
* @param requestedUrl
|
|
419
420
|
*/
|
|
420
421
|
export const goToLoginPage: (requestedUrl?: string | undefined) => void;
|
|
422
|
+
export const getLoginUrl: (requestedUrl?: string | undefined) => URL;
|
|
421
423
|
export const logout: () => Promise<void>;
|
|
422
424
|
export const updateStorage: (storage: {
|
|
423
425
|
[index: string]: Object;
|
|
@@ -487,8 +489,8 @@ declare module '@amedia/user/lib/PaywallUnlockRequest' {
|
|
|
487
489
|
private requestedAccessFeatures;
|
|
488
490
|
private reload;
|
|
489
491
|
private requestedUrl;
|
|
490
|
-
private
|
|
491
|
-
|
|
492
|
+
private siteDomain;
|
|
493
|
+
withSiteDomain(domain: string): this;
|
|
492
494
|
withAccessFeatures(accessFeatures: string[]): this;
|
|
493
495
|
reloadOnAccess(): this;
|
|
494
496
|
redirectOnAccess(requestedUrl: string): this;
|
|
@@ -644,7 +646,7 @@ declare module '@amedia/user/utils/debouncer' {
|
|
|
644
646
|
* resolve my promise', but instead of the fetch being performed right away, we want to wait for more users to
|
|
645
647
|
* request other stuff. This will keep us from performing lots of individual fetches to the backend.
|
|
646
648
|
*
|
|
647
|
-
* Our main use case is a standard
|
|
649
|
+
* Our main use case is a standard site front page where one component on the page requests the euucp namespace
|
|
648
650
|
* from Europa, and then another component requests the privacy_preferences namespace. Instead of the Europa client
|
|
649
651
|
* calling two fetches to the server, one for euucp and another for privacy_preferences, we want the Debouncer to
|
|
650
652
|
* aggregate these calls into one call to the backend, that requests both euucp AND privacy_preferences, so the response
|
|
@@ -762,7 +764,7 @@ declare module '@amedia/user/utils/url' {
|
|
|
762
764
|
export const getCurrentHostname: () => string;
|
|
763
765
|
export const getCurrentUrl: () => string;
|
|
764
766
|
export const getCurrentEnvironment: () => string | null;
|
|
765
|
-
export const
|
|
767
|
+
export const getCurrentSiteDomain: () => string;
|
|
766
768
|
export const getAidDomain: () => string;
|
|
767
769
|
|
|
768
770
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { login } from './authentication';
|
|
|
4
4
|
|
|
5
5
|
beforeEach(() => {
|
|
6
6
|
spyOn(url, 'getCurrentUrl').and.returnValue('https://www.telen.no/artikkel/');
|
|
7
|
-
spyOn(url, '
|
|
7
|
+
spyOn(url, 'getCurrentSiteDomain').and.returnValue('www.telen.no');
|
|
8
8
|
spyOn(location, 'navigateTo');
|
|
9
9
|
});
|
|
10
10
|
|
|
@@ -2,19 +2,24 @@ import { getCurrentSession, removeSession } from '../clients/pluto';
|
|
|
2
2
|
import cache from '../cache';
|
|
3
3
|
import { getRPCClient } from '../lib/rpc';
|
|
4
4
|
import { removeCookie } from '../lib/cookie';
|
|
5
|
-
import { getAidDomain,
|
|
5
|
+
import { getAidDomain, getCurrentSiteDomain } from '../utils/url';
|
|
6
6
|
import log from '../utils/log';
|
|
7
7
|
import { UserAttributes } from '../types';
|
|
8
8
|
import { navigateTo } from '../utils/location';
|
|
9
9
|
|
|
10
|
-
export const
|
|
10
|
+
export const loginUrl = (requestedUrl: URL | string) => {
|
|
11
11
|
const url = new URL(
|
|
12
|
-
`https://${getAidDomain()}/aid/logg_inn/${
|
|
12
|
+
`https://${getAidDomain()}/aid/logg_inn/${getCurrentSiteDomain()}/`
|
|
13
13
|
);
|
|
14
14
|
url.searchParams.set(
|
|
15
15
|
'requestedUrl',
|
|
16
16
|
requestedUrl instanceof URL ? requestedUrl.href : requestedUrl
|
|
17
17
|
);
|
|
18
|
+
return url;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const login = (requestedUrl: URL | string) => {
|
|
22
|
+
const url = loginUrl(requestedUrl);
|
|
18
23
|
navigateTo(url.href);
|
|
19
24
|
};
|
|
20
25
|
|
|
@@ -29,7 +34,7 @@ function clearCookies() {
|
|
|
29
34
|
|
|
30
35
|
export const logout = async () =>
|
|
31
36
|
// TODO: It now clears the entire cache. Might be too aggressive.
|
|
32
|
-
Promise.all([removeSession(
|
|
37
|
+
Promise.all([removeSession(getCurrentSiteDomain()), cache.clear()])
|
|
33
38
|
.then(() => {
|
|
34
39
|
// TODO This should be separated from logout and instead be setup to listen on state changes on storage
|
|
35
40
|
getRPCClient().userAuthenticated(false);
|
|
@@ -20,7 +20,7 @@ import * as authentication from './authentication';
|
|
|
20
20
|
import { removeAllCookies } from '../lib/cookie';
|
|
21
21
|
import { AccessFeatures } from '../clients/jupiter';
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const siteDomain = 'www.avisnavn.no';
|
|
24
24
|
|
|
25
25
|
beforeEach(() => {
|
|
26
26
|
removeAllCookies();
|
|
@@ -213,7 +213,7 @@ describe('setUserAccessCookie', () => {
|
|
|
213
213
|
describe('when getUserAccess is successful', () => {
|
|
214
214
|
getUserAccessSucceeds(['newspaper', 'plussalt']);
|
|
215
215
|
beforeEach(async () => {
|
|
216
|
-
cookieResponse = await setUserAccessCookie(
|
|
216
|
+
cookieResponse = await setUserAccessCookie(siteDomain);
|
|
217
217
|
});
|
|
218
218
|
itReturnsCookieResponse(true, ['newspaper', 'plussalt']);
|
|
219
219
|
itSetsVstokenCookie();
|
|
@@ -222,7 +222,7 @@ describe('setUserAccessCookie', () => {
|
|
|
222
222
|
describe('when getUserAccess is not successful', () => {
|
|
223
223
|
getUserAccessFails(['newspaper', 'plussalt']);
|
|
224
224
|
beforeEach(async () => {
|
|
225
|
-
cookieResponse = await setUserAccessCookie(
|
|
225
|
+
cookieResponse = await setUserAccessCookie(siteDomain);
|
|
226
226
|
});
|
|
227
227
|
itReturnsCookieResponse(false, ['newspaper', 'plussalt']);
|
|
228
228
|
itSetsNoCookies();
|
|
@@ -233,7 +233,7 @@ describe('setNonUserAccessCookie', () => {
|
|
|
233
233
|
describe('when getNonUserAccess is successful', () => {
|
|
234
234
|
getNonUserAccessSucceeds(['newspaper', 'plussalt']);
|
|
235
235
|
beforeEach(async () => {
|
|
236
|
-
cookieResponse = await setNonUserAccessCookie(
|
|
236
|
+
cookieResponse = await setNonUserAccessCookie(siteDomain);
|
|
237
237
|
});
|
|
238
238
|
itReturnsCookieResponse(true, ['newspaper', 'plussalt']);
|
|
239
239
|
itSetsVstoken2Cookie();
|
|
@@ -242,7 +242,7 @@ describe('setNonUserAccessCookie', () => {
|
|
|
242
242
|
describe('when getNonUserAccess is not successful', () => {
|
|
243
243
|
getNonUserAccessFails(['newspaper', 'plussalt']);
|
|
244
244
|
beforeEach(async () => {
|
|
245
|
-
cookieResponse = await setNonUserAccessCookie(
|
|
245
|
+
cookieResponse = await setNonUserAccessCookie(siteDomain);
|
|
246
246
|
});
|
|
247
247
|
itReturnsCookieResponse(false, ['newspaper', 'plussalt']);
|
|
248
248
|
itSetsNoCookies();
|
|
@@ -254,7 +254,7 @@ describe('setAccessCookies', () => {
|
|
|
254
254
|
getUserAccessSucceeds(['newspaper', 'plussalt']);
|
|
255
255
|
getNonUserAccessSucceeds(['sport', 'pluss', 'newspaper']);
|
|
256
256
|
beforeEach(async () => {
|
|
257
|
-
cookieResponse = await setAccessCookies(
|
|
257
|
+
cookieResponse = await setAccessCookies(siteDomain);
|
|
258
258
|
});
|
|
259
259
|
itReturnsCookieResponse(true, ['newspaper', 'pluss', 'plussalt', 'sport']);
|
|
260
260
|
itSetsVstokenCookie();
|
|
@@ -265,7 +265,7 @@ describe('setAccessCookies', () => {
|
|
|
265
265
|
getUserAccessFails(['newspaper']);
|
|
266
266
|
getNonUserAccessSucceeds(['sport', 'pluss', 'newspaper']);
|
|
267
267
|
beforeEach(async () => {
|
|
268
|
-
cookieResponse = await setAccessCookies(
|
|
268
|
+
cookieResponse = await setAccessCookies(siteDomain);
|
|
269
269
|
});
|
|
270
270
|
itReturnsCookieResponse(false, ['newspaper', 'pluss', 'sport']);
|
|
271
271
|
itDoesNotSetVstokenCookie();
|
|
@@ -276,7 +276,7 @@ describe('setAccessCookies', () => {
|
|
|
276
276
|
getUserAccessSucceeds(['newspaper', 'plussalt']);
|
|
277
277
|
getNonUserAccessFails(['newspaper']);
|
|
278
278
|
beforeEach(async () => {
|
|
279
|
-
cookieResponse = await setAccessCookies(
|
|
279
|
+
cookieResponse = await setAccessCookies(siteDomain);
|
|
280
280
|
});
|
|
281
281
|
itReturnsCookieResponse(false, ['newspaper', 'plussalt']);
|
|
282
282
|
itSetsVstokenCookie();
|
|
@@ -287,7 +287,7 @@ describe('setAccessCookies', () => {
|
|
|
287
287
|
getUserAccessFails(['newspaper', 'plussalt']);
|
|
288
288
|
getNonUserAccessFails(['newspaper']);
|
|
289
289
|
beforeEach(async () => {
|
|
290
|
-
cookieResponse = await setAccessCookies(
|
|
290
|
+
cookieResponse = await setAccessCookies(siteDomain);
|
|
291
291
|
});
|
|
292
292
|
itReturnsCookieResponse(false, ['newspaper', 'plussalt']);
|
|
293
293
|
itSetsNoCookies();
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
getNonUserAccess,
|
|
4
4
|
getUserAccess,
|
|
5
5
|
} from '../clients/jupiter';
|
|
6
|
-
import {
|
|
6
|
+
import { getCurrentSiteDomain, getCurrentUrl } from '../utils/url';
|
|
7
7
|
import { UserAttributes } from '../types';
|
|
8
8
|
import { activateSubscription, UserDeactivatedError } from '../clients/mercury';
|
|
9
9
|
import { logout } from './authentication';
|
|
@@ -14,14 +14,14 @@ type SetCookieResponse = { success: boolean; accessFeatures: string[] };
|
|
|
14
14
|
export const getAccess = (
|
|
15
15
|
accessFeatures: string[] = ['newspaper']
|
|
16
16
|
): Promise<Pick<UserAttributes, 'access'>> =>
|
|
17
|
-
checkForAccess(
|
|
17
|
+
checkForAccess(getCurrentSiteDomain(), accessFeatures);
|
|
18
18
|
|
|
19
19
|
export const activate = async (
|
|
20
20
|
accessFeatures: string[],
|
|
21
|
-
|
|
21
|
+
siteDomain: string
|
|
22
22
|
): Promise<string[]> => {
|
|
23
23
|
try {
|
|
24
|
-
return await activateSubscription(accessFeatures,
|
|
24
|
+
return await activateSubscription(accessFeatures, siteDomain);
|
|
25
25
|
} catch (error) {
|
|
26
26
|
if (error instanceof UserDeactivatedError) {
|
|
27
27
|
await logout();
|
|
@@ -41,9 +41,9 @@ export const hasAccess = (
|
|
|
41
41
|
).length > 0;
|
|
42
42
|
|
|
43
43
|
export const setUserAccessCookie = async (
|
|
44
|
-
|
|
44
|
+
siteDomain: string
|
|
45
45
|
): Promise<SetCookieResponse> => {
|
|
46
|
-
const vstoken = await getUserAccess(
|
|
46
|
+
const vstoken = await getUserAccess(siteDomain);
|
|
47
47
|
if (vstoken.status === 'success') {
|
|
48
48
|
/**
|
|
49
49
|
* The VSTOKEN cookie will live for 365 days, but a timestamp in the payload will ensure that it cannot
|
|
@@ -59,9 +59,9 @@ export const setUserAccessCookie = async (
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
export const setNonUserAccessCookie = async (
|
|
62
|
-
|
|
62
|
+
siteDomain: string
|
|
63
63
|
): Promise<SetCookieResponse> => {
|
|
64
|
-
const vstoken2 = await getNonUserAccess(
|
|
64
|
+
const vstoken2 = await getNonUserAccess(siteDomain);
|
|
65
65
|
if (vstoken2.status === 'success') {
|
|
66
66
|
setCookie('VSTOKEN2', vstoken2.vstoken_cookie, 1, '/');
|
|
67
67
|
}
|
|
@@ -72,16 +72,16 @@ export const setNonUserAccessCookie = async (
|
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
export const setAccessCookies = async (
|
|
75
|
-
|
|
75
|
+
siteDomain: string
|
|
76
76
|
): Promise<SetCookieResponse> => {
|
|
77
77
|
const setters: Array<Promise<SetCookieResponse>> = [];
|
|
78
78
|
setters.push(
|
|
79
|
-
setUserAccessCookie(
|
|
79
|
+
setUserAccessCookie(siteDomain).catch(() =>
|
|
80
80
|
Promise.resolve({ success: false, accessFeatures: [] })
|
|
81
81
|
)
|
|
82
82
|
);
|
|
83
83
|
setters.push(
|
|
84
|
-
setNonUserAccessCookie(
|
|
84
|
+
setNonUserAccessCookie(siteDomain).catch(() =>
|
|
85
85
|
Promise.resolve({ success: false, accessFeatures: [] })
|
|
86
86
|
)
|
|
87
87
|
);
|
package/src/actions/userData.ts
CHANGED
|
@@ -7,13 +7,13 @@ 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 {
|
|
10
|
+
import { getCurrentSiteDomain } from '../utils/url';
|
|
11
11
|
|
|
12
12
|
const getExtraData = () =>
|
|
13
13
|
Promise.all([getBrowserId(), whenLoginStateResolved()]).then(
|
|
14
14
|
([browserId, isLoggedIn]) =>
|
|
15
15
|
getInfo(
|
|
16
|
-
|
|
16
|
+
getCurrentSiteDomain(),
|
|
17
17
|
browserId,
|
|
18
18
|
isLoggedIn
|
|
19
19
|
? store.get('userAttributes')?.trackingKey || undefined
|
|
@@ -21,7 +21,7 @@ beforeEach(async () => {
|
|
|
21
21
|
|
|
22
22
|
describe('jupiter service', () => {
|
|
23
23
|
describe('GET /check_access_for_paper', () => {
|
|
24
|
-
const
|
|
24
|
+
const siteDomain = 'www.rb.no';
|
|
25
25
|
const accessFeatures: AccessFeatures = ['newspaper'];
|
|
26
26
|
|
|
27
27
|
it('should check access for paper', async () => {
|
|
@@ -37,14 +37,14 @@ describe('jupiter service', () => {
|
|
|
37
37
|
|
|
38
38
|
fetch.mockResponseOnce(JSON.stringify(response));
|
|
39
39
|
|
|
40
|
-
await expect(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
await expect(checkForAccess(siteDomain, accessFeatures)).resolves.toEqual(
|
|
41
|
+
{
|
|
42
|
+
access: ['amedia_staff', 'newspaper'],
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
45
|
|
|
46
46
|
expect(fetch).toHaveBeenCalledWith(
|
|
47
|
-
`/api/jupiter/v1/check_access_for_paper/${
|
|
47
|
+
`/api/jupiter/v1/check_access_for_paper/${siteDomain}/?require=any&access_features=${accessFeatures.join(
|
|
48
48
|
','
|
|
49
49
|
)}`
|
|
50
50
|
);
|
|
@@ -56,7 +56,7 @@ describe('jupiter service', () => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
await expect(
|
|
59
|
-
checkForAccess(
|
|
59
|
+
checkForAccess(siteDomain, accessFeatures)
|
|
60
60
|
).rejects.toBeUndefined();
|
|
61
61
|
});
|
|
62
62
|
|
|
@@ -65,7 +65,7 @@ describe('jupiter service', () => {
|
|
|
65
65
|
log.error = jest.fn();
|
|
66
66
|
|
|
67
67
|
await expect(
|
|
68
|
-
checkForAccess(
|
|
68
|
+
checkForAccess(siteDomain, accessFeatures)
|
|
69
69
|
).rejects.toBeUndefined();
|
|
70
70
|
});
|
|
71
71
|
|
|
@@ -82,7 +82,7 @@ describe('jupiter service', () => {
|
|
|
82
82
|
})
|
|
83
83
|
);
|
|
84
84
|
const cacheSetSpy = spyOn(cache, 'set');
|
|
85
|
-
expect(checkForAccess(
|
|
85
|
+
expect(checkForAccess(siteDomain, accessFeatures))
|
|
86
86
|
.resolves.toEqual({ access: [] })
|
|
87
87
|
.then(() => {
|
|
88
88
|
expect(cacheSetSpy).toHaveBeenCalledWith(
|
|
@@ -96,7 +96,7 @@ describe('jupiter service', () => {
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
describe('POST /get_vstoken', () => {
|
|
99
|
-
const
|
|
99
|
+
const siteDomain = 'www.rb.no';
|
|
100
100
|
|
|
101
101
|
it('should return vstoken', async () => {
|
|
102
102
|
const response: GetVstoken = {
|
|
@@ -107,10 +107,10 @@ describe('jupiter service', () => {
|
|
|
107
107
|
|
|
108
108
|
fetch.mockResponseOnce(JSON.stringify(response));
|
|
109
109
|
|
|
110
|
-
await expect(getUserAccess(
|
|
110
|
+
await expect(getUserAccess(siteDomain)).resolves.toEqual(response);
|
|
111
111
|
|
|
112
112
|
expect(fetch).toHaveBeenCalledWith(
|
|
113
|
-
`/api/jupiter/v1/get_vstoken/${
|
|
113
|
+
`/api/jupiter/v1/get_vstoken/${siteDomain}`,
|
|
114
114
|
{
|
|
115
115
|
method: 'post',
|
|
116
116
|
}
|
|
@@ -122,7 +122,7 @@ describe('jupiter service', () => {
|
|
|
122
122
|
status: 400,
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
await expect(getUserAccess(
|
|
125
|
+
await expect(getUserAccess(siteDomain)).rejects.toThrow(
|
|
126
126
|
'Request not ok (400: Bad Request).'
|
|
127
127
|
);
|
|
128
128
|
});
|
|
@@ -131,14 +131,14 @@ describe('jupiter service', () => {
|
|
|
131
131
|
fetch.mockResponseOnce(JSON.stringify({ access_features: 'foo' }));
|
|
132
132
|
log.error = jest.fn();
|
|
133
133
|
|
|
134
|
-
await expect(getUserAccess(
|
|
134
|
+
await expect(getUserAccess(siteDomain)).rejects.toThrow(
|
|
135
135
|
'Expected { status: "success"; cookie: string; access_features: string[]; }, but was incompatible'
|
|
136
136
|
);
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
describe('POST /non_user_access', () => {
|
|
141
|
-
const
|
|
141
|
+
const siteDomain = 'www.rb.no';
|
|
142
142
|
|
|
143
143
|
it('should return none user access', async () => {
|
|
144
144
|
const response: GetNonUserAccess = {
|
|
@@ -150,12 +150,10 @@ describe('jupiter service', () => {
|
|
|
150
150
|
|
|
151
151
|
fetch.mockResponseOnce(JSON.stringify(response));
|
|
152
152
|
|
|
153
|
-
await expect(getNonUserAccess(
|
|
154
|
-
response
|
|
155
|
-
);
|
|
153
|
+
await expect(getNonUserAccess(siteDomain)).resolves.toEqual(response);
|
|
156
154
|
|
|
157
155
|
expect(fetch).toHaveBeenCalledWith(
|
|
158
|
-
`/api/jupiter/v1/non_user_access/${
|
|
156
|
+
`/api/jupiter/v1/non_user_access/${siteDomain}`,
|
|
159
157
|
{ method: 'post' }
|
|
160
158
|
);
|
|
161
159
|
});
|
|
@@ -165,7 +163,7 @@ describe('jupiter service', () => {
|
|
|
165
163
|
status: 400,
|
|
166
164
|
});
|
|
167
165
|
|
|
168
|
-
await expect(getNonUserAccess(
|
|
166
|
+
await expect(getNonUserAccess(siteDomain)).rejects.toThrow(
|
|
169
167
|
'Request not ok (400: Bad Request).'
|
|
170
168
|
);
|
|
171
169
|
});
|
|
@@ -174,7 +172,7 @@ describe('jupiter service', () => {
|
|
|
174
172
|
fetch.mockResponseOnce(JSON.stringify({ vstoken_cookie: 3 }));
|
|
175
173
|
log.error = jest.fn();
|
|
176
174
|
|
|
177
|
-
await expect(getNonUserAccess(
|
|
175
|
+
await expect(getNonUserAccess(siteDomain)).rejects.toThrow(
|
|
178
176
|
'Expected { status: "success"; vstoken_cookie: string; uuid: string; access_features: string[]; }, but was incompatible'
|
|
179
177
|
);
|
|
180
178
|
});
|
package/src/clients/jupiter.ts
CHANGED
|
@@ -57,12 +57,12 @@ const GetNonUserAccessSchema = Record({
|
|
|
57
57
|
export type GetNonUserAccess = Static<typeof GetNonUserAccessSchema>;
|
|
58
58
|
|
|
59
59
|
export const checkForAccess = (
|
|
60
|
-
|
|
60
|
+
siteDomain: string,
|
|
61
61
|
accessFeatures: AccessFeatures
|
|
62
62
|
): Promise<Pick<UserAttributes, 'access'>> =>
|
|
63
63
|
getOrUpdate('checkForAccess', CheckAccessForPaperSchema, () =>
|
|
64
64
|
fetch(
|
|
65
|
-
`/api/jupiter/v1/check_access_for_paper/${
|
|
65
|
+
`/api/jupiter/v1/check_access_for_paper/${siteDomain}/?require=any&access_features=${accessFeatures.join(
|
|
66
66
|
','
|
|
67
67
|
)}`
|
|
68
68
|
)
|
|
@@ -89,8 +89,8 @@ export const checkForAccess = (
|
|
|
89
89
|
})
|
|
90
90
|
).then((data) => ({ access: data.access_features }));
|
|
91
91
|
|
|
92
|
-
export const getUserAccess = (
|
|
93
|
-
fetch(`/api/jupiter/v1/get_vstoken/${
|
|
92
|
+
export const getUserAccess = (siteDomain: string): Promise<GetVstoken> =>
|
|
93
|
+
fetch(`/api/jupiter/v1/get_vstoken/${siteDomain}`, { method: 'post' })
|
|
94
94
|
.then((response) => {
|
|
95
95
|
if (!response.ok) {
|
|
96
96
|
throw new Error(
|
|
@@ -145,9 +145,9 @@ export const getSitesWithAccessFeatures = ({
|
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
export const getNonUserAccess = (
|
|
148
|
-
|
|
148
|
+
siteDomain: string
|
|
149
149
|
): Promise<GetNonUserAccess> =>
|
|
150
|
-
fetch(`/api/jupiter/v1/non_user_access/${
|
|
150
|
+
fetch(`/api/jupiter/v1/non_user_access/${siteDomain}`, {
|
|
151
151
|
method: 'post',
|
|
152
152
|
})
|
|
153
153
|
.then((response) => {
|
|
@@ -23,10 +23,13 @@ describe('activateSubscription()', () => {
|
|
|
23
23
|
it('should return list if access features even if requested access is not "granted"', async () => {
|
|
24
24
|
fetch.mockResponse(
|
|
25
25
|
JSON.stringify({
|
|
26
|
-
status: '
|
|
26
|
+
status: 'subscription_not_found',
|
|
27
27
|
access: 'denied',
|
|
28
28
|
access_features: ['newspaper'],
|
|
29
|
-
})
|
|
29
|
+
}),
|
|
30
|
+
{
|
|
31
|
+
status: 400,
|
|
32
|
+
}
|
|
30
33
|
);
|
|
31
34
|
await expect(
|
|
32
35
|
activateSubscription(['newspaper'], 'www.telen.no')
|
package/src/clients/mercury.ts
CHANGED
|
@@ -10,10 +10,10 @@ const EXPECTED_ERRORS = [
|
|
|
10
10
|
|
|
11
11
|
export const activateSubscription = async (
|
|
12
12
|
accessFeatures: string[],
|
|
13
|
-
|
|
13
|
+
siteDomain: string
|
|
14
14
|
): Promise<string[]> =>
|
|
15
15
|
fetch(
|
|
16
|
-
`/api/mercury/v2/access/activate?publication_wwwdomain=${
|
|
16
|
+
`/api/mercury/v2/access/activate?publication_wwwdomain=${siteDomain}&access_features=${accessFeatures.join(
|
|
17
17
|
','
|
|
18
18
|
)}`,
|
|
19
19
|
{
|
|
@@ -36,7 +36,7 @@ export const activateSubscription = async (
|
|
|
36
36
|
throw new UserDeactivatedError();
|
|
37
37
|
}
|
|
38
38
|
if (EXPECTED_ERRORS.includes(data?.status)) {
|
|
39
|
-
return [];
|
|
39
|
+
return data?.access_features || [];
|
|
40
40
|
}
|
|
41
41
|
log.error(
|
|
42
42
|
`Activate subscription failed. Mercury (HTTP/${response.status}: ${body})`,
|
|
@@ -10,7 +10,7 @@ describe('nebula service', () => {
|
|
|
10
10
|
|
|
11
11
|
describe('GET /info', () => {
|
|
12
12
|
const userKey = '9ea9680f-c810-4693-a981-ca8e732a8a8f';
|
|
13
|
-
const
|
|
13
|
+
const siteDomain = 'www.rb.no';
|
|
14
14
|
const browserId = 'fc0bce06-560b-48e4-92f2-840e67178516';
|
|
15
15
|
|
|
16
16
|
it('should return user information', async () => {
|
|
@@ -35,12 +35,12 @@ describe('nebula service', () => {
|
|
|
35
35
|
|
|
36
36
|
fetch.mockResponseOnce(JSON.stringify(response));
|
|
37
37
|
|
|
38
|
-
await expect(
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
await expect(getInfo(siteDomain, browserId, userKey)).resolves.toEqual({
|
|
39
|
+
extraData: response,
|
|
40
|
+
});
|
|
41
41
|
|
|
42
42
|
expect(fetch).toHaveBeenCalledWith(
|
|
43
|
-
`https://services.gcloud.api.no/api/nebula/v1/info?domain=${
|
|
43
|
+
`https://services.gcloud.api.no/api/nebula/v1/info?domain=${siteDomain}&browser_id=${browserId}&user_key=${userKey}`
|
|
44
44
|
);
|
|
45
45
|
});
|
|
46
46
|
|
|
@@ -49,7 +49,7 @@ describe('nebula service', () => {
|
|
|
49
49
|
log.error = jest.fn();
|
|
50
50
|
|
|
51
51
|
await expect(
|
|
52
|
-
getInfo(userKey,
|
|
52
|
+
getInfo(userKey, siteDomain, browserId)
|
|
53
53
|
).rejects.toBeUndefined();
|
|
54
54
|
});
|
|
55
55
|
|
|
@@ -62,9 +62,9 @@ describe('nebula service', () => {
|
|
|
62
62
|
|
|
63
63
|
fetch.mockResponseOnce(JSON.stringify(response));
|
|
64
64
|
|
|
65
|
-
await expect(
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
await expect(getInfo(userKey, siteDomain, browserId)).resolves.toEqual({
|
|
66
|
+
extraData: response,
|
|
67
|
+
});
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
});
|
package/src/clients/nebula.ts
CHANGED
|
@@ -35,12 +35,12 @@ const InfoSchema = Dictionary(Unknown, String).And(
|
|
|
35
35
|
);
|
|
36
36
|
|
|
37
37
|
const getNebulaData = (
|
|
38
|
-
|
|
38
|
+
siteDomain: string,
|
|
39
39
|
browserId: string,
|
|
40
40
|
trackingKey?: string
|
|
41
41
|
) => {
|
|
42
42
|
const url = new URL('https://services.gcloud.api.no/api/nebula/v1/info');
|
|
43
|
-
url.searchParams.set('domain',
|
|
43
|
+
url.searchParams.set('domain', siteDomain);
|
|
44
44
|
url.searchParams.set('browser_id', browserId);
|
|
45
45
|
if (trackingKey) {
|
|
46
46
|
/**
|
|
@@ -74,10 +74,10 @@ const mapNebulaToUserData = (
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
export const getInfo = (
|
|
77
|
-
|
|
77
|
+
siteDomain: string,
|
|
78
78
|
browserId: string,
|
|
79
79
|
trackingKey?: string
|
|
80
80
|
): Promise<Pick<UserAttributes, 'extraData'>> =>
|
|
81
81
|
getOrUpdate('getNebulaInfo', InfoSchema, () =>
|
|
82
|
-
getNebulaData(
|
|
82
|
+
getNebulaData(siteDomain, browserId, trackingKey)
|
|
83
83
|
).then(mapNebulaToUserData);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { dispatch, listenWithExclusivity } from '../utils/customEventWrapper';
|
|
2
2
|
import { activate } from '../actions/authorization';
|
|
3
3
|
import getGlobalThis from '../utils/getGlobalThis';
|
|
4
|
-
import {
|
|
4
|
+
import { getCurrentSiteDomain } from '../utils/url';
|
|
5
5
|
|
|
6
6
|
export enum ActivationEvents {
|
|
7
7
|
REQUEST_ACTIVATION = 'amedia-user.activation.request-activation',
|
|
@@ -12,7 +12,7 @@ declare global {
|
|
|
12
12
|
interface WindowEventMap {
|
|
13
13
|
[ActivationEvents.REQUEST_ACTIVATION]: CustomEvent<{
|
|
14
14
|
accessFeatures: string[];
|
|
15
|
-
|
|
15
|
+
siteDomain?: string;
|
|
16
16
|
}>;
|
|
17
17
|
[ActivationEvents.ON_ACTIVATION_COMPLETE]: CustomEvent<{
|
|
18
18
|
accessFeatures: string[];
|
|
@@ -24,7 +24,7 @@ export const listenForActivationRequests = () => {
|
|
|
24
24
|
listenWithExclusivity(ActivationEvents.REQUEST_ACTIVATION, (evt) => {
|
|
25
25
|
activate(
|
|
26
26
|
evt.detail.accessFeatures,
|
|
27
|
-
evt.detail.
|
|
27
|
+
evt.detail.siteDomain || getCurrentSiteDomain()
|
|
28
28
|
).then((accessFeatures) => {
|
|
29
29
|
dispatch(
|
|
30
30
|
new CustomEvent(ActivationEvents.ON_ACTIVATION_COMPLETE, {
|
package/src/index.ts
CHANGED
|
@@ -21,6 +21,9 @@ export { default as PaywallError } from './exceptions/PaywallError';
|
|
|
21
21
|
export const goToLoginPage = (requestedUrl?: string) =>
|
|
22
22
|
authentication.login(requestedUrl || getCurrentUrl());
|
|
23
23
|
|
|
24
|
+
export const getLoginUrl = (requestedUrl?: string) =>
|
|
25
|
+
authentication.loginUrl(requestedUrl || getCurrentUrl());
|
|
26
|
+
|
|
24
27
|
export const logout = () => authentication.logout();
|
|
25
28
|
|
|
26
29
|
export const updateStorage = (storage: { [index: string]: Object }) => {
|
|
@@ -10,7 +10,7 @@ import { AccessFeatures } from '../../clients/jupiter';
|
|
|
10
10
|
const mockUuid = '3-1-33-7';
|
|
11
11
|
|
|
12
12
|
beforeEach(() => {
|
|
13
|
-
spyOn(url, '
|
|
13
|
+
spyOn(url, 'getCurrentSiteDomain').mockReturnValue('www.avisnavn.no');
|
|
14
14
|
url.setCurrentHostname('www.avisnavn.no');
|
|
15
15
|
jest
|
|
16
16
|
.spyOn(authorization, 'setUserAccessCookie')
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
setNonUserAccessCookie,
|
|
5
5
|
setUserAccessCookie,
|
|
6
6
|
} from '../../actions/authorization';
|
|
7
|
-
import {
|
|
7
|
+
import { getCurrentSiteDomain } from '../../utils/url';
|
|
8
8
|
|
|
9
9
|
const validCookieGenerator = 'jupiter';
|
|
10
10
|
|
|
11
11
|
async function verifyAndSetUserAccessCookie() {
|
|
12
12
|
const cookieName = 'VSTOKEN';
|
|
13
|
-
const
|
|
13
|
+
const siteDomain = getCurrentSiteDomain();
|
|
14
14
|
const cookie = getCookie(cookieName);
|
|
15
15
|
|
|
16
16
|
new UserDataRequest()
|
|
@@ -27,7 +27,7 @@ async function verifyAndSetUserAccessCookie() {
|
|
|
27
27
|
|
|
28
28
|
if (typeof cookie !== 'string') {
|
|
29
29
|
// We want to set a VSTOKEN cookie for the user so it's ready upon next page load
|
|
30
|
-
await setUserAccessCookie(
|
|
30
|
+
await setUserAccessCookie(siteDomain);
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -44,18 +44,18 @@ async function verifyAndSetUserAccessCookie() {
|
|
|
44
44
|
if (
|
|
45
45
|
validTo.getTime() > Date.now() &&
|
|
46
46
|
cookieParts[3] === attributes.uuid &&
|
|
47
|
-
|
|
47
|
+
siteDomain.includes(cookieParts[4]) &&
|
|
48
48
|
cookieParts[5] === validCookieGenerator
|
|
49
49
|
) {
|
|
50
50
|
return; // Cookie is valid for more than 24 hours, keep it as it is
|
|
51
51
|
}
|
|
52
|
-
await setUserAccessCookie(
|
|
52
|
+
await setUserAccessCookie(siteDomain);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function verifyAndSetNonUserAccessCookie() {
|
|
57
57
|
const cookieName = 'VSTOKEN2';
|
|
58
|
-
const
|
|
58
|
+
const siteDomain = getCurrentSiteDomain();
|
|
59
59
|
const cookie = getCookie(cookieName);
|
|
60
60
|
|
|
61
61
|
new UserDataRequest()
|
|
@@ -63,7 +63,7 @@ function verifyAndSetNonUserAccessCookie() {
|
|
|
63
63
|
.then(async ({ state: { isLoggedIn } }) => {
|
|
64
64
|
if (isLoggedIn) {
|
|
65
65
|
if (typeof cookie !== 'string') {
|
|
66
|
-
await setNonUserAccessCookie(
|
|
66
|
+
await setNonUserAccessCookie(siteDomain);
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
/* The format of the cookie is:
|
|
@@ -77,12 +77,12 @@ function verifyAndSetNonUserAccessCookie() {
|
|
|
77
77
|
// Make sure that current cookie is not too old and is created for this domain by jupiter
|
|
78
78
|
if (
|
|
79
79
|
validTo.getTime() > Date.now() &&
|
|
80
|
-
|
|
80
|
+
siteDomain.includes(cookieParts[4]) &&
|
|
81
81
|
cookieParts[5] === validCookieGenerator
|
|
82
82
|
) {
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
await setNonUserAccessCookie(
|
|
85
|
+
await setNonUserAccessCookie(siteDomain);
|
|
86
86
|
}
|
|
87
87
|
})
|
|
88
88
|
.then(() => {});
|
|
@@ -43,12 +43,12 @@ function itShouldNotAttemptActivation() {
|
|
|
43
43
|
|
|
44
44
|
function itShouldAttemptActivationWithAccessFeatures(
|
|
45
45
|
accessFeatures: string[],
|
|
46
|
-
|
|
46
|
+
siteDomain: string = 'localhost'
|
|
47
47
|
) {
|
|
48
48
|
it('should attempt activation with access features', () => {
|
|
49
49
|
expect(authorization.activate).toHaveBeenCalledWith(
|
|
50
50
|
accessFeatures,
|
|
51
|
-
|
|
51
|
+
siteDomain
|
|
52
52
|
);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
@@ -264,10 +264,10 @@ describe('PaywallUnlocker', () => {
|
|
|
264
264
|
itShouldNotRedirect();
|
|
265
265
|
});
|
|
266
266
|
|
|
267
|
-
describe('with specific
|
|
267
|
+
describe('with specific siteDomain', () => {
|
|
268
268
|
beforeEach(async () => {
|
|
269
269
|
unlockResponse = await new PaywallUnlockRequest()
|
|
270
|
-
.
|
|
270
|
+
.withSiteDomain('www.telen.no')
|
|
271
271
|
.tryUnlock();
|
|
272
272
|
});
|
|
273
273
|
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
setAccessCookies,
|
|
6
6
|
setHasPerformedPaywallReload,
|
|
7
7
|
} from '../actions/authorization';
|
|
8
|
-
import {
|
|
8
|
+
import { getCurrentSiteDomain } from '../utils/url';
|
|
9
9
|
import * as location from '../utils/location';
|
|
10
10
|
import PaywallError from '../exceptions/PaywallError';
|
|
11
11
|
import UserDataRequest from './UserDataRequest';
|
|
@@ -50,10 +50,10 @@ class PaywallUnlockRequest {
|
|
|
50
50
|
|
|
51
51
|
private requestedUrl: string | undefined;
|
|
52
52
|
|
|
53
|
-
private
|
|
53
|
+
private siteDomain: string = getCurrentSiteDomain();
|
|
54
54
|
|
|
55
|
-
public
|
|
56
|
-
this.
|
|
55
|
+
public withSiteDomain(domain: string): this {
|
|
56
|
+
this.siteDomain = domain;
|
|
57
57
|
return this;
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -146,7 +146,7 @@ class PaywallUnlockRequest {
|
|
|
146
146
|
private setAccessCookiesAndGetAccessFeatures(
|
|
147
147
|
requestedAccessFeatures: AccessFeatures
|
|
148
148
|
) {
|
|
149
|
-
return setAccessCookies(
|
|
149
|
+
return setAccessCookies(getCurrentSiteDomain()).then((response) => {
|
|
150
150
|
const accessDenied = !hasAccess(
|
|
151
151
|
response.accessFeatures,
|
|
152
152
|
requestedAccessFeatures
|
|
@@ -167,7 +167,7 @@ class PaywallUnlockRequest {
|
|
|
167
167
|
private async activateAccess(requestedAccessFeatures: AccessFeatures) {
|
|
168
168
|
const accessFeatures = await activate(
|
|
169
169
|
this.requestedAccessFeatures,
|
|
170
|
-
this.
|
|
170
|
+
this.siteDomain
|
|
171
171
|
);
|
|
172
172
|
return {
|
|
173
173
|
denied: !hasAccess(accessFeatures, requestedAccessFeatures),
|
package/src/utils/debouncer.ts
CHANGED
|
@@ -26,7 +26,7 @@ function deepCopy<T>(obj: T): T {
|
|
|
26
26
|
* resolve my promise', but instead of the fetch being performed right away, we want to wait for more users to
|
|
27
27
|
* request other stuff. This will keep us from performing lots of individual fetches to the backend.
|
|
28
28
|
*
|
|
29
|
-
* Our main use case is a standard
|
|
29
|
+
* Our main use case is a standard site front page where one component on the page requests the euucp namespace
|
|
30
30
|
* from Europa, and then another component requests the privacy_preferences namespace. Instead of the Europa client
|
|
31
31
|
* calling two fetches to the server, one for euucp and another for privacy_preferences, we want the Debouncer to
|
|
32
32
|
* aggregate these calls into one call to the backend, that requests both euucp AND privacy_preferences, so the response
|
package/src/utils/url.spec.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getCurrentEnvironment,
|
|
3
|
-
|
|
3
|
+
getCurrentSiteDomain,
|
|
4
4
|
setCurrentHostname,
|
|
5
5
|
} from './url';
|
|
6
6
|
|
|
7
7
|
describe('URL utils', () => {
|
|
8
|
-
it('should get proper
|
|
8
|
+
it('should get proper site domain', () => {
|
|
9
9
|
const domains = [
|
|
10
10
|
'www.telen.no.localhost.api.no',
|
|
11
11
|
'www.telen.no.snap5.api.no',
|
|
@@ -14,7 +14,7 @@ describe('URL utils', () => {
|
|
|
14
14
|
expect.assertions(domains.length);
|
|
15
15
|
domains.forEach((domain) => {
|
|
16
16
|
setCurrentHostname(domain);
|
|
17
|
-
expect(
|
|
17
|
+
expect(getCurrentSiteDomain()).toEqual('www.telen.no');
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
|
package/src/utils/url.ts
CHANGED
|
@@ -22,7 +22,7 @@ export const getCurrentEnvironment = () => {
|
|
|
22
22
|
return null;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export const
|
|
25
|
+
export const getCurrentSiteDomain = () =>
|
|
26
26
|
getCurrentHostname().replace(/\.[^.]+\.api\.no/, '');
|
|
27
27
|
|
|
28
28
|
export const getAidDomain = (): string => {
|