-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
162 lines (136 loc) · 5.18 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { EventEmitter } from 'events';
import { StaMP } from '@stampit/stamp';
export declare namespace BotSocket {
import MessagesRequestDataMap = BotSocket.Protocol.Messages.MessagesRequestDataMap;
type StatusLevel =
| 'info'
| 'danger'
| 'warning'
| 'success'
;
interface ClientSocket extends EventEmitter {
connect();
reconnect();
close(code);
sendMessageToServer<RequestType extends keyof MessagesRequestDataMap>(request: RequestType, data: MessagesRequestDataMap[RequestType]);
}
// region namespace: Protocol
namespace Protocol {
interface BotUserConversation {
botUserId: string;
conversationId: string;
expiresAt: string;
}
namespace Messages {
interface MessagesRequestDataMap {
'handshake': ClientHandshakeData,
'submit-query': SubmitQueryData,
'submit-event': SubmitEventData,
'render-letter': RenderLetterData
}
export type RequestType =
| 'handshake'
| 'submit-query'
| 'submit-event'
| 'render-letter'
;
interface RequestMessage {
request: RequestType;
data: RequestData;
}
interface RequestData {
conversation?: BotUserConversation | null;
}
// region ClientHandshake
interface ClientHandshake extends RequestMessage {
request: 'handshake';
data: ClientHandshakeData;
}
/**
* Data provided by the client in it's handshake requests.
*/
interface ClientHandshakeData extends RequestData {
/**
* @deprecated in favor of userId
*/
sessionId: string;
/**
* @deprecated in favor of userId
*/
clientId: string;
/**
* The id of the user that the client *wants* to
* represent when sending messages to the server.
*/
userId: string;
/**
* The timezone that the client is operating in.
*/
timezone?: string;
}
// endregion
// region ServerHandshake
interface ServerHandshake extends RequestMessage {
request: 'handshake';
data: ServerHandshakeData;
}
/**
* Data provided by the server in it's handshake requests.
*/
interface ServerHandshakeData extends RequestData {
/**
* The id of the user that the server *says* the client
* represents when sending messages to the server.
*/
userId: string;
/**
* How long (in seconds) the server thinks that the
* client should wait before trying to reconnect,
* whenever the server disconnects the client.
*/
retryWaitTime: number;
/**
* The id of the connection that handles this clients
* interactions with the server.
*/
connectionId: string;
/**
* Array of prior requests messages that the server has sent
* previously to clients connected with the given `userId`.
*/
priorRequests: Array<BotSocket.Protocol.Messages.RequestMessage>;
}
// endregion
// region SubmitQuery
interface SubmitQuery extends RequestMessage {
request: 'submit-query';
data: SubmitQueryData;
}
interface SubmitQueryData extends StaMP.Protocol.Messages.StandardisedQueryMessage {
}
// endregion
// region SubmitEvent
interface SubmitEvent<PayloadData extends object, DataData extends object | StaMP.Protocol.Messages.StandardisedEventMessageData> extends RequestMessage {
request: 'submit-event';
data: SubmitEventData<PayloadData, DataData>;
}
interface SubmitEventData<PayloadData extends object, DataData extends object | StaMP.Protocol.Messages.StandardisedEventMessageData> extends StaMP.Protocol.Messages.StandardisedEventMessage<PayloadData, DataData> {
}
// endregion
// region RenderLetter
interface RenderLetter extends RequestMessage {
request: 'render-letter';
data: RenderLetterData;
}
interface RenderLetterData extends RequestData {
/**
* @deprecated in favor of the letter property
*/
messages: StaMP.Protocol.Letter;
letter: StaMP.Protocol.Letter;
}
// endregion
}
}
// endregion
}