onairos 0.0.7 → 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,13 +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} access_token={access_token} 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
- - `access_token` - App Assigned Access Token - String
58
56
  - `webpageName` - App Display Name - String
59
57
  - `proofMode` - Wish to recieve ZK proof after recieving Data , default FALSE - boolean
60
58
 
@@ -69,11 +67,15 @@ event.data.source === 'content-script'
69
67
  event.data.type === 'API_URL_RESPONSE'
70
68
  ```
71
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
+
72
73
  For example:
73
74
 
74
75
  ``` jsx
75
76
  export default async function UseAPIURL(event){
76
77
  if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
78
+ const { APIurl } = event.data;
77
79
  //Fetch Onairos Data from Returned API url
78
80
  }
79
81
  }
@@ -97,6 +99,8 @@ Send a POST request to the API endpoint with a JSON payload containing a set of
97
99
  - `category`: The category to which the content belongs (String) - required
98
100
  - `img_url`: The URL of an image associated with the content (String) - optional
99
101
 
102
+ You should also send the access token as part of this request, from your **backend**
103
+ - `access_token` - App Assigned Access Token - String
100
104
  Example JSON body for the POST request:
101
105
 
102
106
  ```json
@@ -116,14 +120,16 @@ Example JSON body for the POST request:
116
120
  "text": "Example text input 3",
117
121
  "category": "Example Category 3",
118
122
  "img_url": "http://example.com/image3.jpg"
119
- }
123
+ },
124
+ "AccessToken":"access_token"
120
125
  }
121
126
  // Additional entries can be added here
122
127
 
123
128
 
124
129
  ```
125
130
 
126
- 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
127
133
 
128
134
  ```jsx
129
135
  export default async function UseAPIURL(event){
@@ -133,6 +139,7 @@ export default async function UseAPIURL(event){
133
139
  method: 'POST',
134
140
  headers: {
135
141
  'Content-Type': 'application/json',
142
+ 'Authorization': `Bearer ${accessToken}` // Include the access token in the Authorization header
136
143
  },
137
144
  body: JSON.stringify(InputData),
138
145
  }).then(async (data)=>{
@@ -186,6 +193,7 @@ function App() {
186
193
  method: 'POST',
187
194
  headers: {
188
195
  'Content-Type': 'application/json',
196
+ 'Authorization': `Bearer ${accessToken}` // Include the access token in the Authorization header
189
197
  },
190
198
  body: JSON.stringify(InputData),
191
199
  }).then(async (data)=>{
@@ -210,8 +218,8 @@ function App() {
210
218
  type:"Personality",
211
219
  descriptions:"Insight into your Interests",
212
220
  reward:"2 USDC"
213
- }
214
- }
221
+ },
222
+ AccessToken:access_token
215
223
  };
216
224
  useEffect(() => {
217
225
  window.addEventListener('message', UseAPIURL);
@@ -222,7 +230,8 @@ function App() {
222
230
 
223
231
  const onairosID = 'test';
224
232
  return (
225
- <Onairos sendData={sendData} onairosID={onairosID} />
233
+ <Onairos sendData={sendData} webpageName={webpageName} proofMode={proofMode} />
234
+
226
235
  );
227
236
  }
228
237
  export default InferenceComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onairos",
3
- "version": "0.0.7",
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;