-
Notifications
You must be signed in to change notification settings - Fork 69
/
index.d.ts
194 lines (162 loc) · 4.07 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import { Agent } from "http"
import { Response } from "node-fetch"
export = Pusher
declare class Pusher {
constructor(opts: Pusher.Options)
trigger(
channel: string | Array<string>,
event: string,
data: any,
params?: Pusher.TriggerParams
): Promise<Response>
trigger(
channel: string | Array<string>,
event: string,
data: any
): Promise<Response>
triggerBatch(events: Array<Pusher.BatchEvent>): Promise<Response>
get(opts: Pusher.GetOptions): Promise<Response>
post(opts: Pusher.PostOptions): Promise<Response>
/**
* @deprecated Use authorizeChannel
*/
authenticate(
socketId: string,
channel: string,
data?: Pusher.PresenceChannelData
): Pusher.ChannelAuthResponse
authorizeChannel(
socketId: string,
channel: string,
data?: Pusher.PresenceChannelData
): Pusher.ChannelAuthResponse
authenticateUser(
socketId: string,
userData: Pusher.UserChannelData
): Pusher.UserAuthResponse
sendToUser(userId: string, event: string, data: any): Promise<Response>
terminateUserConnections(userId: string): Promise<Response>
webhook(request: Pusher.WebHookRequest): Pusher.WebHook
createSignedQueryString(opts: Pusher.SignedQueryStringOptions): string
}
declare namespace Pusher {
export function forCluster(cluster: string, opts: BaseOptions): Pusher
export function forURL(
connectionString: string,
opts?: Partial<Options>
): Pusher
export interface BaseOptions {
appId: string
key: string
secret: string
useTLS?: boolean
encrypted?: boolean
timeout?: number
agent?: Agent
encryptionMasterKeyBase64?: string
}
interface ClusterOptions extends BaseOptions {
cluster: string
}
interface HostOptions extends BaseOptions {
host: string
port?: string
}
export type Options = ClusterOptions | HostOptions
export interface TriggerParams {
socket_id?: string
info?: string
}
export interface BatchEvent {
channel: string
name: string
data: any
socket_id?: string
info?: string
}
type ReservedParams =
| "auth_key"
| "auth_timestamp"
| "auth_version"
| "auth_signature"
| "body_md5"
// I can't help but feel that this is a bit of a hack, but it seems to be the
// best way of defining a type which allows any key except some known set.
// Relies on the observation that if a reserved key is provided, it must fit
// the RHS of the intersection, and have type `never`.
//
// https://stackoverflow.com/a/58594586
export type Params = { [key: string]: any } & {
[K in ReservedParams]?: never
}
export interface RequestOptions {
path: string
params?: Params
}
export type GetOptions = RequestOptions
export interface PostOptions extends RequestOptions {
body: string
}
export interface SignedQueryStringOptions {
method: string
path: string
body?: string
params?: Params
}
/**
* @deprecated Use ChannelAuthResponse
*/
export interface AuthResponse {
auth: string
channel_data?: string
shared_secret?: string
}
export interface ChannelAuthResponse {
auth: string
channel_data?: string
shared_secret?: string
}
export interface UserAuthResponse {
auth: string
user_data: string
}
export interface PresenceChannelData {
user_id: string
user_info?: {
[key: string]: any
}
}
export interface UserChannelData {
id: string
[key: string]: any
}
export interface WebHookRequest {
headers: object
rawBody: string
}
interface Event {
name: string
channel: string
event: string
data: string
socket_id: string
}
interface WebHookData {
time_ms: number
events: Array<Event>
}
export interface Token {
key: string
secret: string
}
export class WebHook {
constructor(token: Token, request: WebHookRequest)
isValid(extraTokens?: Token | Array<Token>): boolean
isContentTypeValid(): boolean
isBodyValid(): boolean
getData(): WebHookData
getEvents(): Array<Event>
getTime(): Date
}
export { Response }
}