@internetarchive/ia-book-actions 0.0.22 → 0.0.23-alpha1

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.22",
3
+ "version": "0.0.23-alpha1",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -93,7 +93,7 @@ export default css`
93
93
  }
94
94
  .open {
95
95
  display: block;
96
- z-index: 2;
96
+ z-index: 3;
97
97
  }
98
98
  .visible {
99
99
  display: inline-block;
@@ -86,6 +86,7 @@ export class GetLendingActions {
86
86
  primaryTitle: '',
87
87
  primaryActions: [],
88
88
  secondaryActions: [this.actionsConfig.adminOrPrintDisabledExitConfig()],
89
+ borrowType: 'adminBorrowed',
89
90
  };
90
91
  }
91
92
 
@@ -1,5 +1,8 @@
1
1
  import ActionsHandlerService from './actions-handler/actions-handler-service.js';
2
2
  import * as Cookies from './doc-cookies.js';
3
+ import {
4
+ analyticsCategories,
5
+ } from '../config/analytics-event-and-category.js';
3
6
 
4
7
  /**
5
8
  * This class is used to create loan token for borrowed books
@@ -13,6 +16,7 @@ export class LoanTokenPoller {
13
16
  this.successCallback = successCallback; // callback function to be called after loan token is created
14
17
  this.errorCallback = errorCallback; // callback function to be called after loan token is created
15
18
  this.pollerDelay = pollerDelay; // value in ms (1000 ms = 1 sec)
19
+ this.analyticsCategories = analyticsCategories;
16
20
 
17
21
  this.loanTokenInterval = undefined;
18
22
  this.enableBookAccess();
@@ -46,9 +50,14 @@ export class LoanTokenPoller {
46
50
  // Do an initial token, then set an interval
47
51
  this.handleLoanTokenPoller(true);
48
52
 
49
- this.loanTokenInterval = setInterval(() => {
50
- this.handleLoanTokenPoller();
51
- }, this.pollerDelay);
53
+ // if this.borrowType = adminBorrowed,
54
+ // - we don't want to fetch token on interval
55
+ // - the initial token is enough to set cookies for reading book and readaloud features
56
+ if (this.borrowType !== 'adminBorrowed') {
57
+ this.loanTokenInterval = setInterval(() => {
58
+ this.handleLoanTokenPoller();
59
+ }, this.pollerDelay);
60
+ }
52
61
 
53
62
  // event category and action for browsing book access
54
63
  const category = `${this.borrowType}BookAccess`;
@@ -64,13 +73,14 @@ export class LoanTokenPoller {
64
73
  }
65
74
  }
66
75
 
67
- sendEvent(eventCategory, eventAction) {
76
+ sendEvent(eventCategory, eventAction, extraParams = {}) {
68
77
  // eslint-disable-next-line no-console
69
- console?.log('Book action: ', { eventCategory, eventAction });
78
+ console?.log('Book action: ', { eventCategory, eventAction, extraParams });
70
79
  window?.archive_analytics?.send_event_no_sampling(
71
80
  eventCategory,
72
81
  eventAction,
73
- `identifier=${this.identifier}`
82
+ `identifier=${this.identifier}`,
83
+ extraParams
74
84
  );
75
85
  }
76
86
 
@@ -80,7 +90,19 @@ export class LoanTokenPoller {
80
90
  identifier: this.identifier,
81
91
  action,
82
92
  error: data => {
83
- window?.Sentry?.captureMessage('handleLoanTokenPoller error');
93
+ window?.Sentry?.captureMessage(`
94
+ handleLoanTokenPoller error, identifier:${this.identifier}, borrowType:${this.borrowType}, interval:${this.loanTokenInterval}
95
+ `);
96
+ this.sendEvent(
97
+ this.analyticsCategories.browse,
98
+ 'LoanTokenError',
99
+ {
100
+ 'identifier' : this.identifier,
101
+ 'isInitial' : isInitial,
102
+ 'borrowType' : this.borrowType,
103
+ 'interval' : this.loanTokenInterval,
104
+ }
105
+ );
84
106
  this.disconnectedInterval(); // stop token fetch api
85
107
  this.errorCallback({ detail: { action, data } });
86
108
  },
@@ -6,9 +6,6 @@ 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');
11
-
12
9
  const tokenPoller = new LoanTokenPoller(
13
10
  'identifier1',
14
11
  'browsed',
@@ -24,17 +21,26 @@ describe('Get Loan Token', () => {
24
21
  successCallbackSpy();
25
22
  expect(successCallbackSpy.callCount).to.equal(1);
26
23
 
27
- // localCacheGetSpy();
28
- // expect(localCacheGetSpy.callCount).to.equal(1);
29
-
30
- // expect(tokenPoller.localCache.namespace).to.equal('LocalCache');
31
- // expect(tokenPoller.localCache.get).to.be.a('function');
32
-
33
- // tokenPoller.disconnectedInterval(); // clear token poller interval
34
- // expect(tokenPoller.loanTokenInterval).to.equal(undefined);
35
-
36
24
  tokenPoller.handleLoanTokenPoller(true);
37
25
  expect(tokenPoller.errorCallback).to.be.a('function');
38
26
  expect(tokenPoller.successCallback).have;
39
27
  });
28
+
29
+ it('get loan token for admin borrowed books', async () => {
30
+ const tokenPoller = new LoanTokenPoller(
31
+ 'identifier1',
32
+ 'adminBorrowed',
33
+ () => {},
34
+ () => {},
35
+ 2000 // 2 minutes'
36
+ );
37
+
38
+ const successCallbackSpy = Sinon.stub(tokenPoller, 'successCallback');
39
+ successCallbackSpy();
40
+ expect(successCallbackSpy.callCount).to.equal(1);
41
+
42
+ // for adminBorrowed,
43
+ // - not initialize loanTokenInterval as don't need to fetch loan after specific interval
44
+ expect(tokenPoller.loanTokenInterval).to.equal(undefined);
45
+ });
40
46
  });