@vuu-ui/vuu-data-remote 0.13.105 → 0.13.106

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.
Files changed (47) hide show
  1. package/cjs/ConnectionManager.js +23 -24
  2. package/cjs/ConnectionManager.js.map +1 -1
  3. package/cjs/DedicatedWorker.js +1 -6
  4. package/cjs/DedicatedWorker.js.map +1 -1
  5. package/cjs/LostConnectionHandler.js +80 -0
  6. package/cjs/LostConnectionHandler.js.map +1 -0
  7. package/cjs/VuuAuthProvider.js +87 -0
  8. package/cjs/VuuAuthProvider.js.map +1 -0
  9. package/cjs/VuuAuthenticator.js +50 -0
  10. package/cjs/VuuAuthenticator.js.map +1 -0
  11. package/cjs/WebSocketConnection.js +11 -17
  12. package/cjs/WebSocketConnection.js.map +1 -1
  13. package/cjs/authenticate.js +15 -0
  14. package/cjs/authenticate.js.map +1 -1
  15. package/cjs/index.js +9 -0
  16. package/cjs/index.js.map +1 -1
  17. package/cjs/inlined-worker.js +259 -343
  18. package/cjs/inlined-worker.js.map +1 -1
  19. package/esm/ConnectionManager.js +25 -26
  20. package/esm/ConnectionManager.js.map +1 -1
  21. package/esm/DedicatedWorker.js +1 -6
  22. package/esm/DedicatedWorker.js.map +1 -1
  23. package/esm/LostConnectionHandler.js +76 -0
  24. package/esm/LostConnectionHandler.js.map +1 -0
  25. package/esm/VuuAuthProvider.js +85 -0
  26. package/esm/VuuAuthProvider.js.map +1 -0
  27. package/esm/VuuAuthenticator.js +47 -0
  28. package/esm/VuuAuthenticator.js.map +1 -0
  29. package/esm/WebSocketConnection.js +11 -17
  30. package/esm/WebSocketConnection.js.map +1 -1
  31. package/esm/authenticate.js +15 -1
  32. package/esm/authenticate.js.map +1 -1
  33. package/esm/index.js +4 -1
  34. package/esm/index.js.map +1 -1
  35. package/esm/inlined-worker.js +259 -343
  36. package/esm/inlined-worker.js.map +1 -1
  37. package/package.json +7 -7
  38. package/types/ConnectionManager.d.ts +5 -6
  39. package/types/DedicatedWorker.d.ts +1 -2
  40. package/types/LostConnectionHandler.d.ts +28 -0
  41. package/types/VuuAuthProvider.d.ts +38 -0
  42. package/types/VuuAuthenticator.d.ts +21 -0
  43. package/types/WebSocketConnection.d.ts +19 -38
  44. package/types/authenticate.d.ts +4 -0
  45. package/types/index.d.ts +5 -2
  46. package/types/inlined-worker.d.ts +1 -1
  47. package/types/server-proxy/server-proxy.d.ts +2 -2
