@internetarchive/ia-book-actions 0.0.10 → 0.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
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
  },
@@ -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
- const existingCount = await this.localCache.get(storageKey);
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
- await this.localCache.set({
254
- key: storageKey,
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
- console.log(error);
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
- const existingCount = await this.localCache.get(
35
- `loan-count-${this.identifier}`
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
- console.log(error);
37
+ this.sendEvent('Cookies-Error-Token', error);
40
38
  }
41
39
  }
42
40
 
@@ -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');