UNPKG

4.65 kBTypeScriptView Raw
1interface HandshakeFields {
2 ext: any;
3}
4
5interface AbstractHandshakeOptions {
6 authType: string;
7 sandboxId: string;
8 deploymentId: string;
9}
10
11interface CredentialsHandshakeOptions {
12 authType: string;
13 deploymentId: string;
14 login: string;
15 password: string;
16}
17
18interface TokenHandshakeOptions {
19 authType: string;
20 deploymentId: string;
21 token: string;
22}
23
24interface AbstractHandshake {
25 authType: string;
26 authVersion: string;
27 sandboxId: string;
28 deploymentId: string;
29 getHandshakeFields(client: Client): HandshakeFields;
30}
31
32interface CredentialsAuthData {
33 login: string;
34 password: string;
35}
36
37interface CredentialsHandshake extends AbstractHandshake {
38 login: string;
39 password: string;
40 authData: CredentialsAuthData;
41}
42
43interface TokenAuthData {
44 token: string;
45}
46
47interface TokenHandshake extends AbstractHandshake {
48 token: string;
49 authData: TokenAuthData;
50}
51
52type AuthenticationCallback = () => AbstractHandshake;
53
54type AsyncMacroServicePublisher = (method: string, parameters: any, hardFail?: boolean, debug?: number) => Promise<any>;
55
56type MacroServicePublisher = (method: string, parameters: any, hardFail?: boolean, debug?: number) => void;
57
58type ServicePublisher = (method: string, parameters: any) => void;
59
60interface Options {
61 apiUrl?: string;
62 sandboxId: string;
63 forceHttps?: boolean;
64 resource?: string;
65 transports?: any[];
66}
67
68interface Service {
69 DEFAULT_DEPLOYMENT_ID: string;
70}
71
72interface ServiceDeclaration {
73 deploymentId?: string;
74 listener?: any;
75 Type: Service;
76}
77
78interface Token {
79 token: string;
80}
81
82interface Credentials {
83 login: string;
84 password: string;
85}
86
87interface ClientHelper {
88 authentication: AuthenticationCallback;
89 servers: Promise<string[]>;
90 getUniqRequestId(): string;
91}
92
93type ConnectionStatusHandler = number;
94
95export interface ClientOptions extends Options {
96 authentication(): AbstractHandshake;
97}
98
99export interface WeakClientOptions extends Options {
100 deploymentId?: string;
101}
102
103export class Authentication {
104 static delegating({ token }: TokenAuthData): TokenHandshake;
105 static simple({ login, password }: CredentialsAuthData): CredentialsHandshake;
106 static weak({ token }: TokenAuthData): TokenHandshake;
107}
108
109export interface ConnectionStatusListener {
110 onConnectionBroken(): void;
111 onConnectionClosed(): void;
112 onConnectionEstablished(): void;
113 onConnectionToServerFail(failure: any): void;
114 onConnectionWillClose(): void;
115 onFailedHandshake(failure: any): void;
116 onMessageLost(): void;
117 onNoServerUrlAvailable(): void;
118 onSuccessfulHandshake(authentication: any): void;
119}
120
121export class Client {
122 helper: ClientHelper;
123 constructor(options: ClientOptions);
124 addConnectionStatusListener(listener: ConnectionStatusListener): ConnectionStatusHandler;
125 connect(): void;
126 createService(declaration: ServiceDeclaration): Service;
127 createAsyncMacroService(declaration: ServiceDeclaration): services.Macro;
128 disconnect(): void;
129 isConnected(): boolean;
130 getSandboxId(): string;
131 getResource(): string;
132 getUserId(): string;
133 removeConnectionStatusListener(listener: ConnectionStatusHandler): void;
134 setAuthentication(authentication: AuthenticationCallback): void;
135 setLogLevel(level: string): void;
136 setResource(resource: string): void;
137 unsubscribe(service: Service): void;
138 //
139 onConnectionBroken(handler: () => void): ConnectionStatusHandler;
140 onConnectionClosed(handler: () => void): ConnectionStatusHandler;
141 onConnectionEstablished(handler: () => void): ConnectionStatusHandler;
142 onConnectionToServerFail(handler: (failure: any) => void): ConnectionStatusHandler;
143 onConnectionWillClose(handler: () => void): ConnectionStatusHandler;
144 onFailedHandshake(handler: (failure: any) => void): ConnectionStatusHandler;
145 onMessageLost(handler: () => void): ConnectionStatusHandler;
146 onNoServerUrlAvailable(handler: () => void): ConnectionStatusHandler;
147 onSuccessfulHandshake(handler: (authentication: any) => void): ConnectionStatusHandler;
148}
149
150export class SmartClient extends Client {
151 getCredentials(): any;
152 getSession(): any;
153 hasCredentials(): boolean;
154 isStronglyAuthenticated(session?: any): boolean;
155 isWeaklyAuthenticated(session?: any): boolean;
156 setCredentials(credentials: any): void;
157}
158
159export class WeakClient extends Client {
160 constructor(options: WeakClientOptions);
161 getToken(): Token;
162}
163
164export namespace services {
165 class Macro implements Service {
166 DEFAULT_DEPLOYMENT_ID: string;
167 static DEFAULT_DEPLOYMENT_ID: string;
168 $publish: AsyncMacroServicePublisher;
169 constructor($publish: AsyncMacroServicePublisher);
170 }
171}
172
173export const VERSION: string;
174
175export as namespace ZetaPush;