@@ -0,0 +1,28 @@
1
+ import { VuuAuthenticator } from "./VuuAuthenticator";
2
+ interface RetryOptions {
3
+ interval: number;
4
+ next: () => void;
5
+ remaining: number;
6
+ }
7
+ declare class RetryOptionsImpl implements RetryOptions {
8
+ private retryIntervals;
9
+ private ind;
10
+ constructor(retryIntervals: number[]);
11
+ next(): void;
12
+ get remaining(): number;
13
+ get interval(): number;
14
+ }
15
+ export declare function RetryOptions(retryIntervals: number[]): RetryOptionsImpl;
16
+ export declare class RetryGenerator {
17
+ private vuuAuth;
18
+ private options;
19
+ constructor(vuuAuth: VuuAuthenticator, options: RetryOptions);
20
+ [Symbol.asyncIterator](): AsyncGenerator;
21
+ }
22
+ export declare class LostConnectionHandler {
23
+ private vuuAuth;
24
+ private retryIntervals;
25
+ constructor(vuuAuth: VuuAuthenticator, retryIntervals?: number[]);
26
+ reconnect(): Promise<void>;
27
+ }
28
+ export {};
@@ -0,0 +1,38 @@
1
+ export type User = {
2
+ userName: string;
3
+ };
4
+ export interface AuthProvider {
5
+ login: (username?: string, password?: string) => Promise<{
6
+ authorizations: string[];
7
+ token: string;
8
+ user: User;
9
+ }>;
10
+ logout: () => void;
11
+ }
12
+ /**
13
+ * The Vuu AuthProvider is a simple Demoware auth provider that
14
+ * grabs username and pasdsword from. a simple login form and
15
+ * exchanges these for a Vuu Token. Password is manipulated in
16
+ * plain text, hence not suitable for real world usage.
17
+ *
18
+ * This AuthProvider is used by the login panel, which sets
19
+ * user credentials in cookies.
20
+ * It is then used by the application itself to retrieve the
21
+ * credentials and login to vuu.
22
+ */
23
+ export declare class VuuAuthProvider implements AuthProvider {
24
+ private authEndpoint;
25
+ constructor(authEndpoint: string);
26
+ login: (username?: string, password?: string) => Promise<{
27
+ authorizations: string[];
28
+ user: {
29
+ userName: string;
30
+ };
31
+ token: string;
32
+ }>;
33
+ private getVuuTokenWithUsernameAndPassword;
34
+ private clear;
35
+ private redirectToLoginPage;
36
+ private redirectToApplication;
37
+ logout(): void;
38
+ }
@@ -0,0 +1,21 @@
1
+ import { ValueOf } from "@vuu-ui/vuu-utils";
2
+ import { User, type AuthProvider } from "./VuuAuthProvider";
3
+ export declare const VuuAuthTokenIssuePolicy: {
4
+ readonly BearerToken: "bearer-token";
5
+ readonly UsernamePassword: "username-password";
6
+ };
7
+ export type VuuAuthTokenIssuePolicy = ValueOf<typeof VuuAuthTokenIssuePolicy>;
8
+ export interface VuuAuthenticatorConstructorOptions {
9
+ authProvider: AuthProvider;
10
+ authTokenIssuePolicy?: VuuAuthTokenIssuePolicy;
11
+ websocketUrl: string;
12
+ }
13
+ export declare class VuuAuthenticator {
14
+ private authProvider;
15
+ private authTokenIssuePolicy;
16
+ private websocketUrl;
17
+ constructor({ authProvider, authTokenIssuePolicy, websocketUrl, }: VuuAuthenticatorConstructorOptions);
18
+ private openWebsocketConnection;
19
+ login: () => Promise<[User, string[]] | never>;
20
+ logout: () => void;
21
+ }
@@ -1,58 +1,41 @@
1
1
  import { WebSocketProtocol } from "@vuu-ui/vuu-data-types";
2
- import { VuuClientMessage, VuuServerMessage } from "@vuu-ui/vuu-protocol-types";
2
+ import { InvalidSessionReason, InvalidTokenReason, LoginErrorMessage, VuuClientMessage, VuuServerMessage } from "@vuu-ui/vuu-protocol-types";
3
3
  import { EventEmitter } from "@vuu-ui/vuu-utils";
4
+ export type ConnectionPhase = "initial-connection" | "post-disconnect-reconnection";
4
5
  export type ConnectingStatus = "connecting" | "reconnecting";
5
6
  export type ConnectedStatus = "connected" | "reconnected";
6
- export type ConnectionStatus = ConnectedStatus | "closed" | "connection-open-awaiting-session" | "disconnected" | "failed" | "inactive";
7
- type InternalConnectionStatus = ConnectionStatus | ConnectingStatus;
8
- type ReconnectAttempts = {
9
- retryAttemptsTotal: number;
10
- retryAttemptsRemaining: number;
11
- secondsToNextRetry: number;
12
- };
13
- export interface WebSocketConnectionState<T extends InternalConnectionStatus = ConnectionStatus> extends ReconnectAttempts {
14
- connectionPhase: ConnectingStatus;
15
- connectionStatus: T;
16
- }
17
- export declare const isWebSocketConnectionMessage: (msg: object | WebSocketConnectionState) => msg is WebSocketConnectionState;
7
+ export type ConnectionStatus = ConnectingStatus | ConnectedStatus | "closed" | "websocket-open" | "disconnected" | "failed" | "inactive";
8
+ export declare const isInvalidTokenReason: (text: string) => text is InvalidTokenReason;
9
+ export declare const isInvalidSessionReason: (text: string) => text is InvalidSessionReason;
10
+ export declare const isWebSocketConnectionStatus: (msg: unknown) => msg is ConnectionStatus;
18
11
  export declare const isConnected: (status: ConnectionStatus) => status is ConnectedStatus;
