onairos 0.0.8 → 0.1.0

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  ### 1. Create a Developer Account
5
5
 
6
- Create a Developer account and retrieve your Onairos developer ID and access token
6
+ Create a Developer account to access Onairos services. Register your domain to ensure secure API access.
7
7
 
8
8
  https://Onairos.uk/dev-board
9
9
 
@@ -48,12 +48,11 @@ Individual Request Information:
48
48
 
49
49
  Then instantiate the Onairos object from the Onairos package - passing in your Onairos Developer ID and your Request Object
50
50
  ```jsx
51
- <Onairos requestData={requestData} onairosID={onairosID} webpageName={webpageName} proofMode={proofMode} />
51
+ <Onairos requestData={requestData} webpageName={webpageName} proofMode={proofMode} />
52
52
  ```
53
53
 
54
54
  Onairos Object fields:
55
55
  - `requestData` - Request Object - Json
56
- - `onairosID` - App Assigned Onairos ID - String
57
56
  - `webpageName` - App Display Name - String
58
57
  - `proofMode` - Wish to recieve ZK proof after recieving Data , default FALSE - boolean
59
58
 
@@ -68,11 +67,15 @@ event.data.source === 'content-script'
68
67
  event.data.type === 'API_URL_RESPONSE'
69
68
  ```
70
69
 
70
+ You will also be given an ACCESS TOKEN which you must use in any API requests from that specific client.
71
+ This is a short lived token, for usage on your developer registered domain only, and lasts for 1 hour from issue.
72
+
71
73
  For example:
72
74
 
73
75
  ``` jsx
74
76
  export default async function UseAPIURL(event){
75
77
  if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
78
+ const { APIurl } = event.data;
76
79
  //Fetch Onairos Data from Returned API url
77
80
  }
78
81
  }
@@ -125,7 +128,8 @@ Example JSON body for the POST request:
125
128
 
126
129
  ```
127
130
 
128
- You can then call the Inference API with the Inference object created above
131
+ You can then call the Inference API with the Inference object created above.
132
+ You must also include the Access Token in the request Header
129
133
 
130
134
  ```jsx
