@internetarchive/ia-book-actions 0.0.8 → 0.0.10-2
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": "@internetarchive/ia-book-actions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10-2",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"@internetarchive/local-cache": "^0.2.0",
|
|
26
26
|
"@internetarchive/modal-manager": "^0.1.0",
|
|
27
27
|
"@internetarchive/shared-resize-observer": "^0.0.1",
|
|
28
|
+
"js-cookie": "^2.2.1",
|
|
28
29
|
"lit-element": "^2.4.0",
|
|
29
30
|
"lit-html": "^1.3.0"
|
|
30
31
|
},
|
|
@@ -13,7 +13,7 @@ export class InfoIcon extends LitElement {
|
|
|
13
13
|
super();
|
|
14
14
|
this.iconClass = '';
|
|
15
15
|
this.helpURL =
|
|
16
|
-
'https://help.archive.org/
|
|
16
|
+
'https://help.archive.org/help/borrowing-from-the-lending-library';
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
render() {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { LitElement } from 'lit-element';
|
|
2
|
-
import { LocalCache } from '@internetarchive/local-cache';
|
|
3
2
|
|
|
4
3
|
import { URLHelper } from '../../config/url-helper.js';
|
|
5
4
|
import ActionsHandlerService from './actions-handler-service.js';
|
|
5
|
+
import 'js-cookie';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* These are callback functions calling from actions-config.js file.
|
|
@@ -17,7 +17,6 @@ export default class ActionsHandler extends LitElement {
|
|
|
17
17
|
super();
|
|
18
18
|
this.identifier = identifier;
|
|
19
19
|
this.ajaxTimeout = 6000;
|
|
20
|
-
this.localCache = new LocalCache();
|
|
21
20
|
this.bindEvents();
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -242,21 +241,22 @@ export default class ActionsHandler extends LitElement {
|
|
|
242
241
|
try {
|
|
243
242
|
let newCount = 1;
|
|
244
243
|
const storageKey = `loan-count-${this.identifier}`;
|
|
245
|
-
|
|
244
|
+
/* eslint-disable no-undef */
|
|
245
|
+
const existingCount = Cookies.get(storageKey);
|
|
246
246
|
|
|
247
247
|
// increase browse-count by 1 when you consecutive reading a book.
|
|
248
248
|
if (action === 'browseAgain' && existingCount !== undefined) {
|
|
249
|
-
newCount = existingCount ? existingCount + 1 : 1;
|
|
249
|
+
newCount = existingCount ? Number(existingCount) + 1 : 1;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
const date = new Date();
|
|
253
|
+
date.setHours(date.getHours() + 2);
|
|
254
|
+
|
|
252
255
|
// set new value
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
value: newCount,
|
|
256
|
-
ttl: 7200, // 2 hours
|
|
257
|
-
});
|
|
256
|
+
/* eslint-disable no-undef */
|
|
257
|
+
Cookies.set(storageKey, newCount, { expires: date, path: '/' });
|
|
258
258
|
} catch (error) {
|
|
259
|
-
|
|
259
|
+
this.sendEvent('Cookies-Error-Actions', error);
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LocalCache } from '@internetarchive/local-cache';
|
|
2
1
|
import ActionsHandlerService from './actions-handler/actions-handler-service.js';
|
|
2
|
+
import 'js-cookie';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* This class is used to create loan token for borrowed books
|
|
@@ -15,7 +15,6 @@ export class LoanTokenPoller {
|
|
|
15
15
|
this.pollerDelay = pollerDelay; // value in ms (1000 ms = 1 sec)
|
|
16
16
|
|
|
17
17
|
this.loanTokenInterval = undefined;
|
|
18
|
-
this.localCache = new LocalCache();
|
|
19
18
|
this.enableBookAccess();
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -31,12 +30,11 @@ export class LoanTokenPoller {
|
|
|
31
30
|
// send consecutiveLoanCounts for browsed books only.
|
|
32
31
|
if (this.borrowType === 'browsed') {
|
|
33
32
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
33
|
+
/* eslint-disable no-undef */
|
|
34
|
+
const existingCount = Cookies.get(`loan-count-${this.identifier}`);
|
|
37
35
|
consecutiveLoanCounts = existingCount ?? 1;
|
|
38
36
|
} catch (error) {
|
|
39
|
-
|
|
37
|
+
this.sendEvent('Cookies-Error-Token', error);
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
|
package/src/ia-book-actions.js
CHANGED
|
@@ -162,39 +162,13 @@ export default class IABookActions extends LitElement {
|
|
|
162
162
|
this.startBrowseTimer();
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
* it takes 5 params
|
|
170
|
-
* 1. this.identifier
|
|
171
|
-
* 2. this.borrowType
|
|
172
|
-
* 3. successCallback - it used to
|
|
173
|
-
* - disptach lendingFlow::PostInit event
|
|
174
|
-
* - initialize bookreader using br.init()
|
|
175
|
-
* 4. errorCallback
|
|
176
|
-
* 5. tokenPollerDelay
|
|
177
|
-
*/
|
|
178
|
-
if (this.barType === 'action') {
|
|
179
|
-
if (this.tokenPoller) {
|
|
180
|
-
this.tokenPoller.disconnectedInterval();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const successCallback = () => {
|
|
184
|
-
this.lendingBarPostInit();
|
|
185
|
-
};
|
|
186
|
-
const errorCallback = eventObj => {
|
|
187
|
-
this.handleLendingActionError(eventObj);
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
this.tokenPoller = new LoanTokenPoller(
|
|
191
|
-
this.identifier,
|
|
192
|
-
this.borrowType,
|
|
193
|
-
successCallback,
|
|
194
|
-
errorCallback,
|
|
195
|
-
this.tokenDelay // 1000 ms = 1 sec
|
|
196
|
-
);
|
|
165
|
+
// early return if not borrowed or no action-bar
|
|
166
|
+
if (!this.borrowType || this.barType === 'title') {
|
|
167
|
+
this.lendingBarPostInit();
|
|
168
|
+
return;
|
|
197
169
|
}
|
|
170
|
+
|
|
171
|
+
this.startLoanTokenPoller();
|
|
198
172
|
}
|
|
199
173
|
|
|
200
174
|
render() {
|
|
@@ -236,6 +210,40 @@ export default class IABookActions extends LitElement {
|
|
|
236
210
|
`;
|
|
237
211
|
}
|
|
238
212
|
|
|
213
|
+
/**
|
|
214
|
+
* enable access of borrowed/browsed books
|
|
215
|
+
*/
|
|
216
|
+
startLoanTokenPoller() {
|
|
217
|
+
if (this.tokenPoller) {
|
|
218
|
+
this.tokenPoller.disconnectedInterval();
|
|
219
|
+
}
|
|
220
|
+
const successCallback = () => {
|
|
221
|
+
this.lendingBarPostInit();
|
|
222
|
+
};
|
|
223
|
+
const errorCallback = eventObj => {
|
|
224
|
+
this.handleLendingActionError(eventObj);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* LoanTokenPoller is a class that polls the loan token
|
|
229
|
+
* it takes 5 params
|
|
230
|
+
* 1. this.identifier
|
|
231
|
+
* 2. this.borrowType
|
|
232
|
+
* 3. successCallback - it used to
|
|
233
|
+
* - disptach lendingFlow::PostInit event
|
|
234
|
+
* - initialize bookreader using br.init()
|
|
235
|
+
* 4. errorCallback
|
|
236
|
+
* 5. tokenPollerDelay
|
|
237
|
+
*/
|
|
238
|
+
this.tokenPoller = new LoanTokenPoller(
|
|
239
|
+
this.identifier,
|
|
240
|
+
this.borrowType,
|
|
241
|
+
successCallback,
|
|
242
|
+
errorCallback,
|
|
243
|
+
this.tokenDelay // 1000 ms = 1 sec
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
239
247
|
/*
|
|
240
248
|
* custom event handler to toggle action group visibility
|
|
241
249
|
*
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { expect } from '@open-wc/testing';
|
|
2
2
|
import Sinon from 'sinon';
|
|
3
3
|
|
|
4
|
-
import { LocalCache } from '@internetarchive/local-cache';
|
|
4
|
+
// import { LocalCache } from '@internetarchive/local-cache';
|
|
5
5
|
import { LoanTokenPoller } from '../../../src/core/services/loan-token-poller.js';
|
|
6
6
|
|
|
7
7
|
describe('Get Loan Token', () => {
|
|
8
8
|
it('get loan token for browsed books', async () => {
|
|
9
|
-
const localCacheStub = new LocalCache();
|
|
10
|
-
const localCacheGetSpy = Sinon.spy(localCacheStub, 'get');
|
|
9
|
+
// const localCacheStub = new LocalCache();
|
|
10
|
+
// const localCacheGetSpy = Sinon.spy(localCacheStub, 'get');
|
|
11
11
|
|
|
12
12
|
const tokenPoller = new LoanTokenPoller(
|
|
13
13
|
'identifier1',
|
|
@@ -24,14 +24,14 @@ describe('Get Loan Token', () => {
|
|
|
24
24
|
successCallbackSpy();
|
|
25
25
|
expect(successCallbackSpy.callCount).to.equal(1);
|
|
26
26
|
|
|
27
|
-
localCacheGetSpy();
|
|
28
|
-
expect(localCacheGetSpy.callCount).to.equal(1);
|
|
27
|
+
// localCacheGetSpy();
|
|
28
|
+
// expect(localCacheGetSpy.callCount).to.equal(1);
|
|
29
29
|
|
|
30
|
-
expect(tokenPoller.localCache.namespace).to.equal('LocalCache');
|
|
31
|
-
expect(tokenPoller.localCache.get).to.be.a('function');
|
|
30
|
+
// expect(tokenPoller.localCache.namespace).to.equal('LocalCache');
|
|
31
|
+
// expect(tokenPoller.localCache.get).to.be.a('function');
|
|
32
32
|
|
|
33
|
-
tokenPoller.disconnectedInterval(); // clear token poller interval
|
|
34
|
-
expect(tokenPoller.loanTokenInterval).to.equal(undefined);
|
|
33
|
+
// tokenPoller.disconnectedInterval(); // clear token poller interval
|
|
34
|
+
// expect(tokenPoller.loanTokenInterval).to.equal(undefined);
|
|
35
35
|
|
|
36
36
|
tokenPoller.handleLoanTokenPoller(true);
|
|
37
37
|
expect(tokenPoller.errorCallback).to.be.a('function');
|