lucos_search_component 0.0.2 → 0.0.3

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.
@@ -1 +1,3 @@
1
- import '../index.js';
1
+ import '../index.js';
2
+
3
+ document.querySelector('lucos-search').searchAPI('luke')
@@ -1,9 +1,9 @@
1
1
  <html>
2
2
  <head>
3
3
  <title>Hello World Search Component</title>
4
- <script src="./built.js"></script>
5
4
  </head>
6
5
  <body>
7
6
  <lucos-search api-key="${KEY_LUCOS_ARACHNE}"></lucos-search>
7
+ <script src="./built.js"></script>
8
8
  </body>
9
9
  </html>
package/index.js CHANGED
@@ -1,8 +1,30 @@
1
1
  class LucosSearchComponent extends HTMLElement {
2
+ static get observedAttributes() {
3
+ return ['api-key'];
4
+ }
2
5
  constructor() {
3
6
  super();
4
7
  const shadow = this.attachShadow({mode: 'closed'});
5
- console.log("Search Component initiated")
8
+
9
+ const results = document.createElement("span");
10
+ this.updateResults = resultData => {
11
+ results.innerText = JSON.stringify(resultData);
12
+ }
13
+ shadow.appendChild(results);
14
+ }
15
+ async searchAPI(query) {
16
+ const key = this.getAttribute("api-key");
17
+ if (!key) throw new Error("No `api-key` attribute set on `lucos-search` component");
18
+
19
+ const queryParams = new URLSearchParams({
20
+ q: query,
21
+ });
22
+ const response = await fetch("https://arachne.l42.eu/basic-search?"+queryParams.toString(), {
23
+ headers: { Authorization: `key ${key}` },
24
+ signal: AbortSignal.timeout(900),
25
+ });
26
+ const data = await response.json();
27
+ this.updateResults(data);
6
28
  }
7
29
  }
8
30
  customElements.define('lucos-search', LucosSearchComponent);
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "lucos_search_component",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Web Component for searching lucOS data",
5
+ "type": "module",
5
6
  "main": "index.js",
6
7
  "scripts": {
7
8
  "test": "echo \"Error: no test specified\" && exit 1",