@amedia/user 0.14.13 → 0.14.14
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amedia/user",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.14",
|
|
4
4
|
"description": "Client lib for working with aID user and associated data",
|
|
5
5
|
"repository": "https://github.com/amedia/amedia-user-js",
|
|
6
6
|
"author": "Amedia Utvikling (ID og data)",
|
|
@@ -44,6 +44,8 @@
|
|
|
44
44
|
"@types/dexie": "^1.3.1",
|
|
45
45
|
"@types/jest": "^26.0.24",
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^4.29.1",
|
|
47
|
+
"express": "^4.17.1",
|
|
48
|
+
"cors": "^2.8.5",
|
|
47
49
|
"esbuild": "^0.12.19",
|
|
48
50
|
"eslint": "^7.32.0",
|
|
49
51
|
"eslint-config-airbnb-typescript": "^12.3.1",
|
package/src/autologin/index.ts
CHANGED
|
@@ -70,7 +70,7 @@ const attemptAutologin = async (strategies: Strategies) => {
|
|
|
70
70
|
.then((shouldPerformAutoLogin) => {
|
|
71
71
|
if (shouldPerformAutoLogin) {
|
|
72
72
|
if (hasAlreadyAttemptedAutoLogin()) {
|
|
73
|
-
return
|
|
73
|
+
return false;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// Try to get newspaper cookie
|
|
@@ -85,19 +85,18 @@ const attemptAutologin = async (strategies: Strategies) => {
|
|
|
85
85
|
* and will in turn cause flickering and unnecessary (and often aborted) request to
|
|
86
86
|
* various backends.
|
|
87
87
|
*/
|
|
88
|
-
return new Promise(() => {});
|
|
88
|
+
return new Promise<boolean>(() => {});
|
|
89
89
|
}
|
|
90
|
-
return
|
|
90
|
+
return true;
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
if (!(await shouldTryMoreStrategies)) {
|
|
93
|
+
if (!shouldTryMoreStrategies) {
|
|
95
94
|
return;
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
};
|
|
99
98
|
|
|
100
|
-
export const attemptAutoLoginJob =
|
|
99
|
+
export const attemptAutoLoginJob = () =>
|
|
101
100
|
attemptAutologin([
|
|
102
101
|
{
|
|
103
102
|
name: 'third_party',
|
|
@@ -105,7 +104,7 @@ export const attemptAutoLoginJob = async () =>
|
|
|
105
104
|
},
|
|
106
105
|
]);
|
|
107
106
|
|
|
108
|
-
export const attemptPaywallAutoLogin =
|
|
107
|
+
export const attemptPaywallAutoLogin = () =>
|
|
109
108
|
attemptAutologin([
|
|
110
109
|
{
|
|
111
110
|
name: 'paywall',
|
|
@@ -218,9 +218,12 @@ describe('PaywallUnlocker', () => {
|
|
|
218
218
|
|
|
219
219
|
describe('with redirect requested', () => {
|
|
220
220
|
beforeEach(async () => {
|
|
221
|
-
|
|
221
|
+
new PaywallUnlockRequest()
|
|
222
222
|
.redirectOnAccess('https://redirect.pls')
|
|
223
|
-
.tryUnlock()
|
|
223
|
+
.tryUnlock()
|
|
224
|
+
.then((res) => {
|
|
225
|
+
unlockResponse = res;
|
|
226
|
+
});
|
|
224
227
|
});
|
|
225
228
|
|
|
226
229
|
it('should give access with access features', () => {
|
|
@@ -231,10 +234,19 @@ describe('PaywallUnlocker', () => {
|
|
|
231
234
|
});
|
|
232
235
|
});
|
|
233
236
|
|
|
234
|
-
it('should navigate to expected url', () => {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
237
|
+
it('should navigate to expected url', (done) => {
|
|
238
|
+
/**
|
|
239
|
+
* This is not great.
|
|
240
|
+
* Since tryUnlock performs some async actions and we, by design,
|
|
241
|
+
* don't want to resolve tryUnlock when navigating, we have to
|
|
242
|
+
* wait for the next event loop to check location.
|
|
243
|
+
*/
|
|
244
|
+
setTimeout(() => {
|
|
245
|
+
expect(location.replace).toHaveBeenCalledWith(
|
|
246
|
+
'https://redirect.pls'
|
|
247
|
+
);
|
|
248
|
+
done();
|
|
249
|
+
}, 0);
|
|
238
250
|
});
|
|
239
251
|
|
|
240
252
|
itShouldAttemptActivationWithAccessFeatures(['newspaper']);
|
|
@@ -243,9 +255,12 @@ describe('PaywallUnlocker', () => {
|
|
|
243
255
|
|
|
244
256
|
describe('with reload requested', () => {
|
|
245
257
|
beforeEach(async () => {
|
|
246
|
-
|
|
258
|
+
new PaywallUnlockRequest()
|
|
247
259
|
.reloadOnAccess()
|
|
248
|
-
.tryUnlock()
|
|
260
|
+
.tryUnlock()
|
|
261
|
+
.then((res) => {
|
|
262
|
+
unlockResponse = res;
|
|
263
|
+
});
|
|
249
264
|
});
|
|
250
265
|
|
|
251
266
|
it('should give access with access features', () => {
|
|
@@ -256,8 +271,11 @@ describe('PaywallUnlocker', () => {
|
|
|
256
271
|
});
|
|
257
272
|
});
|
|
258
273
|
|
|
259
|
-
it('should reload on access', () => {
|
|
260
|
-
|
|
274
|
+
it('should reload on access', (done) => {
|
|
275
|
+
setTimeout(() => {
|
|
276
|
+
expect(location.reload).toHaveBeenCalled();
|
|
277
|
+
done();
|
|
278
|
+
}, 0);
|
|
261
279
|
});
|
|
262
280
|
|
|
263
281
|
itShouldAttemptActivationWithAccessFeatures(['newspaper']);
|
|
@@ -134,6 +134,9 @@ class PaywallUnlockRequest {
|
|
|
134
134
|
if (this.requestedUrl) {
|
|
135
135
|
location.replace(this.requestedUrl);
|
|
136
136
|
}
|
|
137
|
+
|
|
138
|
+
// Don't resolve tryUnlock promise if we're being reloaded/navigated away
|
|
139
|
+
return new Promise(() => {});
|
|
137
140
|
}
|
|
138
141
|
return {
|
|
139
142
|
isLoggedIn: true,
|