131
135
  export default async function UseAPIURL(event){
@@ -135,6 +139,7 @@ export default async function UseAPIURL(event){
135
139
  method: 'POST',
136
140
  headers: {
137
141
  'Content-Type': 'application/json',
142
+ 'Authorization': `Bearer ${accessToken}` // Include the access token in the Authorization header
138
143
  },
139
144
  body: JSON.stringify(InputData),
140
145
  }).then(async (data)=>{
@@ -188,6 +193,7 @@ function App() {
188
193
  method: 'POST',
189
194
  headers: {
190
195
  'Content-Type': 'application/json',
196
+ 'Authorization': `Bearer ${accessToken}` // Include the access token in the Authorization header
191
197
  },
192
198
  body: JSON.stringify(InputData),
193
199
  }).then(async (data)=>{
@@ -224,7 +230,8 @@ function App() {
224
230
 
225
231
  const onairosID = 'test';
226
232
  return (
227
- <Onairos sendData={sendData} onairosID={onairosID} />
233
+ <Onairos sendData={sendData} webpageName={webpageName} proofMode={proofMode} />
234
+
228
235
  );
229
236
  }
230
237
  export default InferenceComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onairos",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "dependencies": {
5
5
  "@testing-library/jest-dom": "^5.17.0",
6
6
  "@testing-library/react": "^13.4.0",
package/src/onairos.jsx CHANGED
@@ -1,7 +1,8 @@
1
- import React from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import onairosLogo from "./OnairosBlack.png";
3
3
 
4
- function Onairos( {requestData, onairosID, proofMode=false,webpageName}) {
4
+ function Onairos( {requestData, proofMode=false,webpageName}) {
5
+ const [token,setToken] = useState();
5
6
  const OnairosAnime = async () => {
6
7
  try {
7
8
  console.log("Clicked Onairos Connect")
@@ -12,16 +13,38 @@ function Onairos( {requestData, onairosID, proofMode=false,webpageName}) {
12
13
  }
13
14
  };
14
15
 
16
+ const requestToken = async () =>{
17
+ const domain = window.location.hostname;
18
+ const response = await fetch('https://api2.onairos.uk/dev/request-token', {
19
+ method: 'POST',
20
+ headers: {
21
+ 'Content-Type': 'application/json',
22
+ },
23
+ body: JSON.stringify({ domain }),
24
+ });
25
+
26
+ if (!response.ok) {
27
+ throw new Error('Token request failed: ' + response.statusText);
28
+ }
29
+
30
+ const data = await response.json();
31
+ setToken(data.token);
32
+ // this.token = data.token; // Store the token
33
+ }
34
+
15
35
  const ConnectOnairos = async () => {
16
36
  // Title here has to match a model in the Users : accountInfo.AccountInfo.models
17
37
  // Prepare the data to be sent
18
38
  // Send the data to the content script
39
+
40
+ await requestToken();
41
+
19
42
  window.postMessage({
20
43
  source: 'webpage',
21
44
  type: 'GET_API_URL',
22
45
  webpageName: webpageName,
23
- onairosID:onairosID,
24
- access_token:"access_token",
46
+ onairosID:'onairosID', // Remove
47
+ access_token:token,
25
48
  account:"ConnectedAccountRef.current", //No Longer needed, REMOVE
26
49
  requestData: requestData,
27
50
  proofMode:proofMode
@@ -42,3 +65,72 @@ function Onairos( {requestData, onairosID, proofMode=false,webpageName}) {
42
65
  }
43
66
 
44
67
  export default Onairos;
68
+
69
+
70
+ // import React from 'react';
71
+ // import onairosLogo from "./OnairosBlack.png";
72
+
73
+ // class Onairos {
74
+ // constructor({ requestData, onairosID, proofMode = false, webpageName }) {
75
+ // const OnairosAnime = async () => {
76
+ // try {
77
+ // console.log("Clicked Onairos Connect");
78
+ // await ConnectOnairos();
79
+ // } catch (error) {
80
+ // // Handle any errors here
81
+ // console.error("Error connecting to Onairos", error);
82
+ // }
83
+ // };
84
+
85
+ // const requestToken = async () => {
86
+ // const domain = window.location.hostname;
87
+ // // const response = await fetch('https://api2.onairos.uk/request-token', {
88
+ // const response = await fetch('http://localhost:8000/request-token', {
89
+ // method: 'POST',
90
+ // headers: {
91
+ // 'Content-Type': 'application/json',
92
+ // },
93
+ // body: JSON.stringify({ domain }),
94
+ // });
95
+
96
+ // if (!response.ok) {
97
+ // throw new Error('Token request failed: ' + response.statusText);
98
+ // }
99
+
100
+ // const data = await response.json();
101
+ // this.token = data.token; // Store the token
102
+ // };
103
+
104
+ // const ConnectOnairos = async () => {
105
+ // // Title here has to match a model in the Users : accountInfo.AccountInfo.models
106
+ // // Prepare the data to be sent
107
+ // // Send the data to the content script
108
+ // await requestToken();
109
+
110
+ // window.postMessage({
111
+ // source: 'webpage',
112
+ // type: 'GET_API_URL',
113
+ // webpageName: webpageName,
114
+ // onairosID: onairosID,
115
+ // access_token: "access_token",
116
+ // account: "ConnectedAccountRef.current",
117
+ // requestData: requestData,
118
+ // proofMode: proofMode
119
+ // });
120
+ // };
121
+
122
+ // return (
123
+ // <div>
124
+ // <button
125
+ // className="OnairosConnect w-20 h-20 flex flex-col items-center justify-center text-white font-bold py-2 px-4 rounded cursor-pointer"
126
+ // onClick={OnairosAnime}
127
+ // >
128
+ // <img src={onairosLogo} alt="Onairos Logo" className="w-16 h-16 object-contain mb-2" /> {/* Adjust size as needed */}
129
+ // <span className="whitespace-nowrap">Connect to Onairos</span> {/* Prevent text from wrapping */}
130
+ // </button>
131
+ // </div>
132
+ // );
133
+ // }
134
+ // }
135
+
136
+ // export default Onairos;