@vuu-ui/vuu-data-remote 4.0.0-alpha.9 → 4.0.0-beta.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 +12 -12
- package/src/ConnectionManager.js +65 -158
- package/src/DedicatedWorker.js +1 -4
- package/src/LostConnectionHandler.js +89 -0
- package/src/VuuAuthProvider.js +78 -0
- package/src/VuuAuthenticator.js +36 -0
- package/src/VuuDataSource.js +7 -10
- package/src/WebSocketConnection.js +1 -8
- package/src/authenticate.js +50 -0
- package/src/index.js +4 -0
- package/src/inlined-worker.js +1 -2805
- package/src/server-proxy/array-backed-moving-window.js +12 -17
- package/src/server-proxy/server-proxy.js +4 -7
- package/src/worker.js +2 -3
- package/types/ConnectionManager.d.ts +17 -45
- package/types/DedicatedWorker.d.ts +3 -10
- package/types/VuuDataSource.d.ts +1 -1
- package/types/WebSocketConnection.d.ts +3 -3
- package/types/index.d.ts +4 -0
- package/types/inlined-worker.d.ts +1 -1
- package/types/server-proxy/server-proxy.d.ts +2 -4
- package/types/src/ConnectionManager.d.ts +0 -36
- package/types/src/DedicatedWorker.d.ts +0 -9
- package/types/src/LostConnectionHandler.d.ts +0 -28
- package/types/src/VuuAuthProvider.d.ts +0 -39
- package/types/src/VuuAuthenticator.d.ts +0 -21
- package/types/src/VuuDataSource.d.ts +0 -74
- package/types/src/WebSocketConnection.d.ts +0 -54
- package/types/src/authenticate.d.ts +0 -15
- package/types/src/constants.d.ts +0 -41
- package/types/src/data-source.d.ts +0 -6
- package/types/src/index.d.ts +0 -11
- package/types/src/inlined-worker.d.ts +0 -1
- package/types/src/message-utils.d.ts +0 -20
- package/types/src/server-proxy/array-backed-moving-window.d.ts +0 -27
- package/types/src/server-proxy/messages.d.ts +0 -33
- package/types/src/server-proxy/server-proxy.d.ts +0 -68
- package/types/src/server-proxy/viewport.d.ts +0 -132
- package/types/src/worker.d.ts +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const defaultAuthUrl = "api/authn";
|
|
2
|
+
const isValidVuuUser = (response)=>"object" == typeof response && null !== response && "name" in response && "authorizations" in response && "string" == typeof response.name && Array.isArray(response.authorizations);
|
|
3
|
+
const parseVuuUserFromToken = (token)=>{
|
|
4
|
+
const [base64EncodedVuuUser] = token.split(".");
|
|
5
|
+
const jsonString = atob(base64EncodedVuuUser);
|
|
6
|
+
const response = JSON.parse(jsonString);
|
|
7
|
+
if (isValidVuuUser(response)) return response;
|
|
8
|
+
throw Error("auth token does not containe VuuUser");
|
|
9
|
+
};
|
|
10
|
+
const getVuuAuthToken = async (authUrl, token)=>{
|
|
11
|
+
const response = await fetch(authUrl, {
|
|
12
|
+
headers: {
|
|
13
|
+
Authorization: `Bearer ${token}`
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) throw Error("Authentication error: Auth token failure");
|
|
17
|
+
const json = await response.json();
|
|
18
|
+
const vuuUser = parseVuuUserFromToken(json.token);
|
|
19
|
+
return {
|
|
20
|
+
authorizations: vuuUser.authorizations,
|
|
21
|
+
token: json.token
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const authenticate = async (username, password, authUrl = defaultAuthUrl)=>fetch(authUrl, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
credentials: "include",
|
|
27
|
+
headers: {
|
|
28
|
+
"Content-Type": "application/json",
|
|
29
|
+
"access-control-allow-origin": location.host
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
username,
|
|
33
|
+
password
|
|
34
|
+
})
|
|
35
|
+
}).then((response)=>{
|
|
36
|
+
if (response.ok) {
|
|
37
|
+
const authToken = response.headers.get("vuu-auth-token");
|
|
38
|
+
if ("string" == typeof authToken && authToken.length > 0) try {
|
|
39
|
+
return {
|
|
40
|
+
token: authToken,
|
|
41
|
+
user: parseVuuUserFromToken(authToken)
|
|
42
|
+
};
|
|
43
|
+
} catch (e) {
|
|
44
|
+
throw Error("Authentication error: vuu auth token decoding failed.");
|
|
45
|
+
}
|
|
46
|
+
throw Error("Authentication failed auth token not returned by server");
|
|
47
|
+
}
|
|
48
|
+
throw Error(`Authentication failed ${response.status} ${response.statusText}`);
|
|
49
|
+
});
|
|
50
|
+
export { authenticate, getVuuAuthToken, parseVuuUserFromToken };
|
package/src/index.js
CHANGED
|
@@ -3,5 +3,9 @@ export * from "./constants.js";
|
|
|
3
3
|
export * from "./data-source.js";
|
|
4
4
|
export * from "./message-utils.js";
|
|
5
5
|
export * from "./VuuDataSource.js";
|
|
6
|
+
export { authenticate, getVuuAuthToken, parseVuuUserFromToken } from "./authenticate.js";
|
|
6
7
|
export { default as ConnectionManager } from "./ConnectionManager.js";
|
|
8
|
+
export { LostConnectionHandler, RetryOptions } from "./LostConnectionHandler.js";
|
|
9
|
+
export { VuuAuthTokenIssuePolicy, VuuAuthenticator } from "./VuuAuthenticator.js";
|
|
10
|
+
export { VuuAuthProvider } from "./VuuAuthProvider.js";
|
|
7
11
|
export { isConnected } from "./WebSocketConnection.js";
|