@internetarchive/ia-book-actions 0.1.6-alpha1 → 0.1.7

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/demo/index.html CHANGED
@@ -131,9 +131,9 @@
131
131
  iaBookActions.returnUrl = '';
132
132
  iaBookActions.localCache = localCache;
133
133
 
134
- let loanTotalTime2Min = { loanTotalTime: 10, loanRenewAtLast: 5, pageChangedInLast: 5 };
134
+ let loanTotalTime2Min = { loanTotalTime: 65, loanRenewAtLast: 60, pageChangedInLast: 15 };
135
135
  let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
- let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 600, pageChangedInLast: 900 };
136
+ let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 660, pageChangedInLast: 900 };
137
137
 
138
138
  iaBookActions.loanRenewTimeConfig = loanTotalTime2Min;
139
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.1.6-alpha1",
3
+ "version": "0.1.7",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -9,10 +9,6 @@ import CollapsibleActionGroupStyle from '../assets/styles/collapsible-action-gro
9
9
 
10
10
  import { tabletContainerWidth } from '../core/config/constants.js';
11
11
  import { purchaseIcon } from '../assets/data/purchase.js';
12
- import {
13
- analyticsCategories,
14
- analyticsActions,
15
- } from '../core/config/analytics-event-and-category.js';
16
12
  import {
17
13
  dropdownOpened,
18
14
  dropdownClosed,
@@ -76,27 +72,14 @@ export class CollapsibleActionGroup extends ActionsHandler {
76
72
 
77
73
  /**
78
74
  * dispatch event when book is auto renewed / returned
79
- * listen these events in action-handler.js
75
+ * listen these events in action-handler.js to execute ajax call on petabox.
80
76
  * @see ActionsHandler
81
77
  *
82
78
  * @param {string} event - autoRenew|autoReturn
83
79
  * @memberof CollapsibleActionGroup
84
80
  */
85
81
  dispatchLoanEvent(event) {
86
- const category = analyticsCategories.browse;
87
- const action =
88
- event === 'autoRenew'
89
- ? analyticsActions.browseAutoRenew
90
- : analyticsActions.browseAutoReturn;
91
-
92
- // listen in action-handler.js to execute ajax call on petabox.
93
- this.dispatchEvent(
94
- new CustomEvent(event, {
95
- detail: {
96
- event: { category, action },
97
- },
98
- })
99
- );
82
+ this.dispatchEvent(new Event(event));
100
83
  }
101
84
 
102
85
  /**
@@ -74,7 +74,7 @@ export default class TimerCountdown extends LitElement {
74
74
  secondsLeft -= this.timerExecutionSeconds;
75
75
  secondsLeft = Math.round(secondsLeft); // round number
76
76
 
77
- // re-sync timer is gone off
77
+ // re-sync timer if gone off because of background window
78
78
  await this.reSyncTimerIfGoneOff(secondsLeft);
79
79
 
80
80
  /**
@@ -5,8 +5,7 @@ export const sentryLogs = {
5
5
  disconnectedCallback: 'IABookActions:disconnectedCallback',
6
6
  bookHasRenewed:
7
7
  'IABookActions:handleLoanAutoRenewed - book has renewed for next one hour',
8
- bookRenewFailed:
9
- 'IABookActions:handleLoanRenewNow - failed to renew',
8
+ bookRenewFailed: 'IABookActions:handleLoanRenewNow - failed to renew',
10
9
  browseHasExpired:
11
10
  'IABookActions:browseHasExpired - one-hour loan has been expired',
12
11
  bookWasExpired:
@@ -47,6 +47,12 @@ export default async function ActionsHandlerService(options) {
47
47
 
48
48
  // return success response for /demo/ server...
49
49
  if (baseHost == '/demo/1' || baseHost == '/demo/') {
50
+ if (option?.action == 'renew_loan') {
51
+ return {
52
+ success: true,
53
+ loan: { renewal: true },
54
+ };
55
+ }
50
56
  return {
51
57
  success: true,
52
58
  message: 'operation executed successfully!',
@@ -54,7 +54,7 @@ export default class ActionsHandler extends LitElement {
54
54
  });
55
55
 
56
56
  this.addEventListener('autoReturn', () => {
57
- this.deleteLoanCookies();
57
+ this.handleReturnIt();
58
58
  this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'autoreturn');
59
59
  });
60
60
 
@@ -64,7 +64,7 @@ export default class ActionsHandler extends LitElement {
64
64
  this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'return');
65
65
  }
66
66
 
67
- this.handleReturnIt();
67
+ this.handleReturnIt('returnNow');
68
68
 
69
69
  // send these events if 14-day borrow return
70
70
  if (detail?.borrowType === 'borrow') {
@@ -161,16 +161,23 @@ export default class ActionsHandler extends LitElement {
161
161
  });
162
162
  }
163
163
 
164
- handleReturnIt() {
164
+ /**
165
+ * excute function when loan is returning
166
+ *
167
+ * @param {string} type - loan return type returnNow|''
168
+ */
169
+ handleReturnIt(type = '') {
165
170
  const action = 'return_loan';
166
- this.dispatchToggleActionGroup();
171
+
172
+ if (type === 'returnNow') this.dispatchToggleActionGroup();
167
173
 
168
174
  ActionsHandlerService({
169
175
  action,
170
176
  identifier: this.identifier,
171
177
  success: () => {
172
178
  this.deleteLoanCookies();
173
- URLHelper.goToUrl(this.returnUrl, true);
179
+
180
+ if (type === 'returnNow') URLHelper.goToUrl(this.returnUrl, true);
174
181
  },
175
182
  error: data => {
176
183
  this.dispatchActionError(action, data);
@@ -40,7 +40,7 @@ import ActionsConfig from './actions-config.js';
40
40
  * @enum {string}
41
41
  */
42
42
  export const bookTitles = {
43
- available_1hr: '',
43
+ available_1hr: 'Renews each hour as long as pages are turned.',
44
44
  available_14d: 'This book can be borrowed for 14 days.',
45
45
  available_pd: 'Book available to patrons with print disabilities.',
46
46
  available_waitlist: 'A waitlist is available.',
@@ -98,7 +98,8 @@ export class GetLendingActions {
98
98
  let isBrowsing =
99
99
  lendingStatus.user_has_browsed && !lendingStatus.browsingExpired;
100
100
  if (isBrowsing) {
101
- primaryTitleText = '';
101
+ primaryTitleText =
102
+ 'Returns automatically after 25 minutes of inactivity.';
102
103
  } else {
103
104
  primaryTitleText = `Your loan of this book has ${lendingStatus.daysLeftOnLoan} days left.`;
104
105
  }
@@ -301,16 +301,28 @@ export default class IABookActions extends LitElement {
301
301
  console.log('** IABookActions:loanRenew', event.detail);
302
302
  await this.autoLoanRenewChecker(false);
303
303
 
304
- // renew in last seconds (let say 50 second) not possible because,
305
- // - very short to renew on datanodes by hitting petabox API
306
- // - loading images by create loan token
307
- if (event?.detail?.secondsLeft < 50) {
304
+ /**
305
+ * auto-renew is not possible in last seconds (let say 50 second) because,
306
+ * 1. less time to execute ajax call
307
+ * 2. less time to write loan on datanodes
308
+ * 3. less time to load images by create_token api
309
+ * so if seconds left is < 50, just expire the loan
310
+ */
311
+ let secondsLeft = event?.detail?.secondsLeft;
312
+ if (secondsLeft < 50) {
308
313
  this.suppressAutoRenew = true;
314
+ this.browseHasExpired();
309
315
  }
310
316
 
311
317
  // show warning message with remaining time to auto returned it.
312
318
  if (this.loanRenewResult.renewNow === false) {
313
- this.loanRenewResult.secondsLeft = event.detail.secondsLeft;
319
+ /**
320
+ * so compensate for the 50 second buffer to handle above race conditions
321
+ * let's reduce 1 min from warning texts and early return the book when 1 min left.
322
+ */
323
+ secondsLeft -= 60;
324
+
325
+ this.loanRenewResult.secondsLeft = secondsLeft;
314
326
  this.showToastMessage();
315
327
  }
316
328
  });
@@ -530,7 +542,6 @@ export default class IABookActions extends LitElement {
530
542
  * @param {object} event
531
543
  */
532
544
  async handleLoanAutoRenewed(event) {
533
- // TODO: just read DATA variable here to apply security { action, data }
534
545
  if (this.loanRenewResult.renewNow) {
535
546
  window?.IALendingIntervals?.clearAll();
536
547