@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,40 +0,0 @@
1
- import { State, UserAttributes } from '../types';
2
-
3
- export enum AmediaUserEvents {
4
- REQUEST_STATE = 'amedia-user.request-state',
5
- REQUEST_USER_ATTRIBUTES = 'amedia-user.request-user-attributes',
6
- REQUEST_STORAGE_NAMESPACES = 'amedia-user.request-storage-namespaces',
7
- REQUEST_NAVIGATION = 'amedia-user.request-navigation',
8
- SAVE_STORAGE = 'amedia-user.save-storage-namespaces',
9
- UPDATE_STORAGE = 'amedia-user.update-storage-namespaces',
10
- ON_ATTRIBUTES_UPDATED = 'amedia-user.on-user-attributes-updated',
11
- ON_STATE_UPDATED = 'amedia-user.on-state-updated',
12
- ON_STORAGE_UPDATED = 'amedia-user.on-storage-updated',
13
- }
14
-
15
- declare global {
16
- interface WindowEventMap {
17
- [AmediaUserEvents.REQUEST_STATE]: CustomEvent;
18
- [AmediaUserEvents.REQUEST_USER_ATTRIBUTES]: CustomEvent<
19
- Array<keyof UserAttributes>
20
- >;
21
- [AmediaUserEvents.REQUEST_STORAGE_NAMESPACES]: CustomEvent<Array<string>>;
22
- [AmediaUserEvents.REQUEST_NAVIGATION]: CustomEvent<{
23
- type: 'reload' | 'location';
24
- url?: string;
25
- replace?: boolean;
26
- }>;
27
- [AmediaUserEvents.SAVE_STORAGE]: CustomEvent<{
28
- [namespace: string]: object;
29
- }>;
30
- [AmediaUserEvents.UPDATE_STORAGE]: CustomEvent<{
31
- [namespace: string]: object;
32
- }>;
33
- // @ts-ignore
34
- [AmediaUserEvents.ON_ATTRIBUTES_UPDATED]: CustomEvent<UserAttributes>;
35
- [AmediaUserEvents.ON_STATE_UPDATED]: CustomEvent<State>;
36
- [AmediaUserEvents.ON_STORAGE_UPDATED]: CustomEvent<{
37
- [index: string]: unknown;
38
- }>;
39
- }
40
- }
@@ -1,189 +0,0 @@
1
- import store from '../store';
2
- import log from '../utils/log';
3
- import * as navigation from './navigation';
4
- import { dispatch } from '../utils/customEventWrapper';
5
- import { AmediaUserEvents } from './eventMap';
6
-
7
- const itShouldSetLocationHrefTo = (url: string) => {
8
- it('should set location href', () => {
9
- expect(navigation.internalLocationHref).toHaveBeenCalledWith(url);
10
- });
11
- };
12
- const itShouldNotSetLocationHref = () => {
13
- it('should not set location href', () => {
14
- expect(navigation.internalLocationHref).not.toHaveBeenCalled();
15
- });
16
- };
17
-
18
- const itShouldReplaceLocationWith = (url: string) => {
19
- it('should replace location', () => {
20
- expect(navigation.internalLocationReplace).toHaveBeenCalledWith(url);
21
- });
22
- };
23
- const itShouldNotReplaceLocation = () => {
24
- it('should not replace location', () => {
25
- expect(navigation.internalLocationReplace).not.toHaveBeenCalled();
26
- });
27
- };
28
-
29
- const itShouldReload = () => {
30
- it('should reload', () => {
31
- expect(navigation.internalLocationReload).toHaveBeenCalled();
32
- });
33
- };
34
-
35
- const itShouldNotReload = () => {
36
- it('should not reload', () => {
37
- expect(navigation.internalLocationReload).not.toHaveBeenCalled();
38
- });
39
- };
40
-
41
- const itShouldPoisonTheWell = () => {
42
- it('should poison the well', () => {
43
- expect(store.get('isPoisoned')).toBeTrue();
44
- });
45
- };
46
-
47
- const itShouldNotPoisonTheWell = () => {
48
- it('should poison the well', () => {
49
- expect(store.get('isPoisoned')).toBeFalsy();
50
- });
51
- };
52
-
53
- const itShouldLogError = (message: string) => {
54
- it('should log error', () => {
55
- expect(log.error).toHaveBeenCalledWith(message);
56
- });
57
- };
58
-
59
- const itShouldNotLogError = () => {
60
- it('should not log error', () => {
61
- expect(log.error).not.toHaveBeenCalled();
62
- });
63
- };
64
-
65
- beforeEach(() => {
66
- store.clear();
67
-
68
- spyOn(log, 'error').and.stub();
69
- spyOn(navigation, 'internalLocationHref').and.stub();
70
- spyOn(navigation, 'internalLocationReload').and.stub();
71
- spyOn(navigation, 'internalLocationReplace').and.stub();
72
-
73
- navigation.listenForNavigationRequests();
74
- });
75
-
76
- describe('when window is not set', () => {
77
- beforeEach(() => {
78
- spyOn(navigation, 'missingWindowContext').and.returnValue(true);
79
- dispatch(
80
- new CustomEvent(AmediaUserEvents.REQUEST_NAVIGATION, {
81
- detail: { type: 'reload' },
82
- })
83
- );
84
- });
85
-
86
- itShouldLogError(
87
- 'Navigation attempted context without window. Be careful not to use interactive UX code in workers and other settings.'
88
- );
89
-
90
- itShouldNotReload();
91
- itShouldNotSetLocationHref();
92
- itShouldNotReplaceLocation();
93
- itShouldNotPoisonTheWell();
94
- });
95
-
96
- describe('when window exists', () => {
97
- beforeEach(() => {
98
- spyOn(navigation, 'missingWindowContext').and.returnValue(false);
99
- });
100
-
101
- describe('and requesting reload', () => {
102
- beforeEach(() => {
103
- dispatch(
104
- new CustomEvent(AmediaUserEvents.REQUEST_NAVIGATION, {
105
- detail: { type: 'reload' },
106
- })
107
- );
108
- });
109
-
110
- itShouldReload();
111
- itShouldPoisonTheWell();
112
-
113
- itShouldNotSetLocationHref();
114
- itShouldNotReplaceLocation();
115
- itShouldNotLogError();
116
- });
117
-
118
- describe('and requesting location change', () => {
119
- beforeEach(() => {
120
- dispatch(
121
- new CustomEvent(AmediaUserEvents.REQUEST_NAVIGATION, {
122
- detail: { type: 'location', url: 'https://www.telen.no' },
123
- })
124
- );
125
- });
126
-
127
- itShouldSetLocationHrefTo('https://www.telen.no');
128
- itShouldPoisonTheWell();
129
-
130
- itShouldNotReload();
131
- itShouldNotReplaceLocation();
132
- itShouldNotLogError();
133
- });
134
-
135
- describe('and requesting location change but forgetting to set url', () => {
136
- beforeEach(() => {
137
- dispatch(
138
- new CustomEvent(AmediaUserEvents.REQUEST_NAVIGATION, {
139
- detail: { type: 'location' },
140
- })
141
- );
142
- });
143
-
144
- itShouldLogError(`Url required for navigation`);
145
-
146
- itShouldNotReload();
147
- itShouldNotSetLocationHref();
148
- itShouldNotReplaceLocation();
149
- itShouldNotPoisonTheWell();
150
- });
151
-
152
- describe('and requesting location replacing', () => {
153
- beforeEach(() => {
154
- dispatch(
155
- new CustomEvent(AmediaUserEvents.REQUEST_NAVIGATION, {
156
- detail: {
157
- type: 'location',
158
- url: 'https://www.telen.no',
159
- replace: true,
160
- },
161
- })
162
- );
163
- });
164
-
165
- itShouldReplaceLocationWith('https://www.telen.no');
166
- itShouldPoisonTheWell();
167
-
168
- itShouldNotReload();
169
- itShouldNotSetLocationHref();
170
- itShouldNotLogError();
171
- });
172
-
173
- describe('but using invalid action', () => {
174
- beforeEach(() => {
175
- dispatch(
176
- new CustomEvent(AmediaUserEvents.REQUEST_NAVIGATION, {
177
- detail: { type: 'invalid' },
178
- })
179
- );
180
- });
181
-
182
- itShouldLogError(`Unknown navigation type (invalid)`);
183
-
184
- itShouldNotReload();
185
- itShouldNotSetLocationHref();
186
- itShouldNotReplaceLocation();
187
- itShouldNotPoisonTheWell();
188
- });
189
- });
@@ -1,58 +0,0 @@
1
- import { listenWithExclusivity } from '../utils/customEventWrapper';
2
- import { AmediaUserEvents } from './eventMap';
3
- import store from '../store';
4
- import log from '../utils/log';
5
-
6
- export const internalLocationHref = (url: string) => {
7
- window.location.href = url;
8
- };
9
-
10
- export const internalLocationReload = () => window.location.reload();
11
- export const internalLocationReplace = (url: string) =>
12
- window.location.replace(url);
13
-
14
- export const missingWindowContext = () => typeof window === 'undefined';
15
-
16
- const handleNavigation = ({
17
- detail: { type, url, replace },
18
- }: WindowEventMap[AmediaUserEvents.REQUEST_NAVIGATION]) => {
19
- switch (type) {
20
- case 'location':
21
- if (!url) {
22
- throw new Error('Url required for navigation');
23
- }
24
- if (replace) {
25
- internalLocationReplace(url);
26
- } else {
27
- internalLocationHref(url);
28
- }
29
- break;
30
- case 'reload':
31
- internalLocationReload();
32
- break;
33
- default:
34
- throw new Error(`Unknown navigation type (${type})`);
35
- }
36
- };
37
-
38
- export const listenForNavigationRequests = () =>
39
- listenWithExclusivity(AmediaUserEvents.REQUEST_NAVIGATION, (evt) => {
40
- if (missingWindowContext()) {
41
- log.error(
42
- 'Navigation attempted context without window. Be careful not to use interactive UX code in workers and other settings.'
43
- );
44
- return;
45
- }
46
-
47
- try {
48
- handleNavigation(evt);
49
- /**
50
- * This will prevent any further event dispatching.
51
- * Effectively having requesters of data wait "forever" (the few
52
- * milliseconds) until we navigate away
53
- */
54
- store.set('isPoisoned', true);
55
- } catch (e) {
56
- log.error(e.message);
57
- }
58
- });
@@ -1,48 +0,0 @@
1
- import { dispatch, listenForAllEvents } from '../utils/customEventWrapper';
2
- import store from '../store';
3
- import { AmediaUserEvents } from './eventMap';
4
- import { listenForStateRequests } from './state';
5
-
6
- beforeEach(() => {
7
- store.clear();
8
- });
9
-
10
- describe('listenForUserAttributeRequests', () => {
11
- let currentState: any;
12
- beforeEach(() => {
13
- listenForAllEvents(AmediaUserEvents.ON_STATE_UPDATED, (evt) => {
14
- currentState = evt.detail;
15
- });
16
- listenForStateRequests();
17
- });
18
-
19
- describe('when empty initial state', () => {
20
- beforeEach(() => {
21
- dispatch(new CustomEvent(AmediaUserEvents.REQUEST_STATE));
22
- });
23
- it('should not return empty state', () => {
24
- expect(currentState).toBeUndefined();
25
- });
26
- });
27
-
28
- describe('with initial state', () => {
29
- beforeEach(() => {
30
- store.set('state', { isLoggedIn: false });
31
- dispatch(new CustomEvent(AmediaUserEvents.REQUEST_STATE));
32
- });
33
- it('should return expected state', () => {
34
- expect(currentState).toEqual({ isLoggedIn: false });
35
- });
36
- describe('when state changes', () => {
37
- beforeEach(() => {
38
- store.merge('state', { emergencyMode: ['aid'] });
39
- });
40
- it('should have updated state', () => {
41
- expect(currentState).toEqual({
42
- isLoggedIn: false,
43
- emergencyMode: ['aid'],
44
- });
45
- });
46
- });
47
- });
48
- });
@@ -1,23 +0,0 @@
1
- import { dispatch, listenWithExclusivity } from '../utils/customEventWrapper';
2
- import store from '../store';
3
- import { AmediaUserEvents } from './eventMap';
4
-
5
- export const listenForStateRequests = () => {
6
- listenWithExclusivity(AmediaUserEvents.REQUEST_STATE, () => {
7
- const state = store.get('state');
8
- if (state && Object.keys(state).length > 0) {
9
- dispatch(
10
- new CustomEvent(AmediaUserEvents.ON_STATE_UPDATED, {
11
- detail: state,
12
- })
13
- );
14
- }
15
- store.on('state', (updatedState) => {
16
- dispatch(
17
- new CustomEvent(AmediaUserEvents.ON_STATE_UPDATED, {
18
- detail: updatedState,
19
- })
20
- );
21
- });
22
- });
23
- };
@@ -1,114 +0,0 @@
1
- import { dispatch, listenForAllEvents } from '../utils/customEventWrapper';
2
- import * as userData from '../actions/userData';
3
- import * as storage from '../actions/storage';
4
- import store from '../store';
5
- import { listenForStorageRequests } from './storage';
6
- import { AmediaUserEvents } from './eventMap';
7
-
8
- beforeEach(() => {
9
- store.clear();
10
- });
11
-
12
- describe('listenForStorageRequests', () => {
13
- let currentStorage: any;
14
- beforeEach(() => {
15
- listenForAllEvents(AmediaUserEvents.ON_STORAGE_UPDATED, (evt) => {
16
- currentStorage = evt.detail;
17
- });
18
- listenForStorageRequests();
19
- jest
20
- .spyOn(userData, 'requestAttributes')
21
- .mockReturnValue(Promise.resolve());
22
- jest.spyOn(storage, 'requestStorage').mockReturnValue();
23
- });
24
-
25
- describe('AmediaUserEvents.REQUEST_STORAGE_NAMESPACES received', () => {
26
- beforeEach(() => {
27
- store.set('state', { isLoggedIn: true });
28
- });
29
-
30
- describe('no previous namespaces', () => {
31
- beforeEach(() => {
32
- dispatch(
33
- new CustomEvent(AmediaUserEvents.REQUEST_STORAGE_NAMESPACES, {
34
- detail: ['privacy_preferences', 'euucp', 'favorite_teams'],
35
- })
36
- );
37
- });
38
- it('calls requestAttributes with requested attributes', () => {
39
- expect(storage.requestStorage).toHaveBeenCalledWith([
40
- 'privacy_preferences',
41
- 'euucp',
42
- 'favorite_teams',
43
- ]);
44
- });
45
- it('does not receive a storage event', () => {
46
- expect(currentStorage).toBeUndefined();
47
- });
48
- });
49
-
50
- describe('with some namespaces', () => {
51
- beforeEach(() => {
52
- store.set('storage', {
53
- favorite_teams: { stabaek: true, sf: true },
54
- });
55
- dispatch(
56
- new CustomEvent(AmediaUserEvents.REQUEST_STORAGE_NAMESPACES, {
57
- detail: ['privacy_preferences', 'euucp', 'favorite_teams'],
58
- })
59
- );
60
- });
61
- it('calls requestStorage with only namespaces we did not already have', () => {
62
- expect(storage.requestStorage).toHaveBeenCalledWith([
63
- 'privacy_preferences',
64
- 'euucp',
65
- ]);
66
- });
67
- it('receives initial event with previous namespaces', () => {
68
- expect(currentStorage).toEqual({
69
- favorite_teams: { stabaek: true, sf: true },
70
- });
71
- });
72
- });
73
-
74
- describe('with previous state and all attributes', () => {
75
- beforeEach(() => {
76
- store.set('storage', {
77
- favorite_teams: { stabaek: true, sf: true },
78
- privacy_preferences: { ads: true, tracking: true },
79
- euucp: { what_is: 'this' },
80
- });
81
- dispatch(
82
- new CustomEvent(AmediaUserEvents.REQUEST_STORAGE_NAMESPACES, {
83
- detail: ['privacy_preferences', 'euucp', 'favorite_teams'],
84
- })
85
- );
86
- });
87
- it('does not call requestAttributes', () => {
88
- expect(storage.requestStorage).not.toHaveBeenCalled();
89
- });
90
- it('receives initial event with all namespaces', () => {
91
- expect(currentStorage).toEqual({
92
- favorite_teams: { stabaek: true, sf: true },
93
- privacy_preferences: { ads: true, tracking: true },
94
- euucp: { what_is: 'this' },
95
- });
96
- });
97
- });
98
-
99
- describe('when is not logged in', () => {
100
- beforeEach(() => {
101
- store.set('state', { isLoggedIn: false });
102
- dispatch(
103
- new CustomEvent(AmediaUserEvents.REQUEST_STORAGE_NAMESPACES, {
104
- detail: ['privacy_preferences', 'euucp', 'favorite_teams'],
105
- })
106
- );
107
- });
108
-
109
- it('does not call requestAttributes', () => {
110
- expect(storage.requestStorage).not.toHaveBeenCalled();
111
- });
112
- });
113
- });
114
- });
@@ -1,45 +0,0 @@
1
- import store from '../store';
2
- import { dispatch, listenWithExclusivity } from '../utils/customEventWrapper';
3
- import { AmediaUserEvents } from './eventMap';
4
- import { requestStorage, saveStorage, updateStorage } from '../actions/storage';
5
- import { whenIsLoggedIn } from '../utils/loginState';
6
-
7
- export const listenForStorageRequests = () => {
8
- store.on('storage', (storage) => {
9
- dispatch(
10
- new CustomEvent(AmediaUserEvents.ON_STORAGE_UPDATED, { detail: storage })
11
- );
12
- });
13
-
14
- listenWithExclusivity(AmediaUserEvents.REQUEST_STORAGE_NAMESPACES, (evt) => {
15
- whenIsLoggedIn().then(() => {
16
- const requestedNamespaces = evt.detail;
17
- const currentStorage = store.get('storage') || {};
18
- if (Object.keys(currentStorage).length > 0) {
19
- dispatch(
20
- new CustomEvent(AmediaUserEvents.ON_STORAGE_UPDATED, {
21
- detail: currentStorage,
22
- })
23
- );
24
- }
25
- const missingNamespaces = requestedNamespaces.filter(
26
- (namespace) => currentStorage[namespace] === undefined
27
- );
28
- if (missingNamespaces.length > 0) {
29
- requestStorage(missingNamespaces);
30
- }
31
- });
32
- });
33
-
34
- listenWithExclusivity(AmediaUserEvents.UPDATE_STORAGE, (evt) => {
35
- whenIsLoggedIn().then(() => {
36
- updateStorage(evt.detail);
37
- });
38
- });
39
-
40
- listenWithExclusivity(AmediaUserEvents.SAVE_STORAGE, (evt) => {
41
- whenIsLoggedIn().then(() => {
42
- saveStorage(evt.detail);
43
- });
44
- });
45
- };
@@ -1,93 +0,0 @@
1
- import { dispatch, listenForAllEvents } from '../utils/customEventWrapper';
2
- import { listenForUserAttributeRequests } from './userAttributes';
3
- import * as userData from '../actions/userData';
4
- import store from '../store';
5
- import { AmediaUserEvents } from './eventMap';
6
-
7
- beforeEach(() => {
8
- store.clear();
9
- });
10
-
11
- describe('listenForUserAttributeRequests', () => {
12
- let currentAttributes: any;
13
- beforeEach(() => {
14
- listenForAllEvents(AmediaUserEvents.ON_ATTRIBUTES_UPDATED, (evt) => {
15
- currentAttributes = evt.detail;
16
- });
17
- listenForUserAttributeRequests();
18
- jest
19
- .spyOn(userData, 'requestAttributes')
20
- .mockReturnValue(Promise.resolve());
21
- });
22
-
23
- describe('AmediaUserEvents.REQUEST_USER_ATTRIBUTES received', () => {
24
- describe('no previous attributes', () => {
25
- beforeEach(() => {
26
- dispatch(
27
- new CustomEvent(AmediaUserEvents.REQUEST_USER_ATTRIBUTES, {
28
- detail: ['uuid', 'name', 'email'],
29
- })
30
- );
31
- });
32
- it('calls requestAttributes with requested attributes', () => {
33
- expect(userData.requestAttributes).toHaveBeenCalledWith([
34
- 'uuid',
35
- 'name',
36
- 'email',
37
- ]);
38
- });
39
- it('does not receive an attribute event', () => {
40
- expect(currentAttributes).toBeUndefined();
41
- });
42
- });
43
-
44
- describe('with some attributes present already', () => {
45
- beforeEach(() => {
46
- store.set('userAttributes', {
47
- uuid: 'someuuid',
48
- });
49
- dispatch(
50
- new CustomEvent(AmediaUserEvents.REQUEST_USER_ATTRIBUTES, {
51
- detail: ['uuid', 'name', 'email'],
52
- })
53
- );
54
- });
55
- it('calls requestAttributes with only attributes we did not already know the value of', () => {
56
- expect(userData.requestAttributes).toHaveBeenCalledWith([
57
- 'name',
58
- 'email',
59
- ]);
60
- });
61
- it('receives initial event with previous attributes', () => {
62
- expect(currentAttributes).toEqual({
63
- uuid: 'someuuid',
64
- });
65
- });
66
- });
67
-
68
- describe('with all attributes present already', () => {
69
- beforeEach(() => {
70
- store.set('userAttributes', {
71
- uuid: 'someuuid',
72
- name: 'Some Name',
73
- email: 'some@where.com',
74
- });
75
- dispatch(
76
- new CustomEvent(AmediaUserEvents.REQUEST_USER_ATTRIBUTES, {
77
- detail: ['uuid', 'name', 'email'],
78
- })
79
- );
80
- });
81
- it('does not call requestAttributes', () => {
82
- expect(userData.requestAttributes).not.toHaveBeenCalled();
83
- });
84
- it('receives initial event with all attributes', () => {
85
- expect(currentAttributes).toEqual({
86
- uuid: 'someuuid',
87
- name: 'Some Name',
88
- email: 'some@where.com',
89
- });
90
- });
91
- });
92
- });
93
- });
@@ -1,31 +0,0 @@
1
- import { requestAttributes } from '../actions/userData';
2
- import { dispatch, listenWithExclusivity } from '../utils/customEventWrapper';
3
- import store from '../store';
4
- import { AmediaUserEvents } from './eventMap';
5
-
6
- export const listenForUserAttributeRequests = () => {
7
- store.on('userAttributes', (user) => {
8
- dispatch(
9
- new CustomEvent(AmediaUserEvents.ON_ATTRIBUTES_UPDATED, {
10
- detail: user,
11
- })
12
- );
13
- });
14
- listenWithExclusivity(AmediaUserEvents.REQUEST_USER_ATTRIBUTES, (evt) => {
15
- const requestedAttributes = evt.detail;
16
- const currentAttributes = store.get('userAttributes') || {};
17
- if (Object.keys(currentAttributes).length > 0) {
18
- dispatch(
19
- new CustomEvent(AmediaUserEvents.ON_ATTRIBUTES_UPDATED, {
20
- detail: currentAttributes,
21
- })
22
- );
23
- }
24
- const missingAttributes = requestedAttributes.filter(
25
- (attribute) => currentAttributes[attribute] === undefined
26
- );
27
- if (missingAttributes.length > 0) {
28
- requestAttributes(missingAttributes);
29
- }
30
- });
31
- };
@@ -1,8 +0,0 @@
1
- export default class FetchTimeoutError extends Error {
2
- partialData: Record<string, object>;
3
-
4
- constructor(message: string, partialData: Record<string, object>) {
5
- super(message);
6
- this.partialData = partialData;
7
- }
8
- }
@@ -1,16 +0,0 @@
1
- class PaywallError extends Error {
2
- static ERROR_RELOADED_NO_ACCESS = 'RELOADED_NO_ACCESS';
3
-
4
- static ERROR_ENABLING_ACCESS_FAILED = 'ENABLING_ACCESS_FAILED';
5
-
6
- static ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES =
7
- 'NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES';
8
-
9
- public code: string;
10
-
11
- constructor(message: string, code: string) {
12
- super(message);
13
- this.code = code;
14
- }
15
- }
16
- export default PaywallError;