@amedia/user 0.14.17 → 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.
Files changed (86) hide show
  1. package/dist/user.d.ts +1 -1
  2. package/package.json +2 -3
  3. package/src/actions/authentication.spec.ts +0 -51
  4. package/src/actions/authentication.ts +0 -49
  5. package/src/actions/authorization.spec.ts +0 -377
  6. package/src/actions/authorization.ts +0 -120
  7. package/src/actions/preferences.spec.ts +0 -41
  8. package/src/actions/preferences.ts +0 -41
  9. package/src/actions/storage.ts +0 -22
  10. package/src/actions/userData.spec.ts +0 -133
  11. package/src/actions/userData.ts +0 -68
  12. package/src/autologin/index.spec.ts +0 -264
  13. package/src/autologin/index.ts +0 -113
  14. package/src/autologin/thirdPartyCookie.spec.ts +0 -95
  15. package/src/autologin/thirdPartyCookie.ts +0 -55
  16. package/src/cache/engines/global.spec.ts +0 -62
  17. package/src/cache/engines/global.ts +0 -49
  18. package/src/cache/index.spec.ts +0 -132
  19. package/src/cache/index.ts +0 -48
  20. package/src/cache/types.ts +0 -12
  21. package/src/clients/europa.spec.ts +0 -209
  22. package/src/clients/europa.ts +0 -183
  23. package/src/clients/jupiter.spec.ts +0 -178
  24. package/src/clients/jupiter.ts +0 -119
  25. package/src/clients/mercury.spec.ts +0 -126
  26. package/src/clients/mercury.ts +0 -105
  27. package/src/clients/mercuryLog.spec.ts +0 -20
  28. package/src/clients/mercuryLog.ts +0 -67
  29. package/src/clients/nebula.spec.ts +0 -70
  30. package/src/clients/nebula.ts +0 -83
  31. package/src/clients/pluto.spec.ts +0 -262
  32. package/src/clients/pluto.ts +0 -126
  33. package/src/eventHandlers/activation.ts +0 -40
  34. package/src/eventHandlers/authentication.ts +0 -34
  35. package/src/eventHandlers/eventMap.ts +0 -40
  36. package/src/eventHandlers/navigation.spec.ts +0 -189
  37. package/src/eventHandlers/navigation.ts +0 -58
  38. package/src/eventHandlers/state.spec.ts +0 -48
  39. package/src/eventHandlers/state.ts +0 -23
  40. package/src/eventHandlers/storage.spec.ts +0 -114
  41. package/src/eventHandlers/storage.ts +0 -45
  42. package/src/eventHandlers/userAttributes.spec.ts +0 -93
  43. package/src/eventHandlers/userAttributes.ts +0 -31
  44. package/src/exceptions/FetchTimeoutError.ts +0 -8
  45. package/src/exceptions/PaywallError.ts +0 -16
  46. package/src/index-authentcation.spec.ts +0 -26
  47. package/src/index-storage.spec.ts +0 -144
  48. package/src/index-subscription.spec.ts +0 -213
  49. package/src/index.ts +0 -46
  50. package/src/janitor/index.spec.ts +0 -18
  51. package/src/janitor/index.ts +0 -60
  52. package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -213
  53. package/src/janitor/jobs/accessCookieRefresher.ts +0 -96
  54. package/src/janitor/jobs/daxsubCookie.spec.ts +0 -109
  55. package/src/janitor/jobs/daxsubCookie.ts +0 -38
  56. package/src/janitor/jobs/removeUserStorage.spec.ts +0 -34
  57. package/src/janitor/jobs/removeUserStorage.ts +0 -12
  58. package/src/lib/PaywallUnlockRequest.spec.ts +0 -446
  59. package/src/lib/PaywallUnlockRequest.ts +0 -161
  60. package/src/lib/UserDataRequest.spec.ts +0 -231
  61. package/src/lib/UserDataRequest.ts +0 -267
  62. package/src/lib/cookie.ts +0 -121
  63. package/src/lib/rpc.ts +0 -19
  64. package/src/store/index.spec.ts +0 -49
  65. package/src/store/index.ts +0 -66
  66. package/src/types.ts +0 -22
  67. package/src/utils/customEventWrapper.spec.ts +0 -237
  68. package/src/utils/customEventWrapper.ts +0 -77
  69. package/src/utils/debouncer.spec.ts +0 -252
  70. package/src/utils/debouncer.ts +0 -123
  71. package/src/utils/deepEquals.ts +0 -42
  72. package/src/utils/expectBootLogs.ts +0 -9
  73. package/src/utils/getGlobalThis.ts +0 -17
  74. package/src/utils/getOrUpdate.spec.ts +0 -166
  75. package/src/utils/getOrUpdate.ts +0 -66
  76. package/src/utils/localhostCheck.ts +0 -10
  77. package/src/utils/location.spec.ts +0 -61
  78. package/src/utils/location.ts +0 -16
  79. package/src/utils/log.spec.ts +0 -177
  80. package/src/utils/log.ts +0 -112
  81. package/src/utils/loginState.ts +0 -24
  82. package/src/utils/networkError.ts +0 -11
  83. package/src/utils/queue.ts +0 -32
  84. package/src/utils/type.ts +0 -19
  85. package/src/utils/url.spec.ts +0 -33
  86. package/src/utils/url.ts +0 -37