19
- export type VuuServerMessageCallback = (msg: VuuServerMessage) => void;
20
- export type RetryLimits = {
21
- connect: number;
22
- reconnect: number;
12
+ export type LoginRejectedMessage = {
13
+ type: "LOGIN_REJECTED";
14
+ reason: LoginErrorMessage;
23
15
  };
16
+ export declare const isLoginRejectedMessage: (message: object) => message is LoginRejectedMessage;
17
+ export type VuuServerMessageCallback = (msg: VuuServerMessage | LoginRejectedMessage) => void;
24
18
  export type WebSocketConnectionConfig = {
25
19
  url: string;
26
20
  protocols: WebSocketProtocol;
27
21
  callback: VuuServerMessageCallback;
28
22
  connectionTimeout?: number;
29
- retryLimits?: RetryLimits;
30
- };
31
- export type WebSocketCloseMessage = {
32
- type: "websocket-closed";
33
- reason: WebSocketConnectionCloseReason;
34
23
  };
35
- export type WebSocketConnectionCloseReason = "failure" | "shutdown" | "invalid-token" | "token-expired";
24
+ export type WebSocketConnectionCloseReason = LoginErrorMessage | "failure" | "shutdown";
36
25
  export type WebSocketConnectionEvents = {
37
- closed: (message: WebSocketCloseMessage) => void;
38
- connected: () => void;
39
- "connection-status": (message: WebSocketConnectionState) => void;
40
- reconnected: () => void;
26
+ "connection-status": (status: ConnectionStatus) => void;
41
27
  };
42
28
  export declare class WebSocketConnection extends EventEmitter<WebSocketConnectionEvents> {
43
29
  #private;
44
- constructor({ callback, connectionTimeout, protocols, retryLimits, url, }: WebSocketConnectionConfig);
30
+ constructor({ callback, connectionTimeout, protocols, url, }: WebSocketConnectionConfig);
45
31
  get connectionTimeout(): number;
46
32
  get protocols(): WebSocketProtocol;
47
- get requiresLogin(): boolean;
48
33
  get isClosed(): boolean;
49
34
  get isDisconnected(): boolean;
50
- get isConnecting(): boolean;
51
- get status(): InternalConnectionStatus;
52
- private set status(value);
53
- get connectionState(): WebSocketConnectionState<InternalConnectionStatus>;
54
- private get hasConnectionAttemptsRemaining();
55
- private get confirmedOpen();
35
+ get connectionPhase(): ConnectionPhase;
36
+ get connectionStatus(): ConnectionStatus;
37
+ private set connectionStatus(value);
38
+ get confirmedOpen(): boolean;
56
39
  /**
57
40
  * We are 'confirmedOpen' when we see the first message transmitted
58
41
  * from the server. This ensures that even if we have one or more
@@ -64,10 +47,8 @@ export declare class WebSocketConnection extends EventEmitter<WebSocketConnectio
64
47
  */
65
48
  private set confirmedOpen(value);
66
49
  get url(): string;
67
- connect(clientCall?: boolean): Promise<unknown>;
68
- private reconnect;
50
+ openWebSocket(): Promise<unknown>;
69
51
  private receive;
70
52
  send: (msg: VuuClientMessage) => void;
71
53
  close(reason?: WebSocketConnectionCloseReason): void;
72
54
  }
73
- export {};
@@ -8,4 +8,8 @@ export type AuthenticationResponse = {
8
8
  token: string;
9
9
  user: VuuUser;
10
10
  };
11
+ export declare const getVuuAuthToken: (authUrl: string, token: string) => Promise<{
12
+ authorizations: string[];
13
+ token: string;
14
+ }>;
11
15
  export declare const authenticate: (username: string, password: string, authUrl?: string) => Promise<AuthenticationResponse>;
package/types/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- export { authenticate, parseVuuUserFromToken } from "./authenticate";
1
+ export { authenticate, getVuuAuthToken, parseVuuUserFromToken, } from "./authenticate";
2
2
  export * from "./ConnectionManager";
3
3
  export { default as ConnectionManager } from "./ConnectionManager";
4
4
  export * from "./constants";
5
5
  export * from "./data-source";
6
+ export { LostConnectionHandler, RetryOptions } from "./LostConnectionHandler";
6
7
  export * from "./message-utils";
8
+ export { VuuAuthenticator, VuuAuthTokenIssuePolicy } from "./VuuAuthenticator";
9
+ export { VuuAuthProvider, type AuthProvider } from "./VuuAuthProvider";
7
10
  export * from "./VuuDataSource";
8
- export { isConnected, type WebSocketConnectionState, } from "./WebSocketConnection";
11
+ export { isConnected, type ConnectionStatus } from "./WebSocketConnection";