@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.16-4",
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.1",
28
- "lit-element": "^2.4.0",
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,4 +1,4 @@
1
- import { html } from 'lit-element';
1
+ import { html } from 'lit';
2
2
 
3
3
  export const archiveLogo = html`
4
4
  <svg
@@ -1,4 +1,4 @@
1
- import { html } from 'lit-element';
1
+ import { html } from 'lit';
2
2
 
3
3
  export const dropdownOpened = html`<svg
4
4
  height="4"
@@ -1,4 +1,4 @@
1
- import { html } from 'lit-element';
1
+ import { html } from 'lit';
2
2
 
3
3
  export const purchaseIcon = html`<svg
4
4
  height="20"
@@ -1,4 +1,4 @@
1
- import { css } from 'lit-element';
1
+ import { css } from 'lit';
2
2
 
3
3
  export default css`
4
4
  :host {
@@ -1,4 +1,4 @@
1
- import { css } from 'lit-element';
1
+ import { css } from 'lit';
2
2
 
3
3
  export default css`
4
4
  .ia-button {
@@ -1,4 +1,4 @@
1
- import { html, css } from 'lit-element';
1
+ import { html, css } from 'lit';
2
2
 
3
3
  import {
4
4
  analyticsCategories,
@@ -1,6 +1,6 @@
1
- import { html } from 'lit-element';
2
- import { nothing } from 'lit-html';
3
- import { classMap } from 'lit-html/directives/class-map';
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-element';
2
- import { unsafeHTML } from 'lit-html/directives/unsafe-html';
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 {
@@ -1,4 +1,4 @@
1
- import { html, css, LitElement } from 'lit-element';
1
+ import { html, css, LitElement } from 'lit';
2
2
 
3
3
  export class TextGroup extends LitElement {
4
4
  static get properties() {
@@ -1,4 +1,4 @@
1
- import { nothing } from 'lit-html';
1
+ import { nothing } from 'lit/html.js';
2
2
 
3
3
  export class URLHelper {
4
4
  /**
@@ -4,7 +4,7 @@
4
4
  * Helper to call loan service
5
5
  * @param {Object} options
6
6
  */
7
- export default async function ActionsHandlerService(options) {
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
- console.log('failed-to-fecth-loan-data fix is here');
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
- // return success response for /demo/ server...
50
- if (baseHost == '/demo/1' || baseHost == '/demo/') {
51
- return {
52
- success: true,
53
- message: 'operation executed successfully!',
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
- // The response is a Response instance.
58
- // You parse the data into a useable format using `.json()`
59
- return response.json();
60
- })
61
- .then(data => {
62
- // `data` is the parsed version of the JSON returned from the above endpoint.
63
- if (!data?.error) {
64
- option?.success(data);
65
- } else {
66
- option?.error(data);
67
- }
68
- });
69
- } catch (err) {}
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
  }
@@ -1,4 +1,4 @@
1
- import { LitElement } from 'lit-element';
1
+ import { LitElement } from 'lit';
2
2
 
3
3
  import { URLHelper } from '../../config/url-helper.js';
4
4
  import ActionsHandlerService from './actions-handler-service.js';
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
- import { html, css, LitElement } from 'lit-element';
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';