@@ -1,446 +0,0 @@
1
- import PaywallUnlockRequest, { UnlockResponse } from './PaywallUnlockRequest';
2
- import * as authorization from '../actions/authorization';
3
- import * as location from '../utils/location';
4
- import * as autologin from '../autologin';
5
- import * as localhostCheck from '../utils/localhostCheck';
6
- import * as mercury from '../clients/mercury';
7
- import { AffiliationType } from '../clients/mercury';
8
- import store from '../store';
9
- import PaywallError from '../exceptions/PaywallError';
10
- import { listenForUserAttributeRequests } from '../eventHandlers/userAttributes';
11
- import { listenForStateRequests } from '../eventHandlers/state';
12
- import { removeAllCookies } from './cookie';
13
- import spyOn = jest.spyOn;
14
-
15
- beforeEach(() => {
16
- store.clear();
17
-
18
- removeAllCookies();
19
-
20
- listenForStateRequests();
21
- listenForUserAttributeRequests();
22
- });
23
-
24
- function itShouldNotReload() {
25
- it('should not reload', () => {
26
- expect(location.reload).not.toHaveBeenCalled();
27
- });
28
- }
29
-
30
- function itShouldNotRedirect() {
31
- it('should not redirect', () => {
32
- expect(location.replace).not.toHaveBeenCalled();
33
- });
34
- }
35
-
36
- function itShouldNotAttemptActivation() {
37
- it('should not attempt activation', () => {
38
- expect(authorization.activate).not.toHaveBeenCalled();
39
- });
40
- }
41
-
42
- function itShouldAttemptActivationWithAccessFeatures(
43
- accessFeatures: string[],
44
- siteDomain: string = 'localhost'
45
- ) {
46
- it('should attempt activation with access features', () => {
47
- expect(authorization.activate).toHaveBeenCalledWith(
48
- accessFeatures,
49
- siteDomain
50
- );
51
- });
52
- }
53
-
54
- function itShouldHaveAskedForSitesThatProvideRequestedAccessFeatures(
55
- accessFeatures: string[]
56
- ) {
57
- it('should have asked for sites', () => {
58
- expect(mercury.getPrimarySite).toHaveBeenCalledWith(accessFeatures);
59
- });
60
- }
61
-
62
- describe('PaywallUnlocker', () => {
63
- beforeEach(() => {
64
- spyOn(autologin, 'attemptPaywallAutoLogin').mockResolvedValue();
65
- spyOn(authorization, 'setHasPerformedPaywallReload');
66
- spyOn(authorization, 'activate');
67
- spyOn(location, 'reload').mockReturnValue();
68
- spyOn(location, 'replace').mockReturnValue();
69
- });
70
-
71
- describe('When running on localhost', () => {
72
- beforeEach(() => {
73
- jest.spyOn(localhostCheck, 'isRunningOnLocalhost').mockReturnValue(true);
74
- });
75
-
76
- it('should fail with expected error', async () => {
77
- try {
78
- await new PaywallUnlockRequest().tryUnlock();
79
- } catch (e) {
80
- expect(e).toEqual(
81
- new Error('@amedia/user cannot unlock paywall on localhost')
82
- );
83
- }
84
- });
85
- });
86
-
87
- describe('When not logged in', () => {
88
- let unlockResponse: UnlockResponse;
89
- beforeEach(async () => {
90
- store.set('state', { isLoggedIn: false });
91
- store.set('userAttributes', { uuid: 'uuid', name: 'Donald Duck' });
92
- unlockResponse = await new PaywallUnlockRequest().tryUnlock();
93
- });
94
-
95
- it('should attempt autologin', async () => {
96
- expect(autologin.attemptPaywallAutoLogin).toHaveBeenCalledTimes(1);
97
- });
98
-
99
- it('should return no access', () => {
100
- expect(unlockResponse).toEqual({
101
- isLoggedIn: false,
102
- hasAccess: false,
103
- accessFeatures: [],
104
- });
105
- });
106
-
107
- itShouldNotRedirect();
108
- itShouldNotReload();
109
- });
110
-
111
- describe('When loggen in', () => {
112
- beforeEach(() => {
113
- store.set('state', { isLoggedIn: true });
114
- store.set('userAttributes', { uuid: 'uuid', name: 'Donald Duck' });
115
- });
116
-
117
- it('should not attempt autologin', () => {
118
- expect(autologin.attemptPaywallAutoLogin).not.toHaveBeenCalled();
119
- });
120
-
121
- itShouldNotRedirect();
122
- itShouldNotReload();
123
-
124
- describe('when has access', () => {
125
- let unlockResponse: UnlockResponse;
126
- beforeEach(async () => {
127
- store.merge('userAttributes', { access: ['newspaper'] });
128
- spyOn(authorization, 'setAccessCookies').mockResolvedValue({
129
- success: true,
130
- accessFeatures: ['newspaper'],
131
- });
132
-
133
- unlockResponse = await new PaywallUnlockRequest().tryUnlock();
134
- });
135
-
136
- describe('When called with reload and already tried to reload', () => {
137
- let error: Error | undefined;
138
- beforeEach(async () => {
139
- spyOn(
140
- authorization,
141
- 'hasRecentlyPerformedPaywallReload'
142
- ).mockReturnValue(true);
143
- error = undefined;
144
- try {
145
- await new PaywallUnlockRequest().reloadOnAccess().tryUnlock();
146
- } catch (e) {
147
- error = e;
148
- }
149
- });
150
- it('should throw exception', () => {
151
- expect(error).toEqual(
152
- new PaywallError(
153
- 'Unlock check already performed.',
154
- PaywallError.ERROR_RELOADED_NO_ACCESS
155
- )
156
- );
157
- });
158
- });
159
-
160
- it('should not store that we tried, since we perform no reload', () => {
161
- expect(
162
- authorization.setHasPerformedPaywallReload
163
- ).not.toHaveBeenCalled();
164
- });
165
-
166
- it('should give access with access features', () => {
167
- expect(unlockResponse).toEqual({
168
- isLoggedIn: true,
169
- hasAccess: true,
170
- accessFeatures: ['newspaper'],
171
- });
172
- });
173
-
174
- itShouldNotAttemptActivation();
175
- itShouldNotRedirect();
176
- itShouldNotReload();
177
- });
178
-
179
- describe('without access', () => {
180
- describe('and activation give access', () => {
181
- let unlockResponse: UnlockResponse;
182
- beforeEach(() => {
183
- spyOn(authorization, 'setAccessCookies')
184
- .mockResolvedValueOnce({
185
- success: true,
186
- accessFeatures: [],
187
- })
188
- .mockResolvedValueOnce({
189
- success: true,
190
- accessFeatures: ['newspaper'],
191
- });
192
- spyOn(authorization, 'activate').mockResolvedValue(['newspaper']);
193
- });
194
-
195
- describe('with no post access actions', () => {
196
- beforeEach(async () => {
197
- unlockResponse = await new PaywallUnlockRequest().tryUnlock();
198
- });
199
-
200
- it('should give access with access features', () => {
201
- expect(unlockResponse).toEqual({
202
- isLoggedIn: true,
203
- hasAccess: true,
204
- accessFeatures: ['newspaper'],
205
- });
206
- });
207
-
208
- itShouldAttemptActivationWithAccessFeatures(['newspaper']);
209
- itShouldNotRedirect();
210
- itShouldNotReload();
211
- });
212
-
213
- describe('with redirect requested', () => {
214
- beforeEach(async () => {
215
- new PaywallUnlockRequest()
216
- .redirectOnAccess('https://redirect.pls')
217
- .tryUnlock()
218
- .then((res) => {
219
- unlockResponse = res;
220
- });
221
- });
222
-
223
- it('should give access with access features', () => {
224
- expect(unlockResponse).toEqual({
225
- isLoggedIn: true,
226
- hasAccess: true,
227
- accessFeatures: ['newspaper'],
228
- });
229
- });
230
-
231
- it('should navigate to expected url', (done) => {
232
- /**
233
- * This is not great.
234
- * Since tryUnlock performs some async actions and we, by design,
235
- * don't want to resolve tryUnlock when navigating, we have to
236
- * wait for the next event loop to check location.
237
- */
238
- setTimeout(() => {
239
- expect(location.replace).toHaveBeenCalledWith(
240
- 'https://redirect.pls'
241
- );
242
- done();
243
- }, 0);
244
- });
245
-
246
- itShouldAttemptActivationWithAccessFeatures(['newspaper']);
247
- itShouldNotReload();
248
- });
249
-
250
- describe('with reload requested', () => {
251
- beforeEach(async () => {
252
- new PaywallUnlockRequest()
253
- .reloadOnAccess()
254
- .tryUnlock()
255
- .then((res) => {
256
- unlockResponse = res;
257
- });
258
- });
259
-
260
- it('should give access with access features', () => {
261
- expect(unlockResponse).toEqual({
262
- isLoggedIn: true,
263
- hasAccess: true,
264
- accessFeatures: ['newspaper'],
265
- });
266
- });
267
-
268
- it('should reload on access', (done) => {
269
- setTimeout(() => {
270
- expect(location.reload).toHaveBeenCalled();
271
- done();
272
- }, 0);
273
- });
274
-
275
- itShouldAttemptActivationWithAccessFeatures(['newspaper']);
276
- itShouldNotRedirect();
277
- });
278
-
279
- describe('with specific siteDomain', () => {
280
- beforeEach(async () => {
281
- unlockResponse = await new PaywallUnlockRequest()
282
- .withSiteDomain('www.telen.no')
283
- .tryUnlock();
284
- });
285
-
286
- it('should give access with access features', () => {
287
- expect(unlockResponse).toEqual({
288
- isLoggedIn: true,
289
- hasAccess: true,
290
- accessFeatures: ['newspaper'],
291
- });
292
- });
293
-
294
- itShouldAttemptActivationWithAccessFeatures(
295
- ['newspaper'],
296
- 'www.telen.no'
297
- );
298
- itShouldNotReload();
299
- itShouldNotRedirect();
300
- });
301
- });
302
-
303
- describe('and activation does not give access', () => {
304
- let unlockResponse: UnlockResponse;
305
- beforeEach(async () => {
306
- spyOn(authorization, 'setAccessCookies').mockResolvedValueOnce({
307
- success: true,
308
- accessFeatures: [],
309
- });
310
- spyOn(authorization, 'activate').mockResolvedValue([]);
311
- spyOn(mercury, 'getPrimarySite').mockResolvedValue({
312
- domain: 'www.telen.no',
313
- name: 'Telen',
314
- affiliation: AffiliationType.ACCESS,
315
- affiliations: [
316
- AffiliationType.ACCESS,
317
- AffiliationType.SUBSCRIPTION,
318
- ],
319
- });
320
- unlockResponse = await new PaywallUnlockRequest().tryUnlock();
321
- });
322
-
323
- it('should not give access', () => {
324
- expect(unlockResponse).toEqual({
325
- isLoggedIn: true,
326
- hasAccess: false,
327
- accessFeatures: [],
328
- primarySite: {
329
- name: 'Telen',
330
- domain: 'www.telen.no',
331
- affiliation: AffiliationType.ACCESS,
332
- affiliations: [
333
- AffiliationType.ACCESS,
334
- AffiliationType.SUBSCRIPTION,
335
- ],
336
- },
337
- });
338
- });
339
-
340
- itShouldHaveAskedForSitesThatProvideRequestedAccessFeatures([
341
- 'newspaper',
342
- ]);
343
- itShouldAttemptActivationWithAccessFeatures(['newspaper']);
344
- itShouldNotRedirect();
345
- itShouldNotReload();
346
- });
347
-
348
- describe("and activation don't give enough access", () => {
349
- let unlockResponse: UnlockResponse;
350
- beforeEach(async () => {
351
- spyOn(authorization, 'setAccessCookies').mockResolvedValueOnce({
352
- success: true,
353
- accessFeatures: ['newspaper'],
354
- });
355
- spyOn(authorization, 'activate').mockResolvedValue(['newspaper']);
356
- spyOn(mercury, 'getPrimarySite').mockResolvedValue(null);
357
- unlockResponse = await new PaywallUnlockRequest()
358
- .withAccessFeatures(['plussalt'])
359
- .tryUnlock();
360
- });
361
-
362
- it('should not give access, but return users access features', () => {
363
- expect(unlockResponse).toEqual({
364
- isLoggedIn: true,
365
- hasAccess: false,
366
- accessFeatures: ['newspaper'],
367
- primarySite: null,
368
- });
369
- });
370
-
371
- itShouldHaveAskedForSitesThatProvideRequestedAccessFeatures([
372
- 'plussalt',
373
- ]);
374
- itShouldAttemptActivationWithAccessFeatures(['plussalt']);
375
- itShouldNotRedirect();
376
- itShouldNotReload();
377
- });
378
- });
379
-
380
- describe('when setting access cookies fails', () => {
381
- let paywallError: any;
382
- beforeEach(async () => {
383
- spyOn(authorization, 'setAccessCookies').mockResolvedValue({
384
- success: false,
385
- accessFeatures: [],
386
- });
387
- try {
388
- await new PaywallUnlockRequest().tryUnlock();
389
- } catch (error) {
390
- paywallError = error;
391
- }
392
- });
393
-
394
- it('should throw error', () => {
395
- expect(paywallError).toEqual(
396
- new PaywallError(
397
- 'Could not set access cookies',
398
- PaywallError.ERROR_ENABLING_ACCESS_FAILED
399
- )
400
- );
401
- });
402
-
403
- itShouldNotAttemptActivation();
404
- itShouldNotRedirect();
405
- itShouldNotReload();
406
- });
407
-
408
- describe('when internal system disagree about users access', () => {
409
- let paywallError: any;
410
- beforeEach(async () => {
411
- spyOn(authorization, 'setAccessCookies')
412
- .mockResolvedValueOnce({
413
- success: true,
414
- accessFeatures: ['newspaper'],
415
- })
416
- .mockResolvedValueOnce({
417
- success: true,
418
- accessFeatures: ['newspaper'], // Notice not changed
419
- });
420
- spyOn(authorization, 'activate').mockResolvedValue([
421
- 'newspaper',
422
- 'plussalt',
423
- ]);
424
- try {
425
- await new PaywallUnlockRequest()
426
- .withAccessFeatures(['plussalt'])
427
- .tryUnlock();
428
- } catch (error) {
429
- paywallError = error;
430
- }
431
- });
432
-
433
- it('should throw error about bad access state', () => {
434
- expect(paywallError).toEqual(
435
- new PaywallError(
436
- 'New subscription was attached and checked successfully, but internal systems disagree about current newspaper access.',
437
- PaywallError.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES
438
- )
439
- );
440
- });
441
-
442
- itShouldNotReload();
443
- itShouldNotRedirect();
444
- });
445
- });
446
- });
@@ -1,161 +0,0 @@
1
- import {
2
- activate,
3
- hasAccess,
4
- hasRecentlyPerformedPaywallReload,
5
- setAccessCookies,
6
- setHasPerformedPaywallReload,
7
- } from '../actions/authorization';
8
- import { getCurrentSiteDomain } from '../utils/url';
9
- import PaywallError from '../exceptions/PaywallError';
10
- import UserDataRequest from './UserDataRequest';
11
- import { attemptPaywallAutoLogin } from '../autologin';
12
- import { AccessFeatures } from '../clients/jupiter';
13
- import { isRunningOnLocalhost } from '../utils/localhostCheck';
14
- import { reload, replace } from '../utils/location';
15
-
16
- import { getPrimarySite, PrimarySite } from '../clients/mercury';
17
-
18
- export type UnlockResponse = {
19
- isLoggedIn: boolean;
20
- hasAccess: boolean;
21
- primarySite?: null | PrimarySite;
22
- accessFeatures: string[];
23
- };
24
-
25
- class PaywallUnlockRequest {
26
- private requestedAccessFeatures: string[] = ['newspaper'];
27
-
28
- private reload: boolean = false;
29
-
30
- private requestedUrl: string | undefined;
31
-
32
- private siteDomain: string = getCurrentSiteDomain();
33
-
34
- public withSiteDomain(domain: string): this {
35
- this.siteDomain = domain;
36
- return this;
37
- }
38
-
39
- public withAccessFeatures(accessFeatures: string[]): this {
40
- this.requestedAccessFeatures = accessFeatures;
41
- return this;
42
- }
43
-
44
- public reloadOnAccess(): this {
45
- this.reload = true;
46
- return this;
47
- }
48
-
49
- public redirectOnAccess(requestedUrl: string): this {
50
- this.requestedUrl = requestedUrl;
51
- return this;
52
- }
53
-
54
- public async tryUnlock(): Promise<UnlockResponse> {
55
- if (isRunningOnLocalhost()) {
56
- return Promise.reject(
57
- new Error('@amedia/user cannot unlock paywall on localhost')
58
- );
59
- }
60
- const {
61
- state: { isLoggedIn },
62
- } = await new UserDataRequest().withAttributes(['name']).fetch();
63
- if (!isLoggedIn) {
64
- // Will attempt one or more strategies for creating a first party session
65
- // Redirects/reloads might occur
66
- await attemptPaywallAutoLogin();
67
- return {
68
- isLoggedIn: false,
69
- hasAccess: false,
70
- accessFeatures: [],
71
- };
72
- }
73
-
74
- let currentAccess = await this.setAccessCookiesAndGetAccessFeatures(
75
- this.requestedAccessFeatures
76
- );
77
- if (currentAccess.denied) {
78
- // Check if we actually have a valid subscription that's not properly connected to the user yet
79
- currentAccess = await this.activateAccess(this.requestedAccessFeatures);
80
- if (currentAccess.denied) {
81
- const primarySite = await getPrimarySite(this.requestedAccessFeatures);
82
- return {
83
- isLoggedIn: true,
84
- hasAccess: false,
85
- primarySite,
86
- accessFeatures: currentAccess.accessFeatures,
87
- };
88
- }
89
- currentAccess = await this.setAccessCookiesAndGetAccessFeatures(
90
- this.requestedAccessFeatures
91
- );
92
- if (currentAccess.denied) {
93
- throw new PaywallError(
94
- 'New subscription was attached and checked successfully, but internal systems disagree about current newspaper access.',
95
- PaywallError.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES
96
- );
97
- }
98
- }
99
- if (this.reload || this.requestedUrl) {
100
- // Ensures we don't get stuck in a reload/redirect loop
101
- if (hasRecentlyPerformedPaywallReload(this.requestedUrl)) {
102
- throw new PaywallError(
103
- 'Unlock check already performed.',
104
- PaywallError.ERROR_RELOADED_NO_ACCESS
105
- );
106
- }
107
-
108
- setHasPerformedPaywallReload(this.requestedUrl);
109
- if (this.reload) {
110
- reload();
111
- }
112
-
113
- if (this.requestedUrl) {
114
- replace(this.requestedUrl);
115
- }
116
-
117
- // Don't resolve tryUnlock promise if we're being reloaded/navigated away
118
- return new Promise(() => {});
119
- }
120
- return {
121
- isLoggedIn: true,
122
- hasAccess: true,
123
- accessFeatures: currentAccess.accessFeatures,
124
- };
125
- }
126
-
127
- // eslint-disable-next-line class-methods-use-this
128
- private setAccessCookiesAndGetAccessFeatures(
129
- requestedAccessFeatures: AccessFeatures
130
- ) {
131
- return setAccessCookies(getCurrentSiteDomain()).then((response) => {
132
- const accessDenied = !hasAccess(
133
- response.accessFeatures,
134
- requestedAccessFeatures
135
- );
136
- if (!response.success && accessDenied) {
137
- throw new PaywallError(
138
- 'Could not set access cookies',
139
- PaywallError.ERROR_ENABLING_ACCESS_FAILED
140
- );
141
- }
142
- return {
143
- denied: accessDenied,
144
- accessFeatures: response.accessFeatures,
145
- };
146
- });
147
- }
148
-
149
- private async activateAccess(requestedAccessFeatures: AccessFeatures) {
150
- const accessFeatures = await activate(
151
- this.requestedAccessFeatures,
152
- this.siteDomain
153
- );
154
- return {
155
- denied: !hasAccess(accessFeatures, requestedAccessFeatures),
156
- accessFeatures,
157
- };
158
- }
159
- }
160
-
161
- export default PaywallUnlockRequest;