@internetarchive/ia-book-actions 0.1.5-alpha1 → 0.1.5-alpha3

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
@@ -128,11 +128,11 @@
128
128
  iaBookActions.modalConfig = modalConfig;
129
129
  iaBookActions.lendingBarPostInit = lendingBarPostInit;
130
130
  iaBookActions.tokenDelay = 2; // 2 seconds
131
- iaBookActions.returnUrl = 'https://openlibrary.org';
131
+ iaBookActions.returnUrl = '';
132
132
  iaBookActions.localCache = localCache;
133
133
 
134
- let loanTotalTime2Min = { loanTotalTime: 10, loanRenewAtLast: 5, pageChangedInLast: 5 };
135
- let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 290, pageChangedInLast: 15 };
134
+ let loanTotalTime2Min = { loanTotalTime: 70, loanRenewAtLast: 65, pageChangedInLast: 5 };
135
+ let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
136
  let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 600, pageChangedInLast: 900 };
137
137
 
138
138
  iaBookActions.loanRenewTimeConfig = loanTotalTime2Min;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.1.5-alpha1",
3
+ "version": "0.1.5-alpha3",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -204,7 +204,11 @@ export class CollapsibleActionGroup extends ActionsHandler {
204
204
  href="${action.url}"
205
205
  target=${action.target}
206
206
  @click=${() => {
207
- this.clickHandler(action.id, action.analyticsEvent);
207
+ this.clickHandler(
208
+ action.id,
209
+ action.analyticsEvent,
210
+ action?.borrowType
211
+ );
208
212
  }}
209
213
  >
210
214
  ${action.id === 'purchaseBook' ? purchaseIcon : ''} ${action.text}
@@ -225,7 +229,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
225
229
  return html`<button
226
230
  class="ia-button ${action.className} ${initialButton ? 'initial' : ''}"
227
231
  @click=${() => {
228
- this.clickHandler(action.id, analyticsEvent);
232
+ this.clickHandler(action.id, analyticsEvent, action?.borrowType);
229
233
  }}
230
234
  >
231
235
  ${action.text}
@@ -238,10 +242,10 @@ export class CollapsibleActionGroup extends ActionsHandler {
238
242
  * @param { object } gaEvent - contains analytics event action and category
239
243
  * @param { string } gaEvent.category
240
244
  * @param { string } gaEvent.action
241
- *
245
+ * @param { string } borrowType browse|borrow
242
246
  * @fires CollapsibleActionGroup#{eventName} - (will be browseBook, borrowBook etc...)
243
247
  */
244
- clickHandler(eventName, gaEvent) {
248
+ clickHandler(eventName, gaEvent, borrowType = '') {
245
249
  this.dropdownState = 'close';
246
250
  this.dropdownArrow = dropdownClosed;
247
251
 
@@ -251,6 +255,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
251
255
  new CustomEvent(eventName, {
252
256
  detail: {
253
257
  event: { category, action },
258
+ borrowType,
254
259
  },
255
260
  })
256
261
  );
@@ -70,6 +70,7 @@ export default class ActionsConfig {
70
70
  category: eventCategory,
71
71
  action: this.analyticsActions.doneBorrowing,
72
72
  },
73
+ borrowType: this.lendingStatus.user_has_browsed ? 'browse' : 'borrow',
73
74
  };
74
75
  }
75
76
 
@@ -1,18 +1,16 @@
1
1
  import { LitElement } from 'lit';
2
2
 
3
3
  import { URLHelper } from '../../config/url-helper.js';
4
- import { sentryLogs } from '../../config/sentry-events.js';
5
- import { analyticsCategories } from '../../config/analytics-event-and-category.js';
6
4
 
7
5
  import ActionsHandlerService from './actions-handler-service.js';
6
+ import LoanAnanlytics from '../loan-analytics.js';
8
7
  import * as Cookies from '../doc-cookies.js';
9
8
 
10
9
  /**
11
10
  * These are callback functions calling from actions-config.js file.
12
11
  *
13
- * ActionsHandlerService is a function being used to execute
14
- * APIs based of the request made by user. It consist some parameters are as follows:-
15
- * 1. identifier: book name.
12
+ * ActionsHandlerService is a function being used to execute APIs based of the request made by user.
13
+ *
16
14
  */
17
15
 
18
16
  export default class ActionsHandler extends LitElement {
@@ -25,202 +23,100 @@ export default class ActionsHandler extends LitElement {
25
23
  */
26
24
  this.waitUntillBorrowComplete = 6; // in seconds
27
25
 
28
- this.bindEvents();
29
- }
30
-
31
- /**
32
- * reponsible to sent events to GA
33
- *
34
- * @param {string} eventCategory
35
- * @param {string} eventAction
36
- * @memberof ActionsHandler
37
- */
38
- sendEvent(eventCategory, eventAction, label, extraParams) {
39
- window?.archive_analytics?.send_event_no_sampling(
40
- eventCategory,
41
- eventAction,
42
- label || `identifier=${this.identifier}`,
43
- extraParams
44
- );
45
- }
26
+ /**
27
+ * bind events for lending bar
28
+ * @type {object}
29
+ */
30
+ this.loanAnanlytics = new LoanAnanlytics();
46
31
 
47
- get getLoanCountStorageKey() {
48
- return `br-browse-${this.identifier}`;
32
+ /**
33
+ * bind events for lending bar
34
+ * @type {Function}
35
+ */
36
+ this.bindEvents();
49
37
  }
50
38
 
51
39
  bindEvents() {
52
- this.addEventListener('browseBook', ({ detail }) => {
40
+ this.addEventListener('browseBook', () => {
53
41
  this.handleBrowseIt();
54
- this.setConsecutiveLoanCounts('browseBook');
55
- const { category, action } = detail.event;
56
- this.sendEvent(category, action);
42
+ this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'browse');
57
43
  });
58
44
 
59
- this.addEventListener('browseBookAgain', ({ detail }) => {
45
+ this.addEventListener('browseBookAgain', () => {
60
46
  this.handleBrowseIt();
61
- this.setConsecutiveLoanCounts('browseBookAgain');
62
- const { category, action } = detail.event;
63
- this.sendEvent(category, action);
47
+ this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'browseagain');
64
48
  });
65
49
 
66
- this.addEventListener('autoRenew', ({ detail }) => {
50
+ this.addEventListener('autoRenew', () => {
67
51
  this.handleLoanRenewNow();
68
- this.setConsecutiveLoanCounts('autoRenew');
69
- const { category, action } = detail.event;
70
- this.sendEvent(category, action);
52
+ this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'autorenew');
71
53
  });
72
54
 
73
- this.addEventListener('autoReturn', ({ detail }) => {
74
- this.setConsecutiveLoanCounts('autoReturn');
75
- const { category, action } = detail.event;
76
- this.sendEvent(category, action);
55
+ this.addEventListener('autoReturn', () => {
56
+ this.deleteLoanCookies();
57
+ this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'autoreturn');
77
58
  });
78
59
 
79
60
  this.addEventListener('returnNow', ({ detail }) => {
61
+ // use loan stats count when 1-hour borrow is active
62
+ if (detail?.borrowType === 'browse') {
63
+ this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'return');
64
+ }
65
+
80
66
  this.handleReturnIt();
81
- const { category, action } = detail.event;
82
- this.sendEvent(category, action);
67
+
68
+ // send these events if 14-day borrow return
69
+ if (detail?.borrowType === 'borrow') {
70
+ const { category, action } = detail.event;
71
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
72
+ }
83
73
  });
84
74
 
85
75
  this.addEventListener('borrowBook', ({ detail }) => {
86
76
  this.handleBorrowIt();
87
77
  const { category, action } = detail.event;
88
- this.sendEvent(category, action);
78
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
89
79
  });
90
80
 
91
81
  this.addEventListener('loginAndBorrow', ({ detail }) => {
92
82
  this.handleLoginOk();
93
83
  const { category, action } = detail.event;
94
- this.sendEvent(category, action);
84
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
95
85
  });
96
86
 
97
87
  this.addEventListener('leaveWaitlist', ({ detail }) => {
98
88
  this.handleRemoveFromWaitingList();
99
89
  const { category, action } = detail.event;
100
- this.sendEvent(category, action);
90
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
101
91
  });
102
92
 
103
93
  this.addEventListener('joinWaitlist', ({ detail }) => {
104
94
  this.handleReserveIt();
105
95
  const { category, action } = detail.event;
106
- this.sendEvent(category, action);
96
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
107
97
  });
108
98
 
109
99
  this.addEventListener('purchaseBook', ({ detail }) => {
110
100
  const { category, action } = detail.event;
111
- this.sendEvent(category, action);
101
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
112
102
  });
113
103
 
114
104
  this.addEventListener('adminAccess', ({ detail }) => {
115
105
  const { category, action } = detail.event;
116
- this.sendEvent(category, action);
106
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
117
107
  });
118
108
 
119
109
  this.addEventListener('exitAdminAccess', ({ detail }) => {
120
110
  const { category, action } = detail.event;
121
- this.sendEvent(category, action);
111
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
122
112
  });
123
113
 
124
114
  this.addEventListener('bookTitleBar', ({ detail }) => {
125
115
  const { category, action } = detail.event;
126
- this.sendEvent(category, action);
116
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
127
117
  });
128
118
  }
129
119
 
130
- /**
131
- * store consecutive one hour loan counts in cookies for GA
132
- *
133
- * There are two possible way of consecutive loan
134
- * - book is browsed again just after getting expired
135
- * - book loan is auto renewed for another hour
136
- *
137
- * @param {string} action - user action on book
138
- * @return {void}
139
- * @memberof ActionsHandler
140
- */
141
- async setConsecutiveLoanCounts(action = '') {
142
- try {
143
- await this.getConsecutiveLoanRecord(action);
144
-
145
- const date = new Date();
146
- date.setHours(date.getHours() + 2); // 2 hours
147
-
148
- // set new value
149
- Cookies.setItem(
150
- this.getLoanCountStorageKey,
151
- JSON.stringify(this.lendingEventCounts),
152
- date,
153
- '/'
154
- );
155
- } catch (error) {
156
- console.log(error);
157
- window?.Sentry?.captureException(
158
- `${sentryLogs.setConsecutiveLoanCounts} - Error: ${error}`
159
- );
160
- this.sendEvent('Cookies-Error-Actions', error);
161
- }
162
- }
163
-
164
- /**
165
- * Get consecutive loan count records from cookies for GA
166
- *
167
- * @param {string} action
168
- * @memberof ActionsHandler
169
- */
170
- async getConsecutiveLoanRecord(action) {
171
- const gaStats = { browse: 0, renew: 0, expire: 0 };
172
-
173
- this.lendingEventCounts = JSON.parse(
174
- Cookies.getItem(this.getLoanCountStorageKey)
175
- );
176
-
177
- let browse = this.lendingEventCounts?.browse ?? 0;
178
- let renew = this.lendingEventCounts?.renew ?? 0;
179
- let expire = this.lendingEventCounts?.expire ?? 0;
180
-
181
- if (this.lendingEventCounts !== null) {
182
- switch (action) {
183
- case 'browseBook' || 'browseBookAgain':
184
- browse = browse ? Number(browse) + 1 : 1;
185
- gaStats.browse = browse;
186
- break;
187
-
188
- case 'autoRenew':
189
- renew = renew ? Number(renew) + 1 : 1;
190
- gaStats.renew = renew;
191
- this.sendEvent(
192
- analyticsCategories.browse,
193
- `BookAutoRenewedFor${renew}`
194
- );
195
- break;
196
-
197
- case 'autoReturn':
198
- expire = expire ? Number(expire) + 1 : 1;
199
- gaStats.expire = expire;
200
-
201
- renew = 0; // reset renew count when book is expired
202
- break;
203
- default:
204
- break;
205
- }
206
- }
207
-
208
- // store these counts in cookies
209
- this.lendingEventCounts = { browse, renew, expire };
210
-
211
- // send google analytics events
212
- this.sendEvent(
213
- analyticsCategories.browse,
214
- `browse${gaStats.browse}-autoRenew${gaStats.renew}-autoExpire${gaStats.expire}`,
215
- '',
216
- {
217
- browse: gaStats.browse,
218
- renew: gaStats.renew,
219
- expire: gaStats.expire,
220
- }
221
- );
222
- }
223
-
224
120
  handleBrowseIt() {
225
121
  const action = 'browse_book';
226
122
  this.dispatchToggleActionGroup();
@@ -267,7 +163,10 @@ export default class ActionsHandler extends LitElement {
267
163
  identifier: this.identifier,
268
164
  success: () => {
269
165
  this.deleteLoanCookies();
270
- URLHelper.goToUrl(this.returnUrl, true);
166
+ // URLHelper.goToUrl(this.returnUrl, true);
167
+ setTimeout(() => {
168
+ URLHelper.goToUrl(this.returnUrl, true);
169
+ }, this.waitUntillBorrowComplete * 1000);
271
170
  },
272
171
  error: data => {
273
172
  this.dispatchActionError(action, data);
@@ -334,7 +233,7 @@ export default class ActionsHandler extends LitElement {
334
233
  */
335
234
  dispatchActionError(action, data = {}) {
336
235
  // send LendingServiceError to GA
337
- this.sendEvent('LendingServiceError', action);
236
+ this.loanAnanlytics?.sendEvent('LendingServiceError', action);
338
237
 
339
238
  this.dispatchEvent(
340
239
  new CustomEvent('lendingActionError', {
@@ -0,0 +1,159 @@
1
+ /* eslint-disable class-methods-use-this */
2
+
3
+ import { analyticsCategories } from '../config/analytics-event-and-category.js';
4
+ import * as Cookies from './doc-cookies.js';
5
+
6
+ /**
7
+ * This class is used to send different GA events for loan system.
8
+ */
9
+ export default class LoanAnanlytics {
10
+ constructor() {
11
+ this.identifier = undefined;
12
+
13
+ /**
14
+ * contains the counts we send to GA
15
+ * @type {object}
16
+ * - @param {number} - browse count
17
+ * - @param {number} - renew count
18
+ * - @param {number} - expire count
19
+ */
20
+ this.gaStats = {};
21
+ }
22
+
23
+ /**
24
+ * store loan stats count in cookies to remember the count we need to sent GA
25
+ *
26
+ * @param {string} identifier - book id
27
+ * @param {string} action - user action on book
28
+ * @return {void}
29
+ * @memberof ActionsHandler
30
+ */
31
+ async storeLoanStatsCount(idetifier, action = '') {
32
+ this.identifier = idetifier;
33
+
34
+ try {
35
+ await this.getLoanStatsCount(action);
36
+
37
+ const date = new Date();
38
+ date.setHours(date.getHours() + 2); // 2 hours
39
+
40
+ // set new value
41
+ Cookies.setItem(
42
+ this.getLoanCountStorageKey,
43
+ JSON.stringify(this.lendingEventCounts),
44
+ date,
45
+ '/'
46
+ );
47
+ } catch (error) {
48
+ console.log(error);
49
+ this.sendEvent('Cookies-Error-Actions', error, this.identifier);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * get loan stats count from cookies for GA
55
+ *
56
+ * @param {string} action 'browse'|'autorenew'|etc...
57
+ * @memberof ActionsHandler
58
+ */
59
+ async getLoanStatsCount(action) {
60
+ this.lendingEventCounts = JSON.parse(
61
+ Cookies.getItem(this.getLoanCountStorageKey)
62
+ );
63
+
64
+ this.gaStats = this.lendingEventCounts ?? {
65
+ browse: 0,
66
+ renew: 0,
67
+ expire: 0,
68
+ };
69
+
70
+ let { browse, renew, expire } = this.lendingEventCounts ?? 0;
71
+
72
+ switch (action) {
73
+ case 'browse' || 'browseagain':
74
+ browse = browse ? Number(browse) + 1 : 1;
75
+ this.gaStats.browse = browse;
76
+
77
+ // reset renew and expire count
78
+ renew = 0;
79
+ expire = 0;
80
+ break;
81
+
82
+ case 'autorenew':
83
+ renew = renew ? Number(renew) + 1 : 1;
84
+ this.gaStats.renew = renew;
85
+ break;
86
+
87
+ case 'return' || 'autoreturn':
88
+ expire = expire ? Number(expire) + 1 : 1;
89
+ this.gaStats.expire = expire;
90
+
91
+ // reset renew and expire count
92
+ renew = 0;
93
+ expire = 0;
94
+ break;
95
+ default:
96
+ break;
97
+ }
98
+
99
+ // store these counts in cookies
100
+ this.lendingEventCounts = { browse, renew, expire };
101
+
102
+ // obtain GA category, event
103
+ const category = analyticsCategories.browse;
104
+ const event = `browse${this.paddedNumber(
105
+ this.gaStats?.browse
106
+ )}-autorenew${this.paddedNumber(this.gaStats?.renew)}:${action}`;
107
+
108
+ // send google analytics events
109
+ this.sendEvent(category, event, this.identifier);
110
+ }
111
+
112
+ /**
113
+ * get zero padded number
114
+ *
115
+ * @param {number} number
116
+ * @return {string} browse001|autorenew001
117
+ * @memberof LoanAnanlytics
118
+ */
119
+ paddedNumber(number) {
120
+ return number.toString().padStart(3, '0');
121
+ }
122
+
123
+ /**
124
+ * get storage key for loan stats count
125
+ *
126
+ * @readonly
127
+ * @memberof LoanAnanlytics
128
+ */
129
+ get getLoanCountStorageKey() {
130
+ return `br-browse-${this.identifier}`;
131
+ }
132
+
133
+ /**
134
+ * reponsible to sent events to GA
135
+ *
136
+ * @param {*} eventCategory
137
+ * @param {*} eventAction
138
+ * @param {*} label
139
+ * @param {*} extraParams
140
+ * @memberof LoanAnanlytics
141
+ */
142
+ sendEvent(eventCategory, eventAction, label, extraParams) {
143
+ console.log(
144
+ 'eventCategory:-',
145
+ eventCategory,
146
+ '\t||\teventAction:-',
147
+ eventAction,
148
+ '\t||\tlabel:-',
149
+ label
150
+ );
151
+
152
+ window?.archive_analytics?.send_event_no_sampling(
153
+ eventCategory,
154
+ eventAction,
155
+ label || this.identifier,
156
+ extraParams
157
+ );
158
+ }
159
+ }
@@ -89,6 +89,7 @@ export class LoanRenewHelper {
89
89
  ) {
90
90
  this.result.texts = this.loanReturnWarning;
91
91
  this.result.renewNow = false; // not viewed
92
+ console.log('warning msg appears');
92
93
  } else if (pageChangedTime >= pageChangeTimeFrame) {
93
94
  this.result.texts = '';
94
95
  this.result.renewNow = true; // viewed in last time frame
@@ -1,4 +1,5 @@
1
1
  import ActionsHandlerService from './actions-handler/actions-handler-service.js';
2
+ import LoanAnanlytics from './loan-analytics.js';
2
3
  import { sentryLogs } from '../config/sentry-events.js';
3
4
 
4
5
  import * as Cookies from './doc-cookies.js';
@@ -17,6 +18,13 @@ export class LoanTokenPoller {
17
18
  this.pollerDelay = pollerDelay; // value in seconds
18
19
 
19
20
  this.loanTokenInterval = undefined;
21
+
22
+ /**
23
+ * loan analytics instance
24
+ * @see loan-analytics.js
25
+ */
26
+ this.loanAnalytics = new LoanAnanlytics();
27
+
20
28
  this.bookAccessed();
21
29
  }
22
30
 
@@ -29,19 +37,18 @@ export class LoanTokenPoller {
29
37
 
30
38
  if (this.borrowType) {
31
39
  // send consecutiveLoanCounts for browsed books only.
32
- if (this.borrowType === 'browsed') {
33
- try {
34
- const existingCount = Cookies.getItem(
35
- `loan-count-${this.identifier}`
36
- );
37
- consecutiveLoanCounts = existingCount ?? 1;
38
- } catch (error) {
39
- window?.Sentry?.captureException(
40
- `${sentryLogs.enableBookAcces} - CookieError: ${error}`
41
- );
42
- this.sendEvent('Cookies-Error-Token', error);
43
- }
44
- }
40
+ // if (this.borrowType === 'browsed') {
41
+ // try {
42
+ // const existingCount = Cookies.getItem(
43
+ // `loan-count-${this.identifier}`
44
+ // );
45
+ // consecutiveLoanCounts = existingCount ?? 1;
46
+ // } catch (error) {
47
+ // window?.Sentry?.captureException(
48
+ // `${sentryLogs.enableBookAcces} - CookieError: ${error}`
49
+ // );
50
+ // }
51
+ // }
45
52
 
46
53
  // Do an initial token, then set an interval
47
54
  this.handleLoanTokenPoller(true);
@@ -60,12 +67,12 @@ export class LoanTokenPoller {
60
67
  }
61
68
 
62
69
  // event category and action for browsing book access
63
- const category = `${this.borrowType}BookAccess`;
64
- const action = `${
65
- this.borrowType === 'browsed' ? 'BrowseCounts-' : 'Counts-'
66
- }${consecutiveLoanCounts}`;
70
+ // const category = `${this.borrowType}BookAccess`;
71
+ // const action = `${
72
+ // this.borrowType === 'browsed' ? 'BrowseCounts-' : 'Counts-'
73
+ // }${consecutiveLoanCounts}`;
67
74
 
68
- this.sendEvent(category, action);
75
+ // this.loanAnalytics?.sendEvent(category, action, this.identifier);
69
76
  } else {
70
77
  window?.Sentry?.captureMessage(
71
78
  `${sentryLogs.bookAccessed} - not borrowed`
@@ -76,14 +83,6 @@ export class LoanTokenPoller {
76
83
  }
77
84
  }
78
85
 
79
- sendEvent(eventCategory, eventAction) {
80
- window?.archive_analytics?.send_event_no_sampling(
81
- eventCategory,
82
- eventAction,
83
- `identifier=${this.identifier}`
84
- );
85
- }
86
-
87
86
  async handleLoanTokenPoller(isInitial = false) {
88
87
  const action = 'create_token';
89
88
  ActionsHandlerService({
@@ -98,7 +97,11 @@ export class LoanTokenPoller {
98
97
  );
99
98
 
100
99
  // send LendingServiceError to GA
101
- this.sendEvent('LendingServiceLoanError', action);
100
+ this.loanAnalytics?.sendEvent(
101
+ 'LendingServiceLoanError',
102
+ action,
103
+ this.identifier
104
+ );
102
105
  },
103
106
  success: () => {
104
107
  if (isInitial) this.successCallback();
@@ -11,6 +11,7 @@ import './components/book-title-bar.js';
11
11
  import './components/text-group.js';
12
12
  import './components/info-icon.js';
13
13
  import './components/timer-countdown.js';
14
+ import './core/config/ia-lending-intervals.js';
14
15
 
15
16
  import { GetLendingActions } from './core/services/get-lending-actions.js';
16
17
  import { mobileContainerWidth } from './core/config/constants.js';
@@ -18,9 +19,6 @@ import { sentryLogs } from './core/config/sentry-events.js';
18
19
  import { LoanTokenPoller } from './core/services/loan-token-poller.js';
19
20
  import { LoanRenewHelper } from './core/services/loan-renew-helper.js';
20
21
 
21
- import './core/config/ia-lending-intervals.js';
22
- import * as Cookies from './core/services/doc-cookies.js';
23
-
24
22
  export const events = {
25
23
  browseExpired: 'IABookReader:BrowsingHasExpired',
26
24
  };
@@ -75,6 +73,7 @@ export default class IABookActions extends LitElement {
75
73
  this.borrowType = ''; // (browsed|borrowed)
76
74
  this.consecutiveLoanCounts = 1; // consecutive loan count
77
75
  this.suppressToast = false;
76
+ this.suppressAutoRenew = false;
78
77
  this.browseTimer = undefined;
79
78
 
80
79
  /**
@@ -173,6 +172,7 @@ export default class IABookActions extends LitElement {
173
172
 
174
173
  async setupLendingToolbarActions() {
175
174
  this.suppressToast = false;
175
+ this.suppressAutoRenew = false;
176
176
 
177
177
  this.lendingOptions = new GetLendingActions(
178
178
  this.userid,
@@ -259,6 +259,10 @@ export default class IABookActions extends LitElement {
259
259
  this.suppressToast = true;
260
260
  this.closeToastManager();
261
261
 
262
+ if (this.suppressAutoRenew) {
263
+ return;
264
+ }
265
+
262
266
  if (this.borrowType === 'browsed') {
263
267
  this.autoLoanRenewChecker(true);
264
268
  }
@@ -290,6 +294,11 @@ export default class IABookActions extends LitElement {
290
294
  this.addEventListener('IABookActions:loanRenew', async event => {
291
295
  await this.autoLoanRenewChecker(false);
292
296
 
297
+ // maybe the renew with-in last 1 minute is too short of a transition time between xhr, loading images etc... let NOT renew in last 50 seconds.
298
+ if (event?.detail?.secondsLeft < 50) {
299
+ this.suppressAutoRenew = true;
300
+ }
301
+
293
302
  // show warning message with remaining time to auto returned it.
294
303
  if (this.loanRenewResult.renewNow === false) {
295
304
  this.loanRenewResult.secondsLeft = event.detail.secondsLeft;
@@ -405,9 +414,6 @@ export default class IABookActions extends LitElement {
405
414
  await this.localCache.delete(`${this.identifier}-loanTime`);
406
415
  await this.localCache.delete(`${this.identifier}-pageChangedTime`);
407
416
 
408
- // remove loan-renew-count-<identifier> cookie
409
- Cookies.removeItem(`loan-renew-count-${this.identifier}`);
410
-
411
417
  // show message after browsed book is expired.
412
418
  this.loanRenewResult.renewNow = false;
413
419
  this.loanRenewResult.texts =
@@ -507,8 +513,10 @@ export default class IABookActions extends LitElement {
507
513
  * - show success message
508
514
  * - then change the remaining time
509
515
  * - reset timer state
516
+ * @param {object} event
510
517
  */
511
- async handleLoanAutoRenewed() {
518
+ async handleLoanAutoRenewed(event) {
519
+ // TODO: just read DATA variable here to apply security { action, data }
512
520
  if (this.loanRenewResult.renewNow) {
513
521
  window?.IALendingIntervals?.clearAll();
514
522
 
@@ -518,12 +526,12 @@ export default class IABookActions extends LitElement {
518
526
  await this.resetTimerCountState();
519
527
 
520
528
  window?.Sentry?.captureMessage(`${sentryLogs.bookHasRenewed}`);
521
- // TODO: analytics?? for consecutive renew.....
522
529
 
523
530
  // testing console....
524
- console.log(sentryLogs.bookHasRenewed, {
531
+ console.log('IABookActions: AutoRenewed:- ', {
532
+ ajaxResponse: event?.detail?.data,
525
533
  loanRenewResult: this.loanRenewResult,
526
- browseHasRenew: this.lendingStatus.secondsLeftOnLoan,
534
+ secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan),
527
535
  resetTimerCountState: this._shadowRoot.querySelector('timer-countdown'),
528
536
  });
529
537
  }