@internetarchive/ia-book-actions 0.0.22-3 → 0.0.23-1

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",
3
+ "version": "0.0.23-1",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -20,9 +20,9 @@
20
20
  "dependencies": {
21
21
  "@internetarchive/icon-info": "^1.2.6",
22
22
  "@internetarchive/local-cache": "^0.2.0",
23
- "@internetarchive/modal-manager": "^0.2.2",
23
+ "@internetarchive/modal-manager": "^0.2.1",
24
24
  "@internetarchive/shared-resize-observer": "^0.2.0",
25
- "lit": "^2.2.2"
25
+ "lit": "^2.2.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@open-wc/eslint-config": "^4.2.0",
@@ -93,7 +93,7 @@ export default css`
93
93
  }
94
94
  .open {
95
95
  display: block;
96
- z-index: 2;
96
+ z-index: 4;
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,6 @@
1
1
  import ActionsHandlerService from './actions-handler/actions-handler-service.js';
2
2
  import * as Cookies from './doc-cookies.js';
3
+ import { analyticsCategories } from '../config/analytics-event-and-category.js';
3
4
 
4
5
  /**
5
6
  * This class is used to create loan token for borrowed books
@@ -13,6 +14,7 @@ export class LoanTokenPoller {
13
14
  this.successCallback = successCallback; // callback function to be called after loan token is created
14
15
  this.errorCallback = errorCallback; // callback function to be called after loan token is created
15
16
  this.pollerDelay = pollerDelay; // value in ms (1000 ms = 1 sec)
17
+ this.analyticsCategories = analyticsCategories;
16
18
 
17
19
  this.loanTokenInterval = undefined;
18
20
  this.enableBookAccess();
@@ -46,9 +48,14 @@ export class LoanTokenPoller {
46
48
  // Do an initial token, then set an interval
47
49
  this.handleLoanTokenPoller(true);
48
50
 
49
- this.loanTokenInterval = setInterval(() => {
50
- this.handleLoanTokenPoller();
51
- }, this.pollerDelay);
51
+ // if this.borrowType = adminBorrowed,
52
+ // - we don't want to fetch token on interval
53
+ // - the initial token is enough to set cookies for reading book and readaloud features
54
+ if (this.borrowType !== 'adminBorrowed') {
55
+ this.loanTokenInterval = setInterval(() => {
56
+ this.handleLoanTokenPoller();
57
+ }, this.pollerDelay);
58
+ }
52
59
 
53
60
  // event category and action for browsing book access
54
61
  const category = `${this.borrowType}BookAccess`;
@@ -64,13 +71,14 @@ export class LoanTokenPoller {
64
71
  }
65
72
  }
66
73
 
67
- sendEvent(eventCategory, eventAction) {
74
+ sendEvent(eventCategory, eventAction, extraParams = {}) {
68
75
  // eslint-disable-next-line no-console
69
- console?.log('Book action: ', { eventCategory, eventAction });
76
+ console?.log('Book action: ', { eventCategory, eventAction, extraParams });
70
77
  window?.archive_analytics?.send_event_no_sampling(
71
78
  eventCategory,
72
79
  eventAction,
73
- `identifier=${this.identifier}`
80
+ `identifier=${this.identifier}`,
81
+ extraParams
74
82
  );
75
83
  }
76
84
 
@@ -80,7 +88,15 @@ export class LoanTokenPoller {
80
88
  identifier: this.identifier,
81
89
  action,
82
90
  error: data => {
83
- window?.Sentry?.captureMessage('handleLoanTokenPoller error');
91
+ window?.Sentry?.captureMessage(`
92
+ handleLoanTokenPoller error, identifier:${this.identifier}, borrowType:${this.borrowType}, interval:${this.loanTokenInterval}
93
+ `);
94
+ this.sendEvent(this.analyticsCategories.browse, 'LoanTokenError', {
95
+ identifier: this.identifier,
96
+ isInitial: isInitial,
97
+ borrowType: this.borrowType,
98
+ interval: this.loanTokenInterval,
99
+ });
84
100
  this.disconnectedInterval(); // stop token fetch api
85
101
  this.errorCallback({ detail: { action, data } });
86
102
  },
@@ -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
  });