@internetarchive/ia-book-actions 0.0.22-4 → 0.0.23-alpha2

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-4",
3
+ "version": "0.0.23-alpha2",
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;
@@ -36,7 +36,6 @@ export default async function ActionsHandlerService(options) {
36
36
  body: formData,
37
37
  })
38
38
  .then(response => {
39
- // return {error: 'not logged in'}
40
39
  // intentional error on localhost
41
40
  if (shouldReturnError && erroneousActions.includes(option?.action)) {
42
41
  return {
@@ -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
  },
@@ -297,9 +297,6 @@ export default class IABookActions extends LitElement {
297
297
  const action = event?.detail?.action;
298
298
  const errorMsg = event?.detail?.data?.error;
299
299
 
300
- console.log('event', event)
301
- console.log('action', action)
302
- console.log('errorMsg', errorMsg)
303
300
  if (errorMsg) this.showErrorModal(errorMsg, action);
304
301
 
305
302
  // update action bar state if book is not available to browse or borrow.
@@ -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
  });