@internetarchive/ia-book-actions 0.0.16-4 → 0.0.17-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 +3 -7
- package/src/assets/data/archive-logo.js +1 -1
- package/src/assets/data/dropdown-arrow.js +1 -1
- package/src/assets/data/purchase.js +1 -1
- package/src/assets/styles/collapsible-action-group.js +1 -1
- package/src/assets/styles/ia-button.js +1 -1
- package/src/components/book-title-bar.js +1 -1
- package/src/components/collapsible-action-group.js +3 -3
- package/src/components/info-icon.js +2 -2
- package/src/components/text-group.js +1 -1
- package/src/core/config/url-helper.js +1 -1
- package/src/core/services/actions-handler/actions-handler-service.js +39 -41
- package/src/core/services/actions-handler/actions-handler.js +1 -1
- package/src/ia-book-actions.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/ia-book-actions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17-1",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -18,15 +18,11 @@
|
|
|
18
18
|
"test:watch": "web-test-runner --watch --playwright --browsers chromium firefox webkit"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@internetarchive/ia-icons": "^1.2.2",
|
|
22
|
-
"@internetarchive/icon-bookmark": "^1.1.3",
|
|
23
|
-
"@internetarchive/icon-close": "^1.1.3",
|
|
24
21
|
"@internetarchive/icon-info": "^1.2.6",
|
|
25
22
|
"@internetarchive/local-cache": "^0.2.0",
|
|
26
23
|
"@internetarchive/modal-manager": "^0.1.0",
|
|
27
|
-
"@internetarchive/shared-resize-observer": "^0.0
|
|
28
|
-
"lit
|
|
29
|
-
"lit-html": "^1.3.0"
|
|
24
|
+
"@internetarchive/shared-resize-observer": "^0.2.0",
|
|
25
|
+
"lit": "^2.2.1"
|
|
30
26
|
},
|
|
31
27
|
"devDependencies": {
|
|
32
28
|
"@open-wc/eslint-config": "^4.2.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { html } from 'lit
|
|
2
|
-
import { nothing } from 'lit
|
|
3
|
-
import { classMap } from 'lit
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
import { nothing } from 'lit/html.js';
|
|
3
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
4
4
|
|
|
5
5
|
import ActionsHandler from '../core/services/actions-handler/actions-handler.js';
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { html, css, LitElement, svg } from 'lit
|
|
2
|
-
import { unsafeHTML } from 'lit
|
|
1
|
+
import { html, css, LitElement, svg } from 'lit';
|
|
2
|
+
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
3
3
|
import '@internetarchive/icon-info/icon-info.js';
|
|
4
4
|
|
|
5
5
|
export class InfoIcon extends LitElement {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Helper to call loan service
|
|
5
5
|
* @param {Object} options
|
|
6
6
|
*/
|
|
7
|
-
export default
|
|
7
|
+
export default function ActionsHandlerService(options) {
|
|
8
8
|
const option = {
|
|
9
9
|
action: null,
|
|
10
10
|
identifier: '',
|
|
@@ -16,13 +16,7 @@ export default async function ActionsHandlerService(options) {
|
|
|
16
16
|
let baseHost = '/services/loans/loan';
|
|
17
17
|
const location = window?.location;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// return error reponse when not production and has ?error=true param...
|
|
22
|
-
const tokenError = 'loan token not found. please try again later.';
|
|
23
|
-
const borrowError =
|
|
24
|
-
'This book is not available to borrow at this time. Please try again later.';
|
|
25
|
-
const erroneousActions = ['browse_book', 'borrow_book', 'create_token'];
|
|
19
|
+
// return intentional error on dev environment
|
|
26
20
|
const shouldReturnError =
|
|
27
21
|
location?.href?.indexOf('?error=true') !== -1 &&
|
|
28
22
|
location?.hostname !== 'archive.org';
|
|
@@ -32,39 +26,43 @@ export default async function ActionsHandlerService(options) {
|
|
|
32
26
|
let formData = new FormData();
|
|
33
27
|
formData.append('action', option.action);
|
|
34
28
|
formData.append('identifier', option.identifier);
|
|
35
|
-
try {
|
|
36
|
-
await fetch(baseHost, {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
body: formData,
|
|
39
|
-
})
|
|
40
|
-
.then(response => {
|
|
41
|
-
// intentional error on localhost
|
|
42
|
-
if (shouldReturnError && erroneousActions.includes(option?.action)) {
|
|
43
|
-
return {
|
|
44
|
-
success: false,
|
|
45
|
-
error: option?.action === 'create_token' ? tokenError : borrowError,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
29
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
fetch(baseHost, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
body: formData,
|
|
33
|
+
})
|
|
34
|
+
.then(response => {
|
|
35
|
+
const tokenError = 'loan token not found. please try again later.';
|
|
36
|
+
const borrowError =
|
|
37
|
+
'This book is not available to borrow at this time. Please try again later.';
|
|
38
|
+
|
|
39
|
+
// return error reponse when not production and has ?error=true param...
|
|
40
|
+
const erroneousActions = ['browse_book', 'borrow_book', 'create_token'];
|
|
41
|
+
if (shouldReturnError && erroneousActions.includes(option?.action)) {
|
|
42
|
+
return {
|
|
43
|
+
success: false,
|
|
44
|
+
error: option?.action === 'create_token' ? tokenError : borrowError,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
48
|
+
// return success response for /demo/ server...
|
|
49
|
+
if (baseHost == '/demo/1' || baseHost == '/demo/') {
|
|
50
|
+
return {
|
|
51
|
+
success: true,
|
|
52
|
+
message: 'operation executed successfully!',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The response is a Response instance.
|
|
57
|
+
// You parse the data into a useable format using `.json()`
|
|
58
|
+
return response.json();
|
|
59
|
+
})
|
|
60
|
+
.then(data => {
|
|
61
|
+
// `data` is the parsed version of the JSON returned from the above endpoint.
|
|
62
|
+
if (!data?.error) {
|
|
63
|
+
option?.success(data);
|
|
64
|
+
} else {
|
|
65
|
+
option?.error(data);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
70
68
|
}
|
package/src/ia-book-actions.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
-
import { html, css, LitElement } from 'lit
|
|
2
|
+
import { html, css, LitElement } from 'lit';
|
|
3
3
|
|
|
4
4
|
import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
|
|
5
5
|
import { ModalConfig } from '@internetarchive/modal-manager';
|