@internetarchive/ia-book-actions 1.4.6-alpha4 → 1.4.6
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 +1 -1
- package/src/ia-book-actions.js +13 -0
- package/test/ia-book-actions.test.js +40 -0
package/package.json
CHANGED
package/src/ia-book-actions.js
CHANGED
|
@@ -129,6 +129,16 @@ export default class IABookActions extends LitElement {
|
|
|
129
129
|
*/
|
|
130
130
|
this.skipNextInitialTokenCall = false;
|
|
131
131
|
|
|
132
|
+
/**
|
|
133
|
+
* True once a create_token failure has torn the session down (see
|
|
134
|
+
* handleLendingActionError), until a renewal confirms access again. The
|
|
135
|
+
* teardown's lendingStatus change re-runs setupLendingToolbarActions(),
|
|
136
|
+
* which would otherwise start a fresh poller straight away; for a
|
|
137
|
+
* borrowed loan (user_has_borrowed is left as is) that poller's initial
|
|
138
|
+
* create_token fails the same way, tearing down again, in a tight loop.
|
|
139
|
+
*/
|
|
140
|
+
this.tokenAccessLost = false;
|
|
141
|
+
|
|
132
142
|
this.warningModalOpen = false;
|
|
133
143
|
|
|
134
144
|
/** Once dismissed, don't re-show the warning modal every tick — only
|
|
@@ -343,6 +353,7 @@ export default class IABookActions extends LitElement {
|
|
|
343
353
|
if (
|
|
344
354
|
!hasExpired &&
|
|
345
355
|
!this.loanRenewInProgress &&
|
|
356
|
+
!this.tokenAccessLost &&
|
|
346
357
|
!window.IALendingIntervals.tokenPoller
|
|
347
358
|
) {
|
|
348
359
|
// Any confirmed renewal's response already minted a valid access
|
|
@@ -781,6 +792,7 @@ export default class IABookActions extends LitElement {
|
|
|
781
792
|
// redundant confirming create_token call, regardless of which path
|
|
782
793
|
// triggered this renewal.
|
|
783
794
|
this.skipNextInitialTokenCall = true;
|
|
795
|
+
this.tokenAccessLost = false;
|
|
784
796
|
|
|
785
797
|
// A page image requested in the gap between expiry and this renewal
|
|
786
798
|
// landing can come back broken — browsers don't retry a failed <img>
|
|
@@ -1070,6 +1082,7 @@ export default class IABookActions extends LitElement {
|
|
|
1070
1082
|
// that isn't accessible.
|
|
1071
1083
|
window?.IALendingIntervals?.clearAll();
|
|
1072
1084
|
this.tokenPoller?.disconnectedCallback();
|
|
1085
|
+
this.tokenAccessLost = true;
|
|
1073
1086
|
this.lendingStatus = {
|
|
1074
1087
|
...this.lendingStatus,
|
|
1075
1088
|
user_has_browsed: false,
|
|
@@ -1891,3 +1891,43 @@ describe('handleLendingActionError - a run of unanswered token refreshes (WEBDEV
|
|
|
1891
1891
|
expect(el.lendingStatus.secondsLeftOnLoan).to.equal(0);
|
|
1892
1892
|
});
|
|
1893
1893
|
});
|
|
1894
|
+
|
|
1895
|
+
describe('create_token failure on a borrowed loan does not loop (WEBDEV-9595)', () => {
|
|
1896
|
+
it('does not restart the token poller after the teardown', async () => {
|
|
1897
|
+
const el = await fixture(
|
|
1898
|
+
container({
|
|
1899
|
+
userid: '@user1',
|
|
1900
|
+
identifier: 'borrowed-teardown-loop',
|
|
1901
|
+
lendingStatus: {
|
|
1902
|
+
is_lendable: true,
|
|
1903
|
+
user_has_borrowed: true,
|
|
1904
|
+
available_to_borrow: false,
|
|
1905
|
+
browsingExpired: false,
|
|
1906
|
+
},
|
|
1907
|
+
})
|
|
1908
|
+
);
|
|
1909
|
+
await el.updateComplete;
|
|
1910
|
+
await aTimeout(150);
|
|
1911
|
+
const startSpy = Sinon.spy(el, 'startLoanTokenPoller');
|
|
1912
|
+
const showErrorModalSpy = Sinon.stub(el, 'showErrorModal');
|
|
1913
|
+
|
|
1914
|
+
el.handleLendingActionError({
|
|
1915
|
+
detail: {
|
|
1916
|
+
action: 'create_token',
|
|
1917
|
+
isInitial: false,
|
|
1918
|
+
consecutiveFailures: MAX_SILENT_TOKEN_REFRESH_FAILURES + 1,
|
|
1919
|
+
data: {
|
|
1920
|
+
error: networkError,
|
|
1921
|
+
detail: 'TypeError: Failed to fetch',
|
|
1922
|
+
networkFailure: true,
|
|
1923
|
+
},
|
|
1924
|
+
},
|
|
1925
|
+
});
|
|
1926
|
+
await el.updateComplete;
|
|
1927
|
+
await aTimeout(300);
|
|
1928
|
+
|
|
1929
|
+
expect(showErrorModalSpy.calledOnce).to.be.true;
|
|
1930
|
+
expect(startSpy.called).to.be.false;
|
|
1931
|
+
expect(window.IALendingIntervals.tokenPoller).to.equal(0);
|
|
1932
|
+
});
|
|
1933
|
+
});
|