kicksdk-js 0.0.0-stage → 0.2.0

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.
@@ -0,0 +1,474 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /** Base URLs to use instead of Kick's. Any left out, or undefined, stay Kick's. */
5
+ export interface Endpoints {
6
+ /** The official API: `https://api.kick.com/public/v1`. */
7
+ api?: string | undefined;
8
+ /** OAuth: `https://id.kick.com`. */
9
+ id?: string | undefined;
10
+ /** kick.com itself, whose `/api/v2` is the website API. */
11
+ website?: string | undefined;
12
+ /** The realtime endpoints: `https://web.kick.com/api/v1/realtime`. */
13
+ realtime?: string | undefined;
14
+ }
15
+
16
+ /** The message a reply answers, from its chat event: `sender_id` is the sender's user id. */
17
+ export interface ReplyTo {
18
+ message_id: string;
19
+ content?: string | undefined;
20
+ sender_id: number;
21
+ sender_username: string;
22
+ }
23
+
24
+ /** A webhook delivery's headers: `[name, value]` pairs (a fetch `Headers` will do) or an object. */
25
+ export type WebhookHeaders = Iterable<readonly [string, string]> | Record<string, string>;
26
+
27
+ /** How a delivery's timestamp is checked. By default: within 5 minutes of this machine's clock. */
28
+ export interface VerifyOptions {
29
+ /** Now, Unix **seconds** (not `Date.now()`'s milliseconds). Default: this machine's clock. */
30
+ now?: number | undefined;
31
+ /** How far from `now` the timestamp may be, either way, in seconds. Default 300. */
32
+ toleranceSecs?: number | undefined;
33
+ /** No freshness check: to re-check a delivery stored earlier. A live receiver never skips it. */
34
+ skipFreshness?: boolean | undefined;
35
+ }
36
+
37
+ /** A delivery that passed: its headers and the typed event. */
38
+ export interface VerifiedWebhook {
39
+ headers: {
40
+ message_id: string;
41
+ timestamp: string;
42
+ signature: string;
43
+ event_type: string;
44
+ version: string;
45
+ subscription_id: string | null;
46
+ };
47
+ event: { type: string; [key: string]: unknown };
48
+ }
49
+
50
+
51
+
52
+ /**
53
+ * Reconnect delays: 1 s doubling to 30 s, and a slower stage for terminal
54
+ * closes (`nextDelayFor`).
55
+ */
56
+ export class Backoff {
57
+ free(): void;
58
+ [Symbol.dispose](): void;
59
+ /**
60
+ * From `initialMs`, doubling to `maxMs` (whole milliseconds).
61
+ */
62
+ constructor(initial_ms?: number | null, max_ms?: number | null);
63
+ /**
64
+ * The wait before reconnecting after a connection ended, ms.
65
+ * `retryAfterMs` is what the end asked for: a `close` action's
66
+ * `retry_after_ms`, `retryAfterMs(code)` for a socket's close code, or 0
67
+ * for a failure without a code. With 0, exactly `nextDelayJittered`.
68
+ * With more (a terminal close), at least that, doubling with each
69
+ * terminal close since `reset()` up to six times it (300000: 5, 10, 20,
70
+ * then 30 minutes), plus up to a quarter more by `random`. Reconnect
71
+ * with a new client id after a terminal close.
72
+ */
73
+ nextDelayFor(retry_after_ms: number, random: number): number;
74
+ /**
75
+ * The next wait, ms, spread over [half of it, all of it] by `random`,
76
+ * drawn uniformly from [0, 1) (`Math.random()`), so that clients dropped
77
+ * together do not all come back together. Out of range is clamped, NaN
78
+ * taken as 0.
79
+ */
80
+ nextDelayJittered(random: number): number;
81
+ /**
82
+ * The next wait, ms.
83
+ */
84
+ nextDelay(): number;
85
+ /**
86
+ * The chat feed subscribed: back to the first wait, and the terminal
87
+ * streak ends.
88
+ */
89
+ reset(): void;
90
+ }
91
+
92
+ /**
93
+ * One connection's protocol. Each method returns the actions to carry out.
94
+ * `now` is whole milliseconds from a clock that only goes forward
95
+ * (`Math.floor(performance.now())`, or `Date.now()`).
96
+ */
97
+ export class Session {
98
+ free(): void;
99
+ [Symbol.dispose](): void;
100
+ /**
101
+ * The socket closed.
102
+ */
103
+ closed(): any;
104
+ /**
105
+ * When to call `tick` next, in ms, or undefined.
106
+ */
107
+ deadline(): number | undefined;
108
+ /**
109
+ * Whether Kick accepted the connection.
110
+ */
111
+ isConnected(): boolean;
112
+ /**
113
+ * Whether a feed is subscribed.
114
+ */
115
+ isSubscribed(channel: string): boolean;
116
+ /**
117
+ * A session for these feeds.
118
+ */
119
+ constructor(channels: string[]);
120
+ /**
121
+ * The socket opened.
122
+ */
123
+ open(token: string, now: number): any;
124
+ /**
125
+ * A text frame arrived.
126
+ */
127
+ receive(text: string, now: number): any;
128
+ /**
129
+ * A new token, after a `refresh_token` action.
130
+ */
131
+ refresh(token: string, now: number): any;
132
+ /**
133
+ * The clock reached `deadline()`.
134
+ */
135
+ tick(now: number): any;
136
+ }
137
+
138
+ /**
139
+ * Kick's webhook key, read once: `new WebhookPublicKey(pem)`, then
140
+ * `key.verify(headers, body, options?)` for each delivery.
141
+ */
142
+ export class WebhookPublicKey {
143
+ free(): void;
144
+ [Symbol.dispose](): void;
145
+ /**
146
+ * Reads a PEM key (`BEGIN PUBLIC KEY`, as Kick serves it, or
147
+ * `BEGIN RSA PUBLIC KEY`); throws if it is not one.
148
+ */
149
+ constructor(pem: string);
150
+ /**
151
+ * `verifyWebhook`, with this key.
152
+ */
153
+ verify(headers: WebhookHeaders, body: string | Uint8Array | ArrayBuffer, options?: VerifyOptions | null): VerifiedWebhook;
154
+ }
155
+
156
+ /**
157
+ * An app token request (client credentials).
158
+ */
159
+ export function appTokenRequest(client_id: string, client_secret: string, endpoints?: Endpoints | null): any;
160
+
161
+ /**
162
+ * Bans a user for good.
163
+ */
164
+ export function banRequest(session: string, channel_slug: string, username: string, endpoints?: Endpoints | null): any;
165
+
166
+ /**
167
+ * A channel by slug (`kick.com/api/v2`): chatroom id, followers, live state.
168
+ */
169
+ export function channelRequest(slug: string, endpoints?: Endpoints | null): any;
170
+
171
+ /**
172
+ * A user as a channel sees them.
173
+ */
174
+ export function channelUserRequest(channel_slug: string, username: string, endpoints?: Endpoints | null): any;
175
+
176
+ /**
177
+ * `/channels` for up to 50 user ids.
178
+ */
179
+ export function channelsByIdsRequest(token: string, user_ids: readonly number[], endpoints?: Endpoints | null): any;
180
+
181
+ /**
182
+ * `/channels` for up to 50 slugs (one unknown slug fails them all).
183
+ */
184
+ export function channelsBySlugsRequest(token: string, slugs: string[], endpoints?: Endpoints | null): any;
185
+
186
+ /**
187
+ * The feeds for one chat, the chat feed first.
188
+ */
189
+ export function chatChannels(chatroom_id: number, channel_id?: number | null): string[];
190
+
191
+ /**
192
+ * Where a channel's chat is served.
193
+ */
194
+ export function chatConnectionRequest(channel_id: number, client_id: string, endpoints?: Endpoints | null): any;
195
+
196
+ /**
197
+ * Where Kick's realtime is served in general.
198
+ */
199
+ export function connectionRequest(client_id: string, endpoints?: Endpoints | null): any;
200
+
201
+ /**
202
+ * Deletes a message.
203
+ */
204
+ export function deleteMessageRequest(session: string, chatroom_id: number, message_id: string, endpoints?: Endpoints | null): any;
205
+
206
+ /**
207
+ * An emote's image URL.
208
+ */
209
+ export function emoteUrl(id: string): string;
210
+
211
+ /**
212
+ * Recent chat and the pin, by channel id.
213
+ */
214
+ export function historyRequest(channel_id: number, endpoints?: Endpoints | null): any;
215
+
216
+ /**
217
+ * `/livestreams` for any number of user ids: one request per 50.
218
+ */
219
+ export function livestreamsRequests(token: string, user_ids: readonly number[], endpoints?: Endpoints | null): any;
220
+
221
+ /**
222
+ * The signed-in viewer's standing on a channel.
223
+ */
224
+ export function meRequest(session: string, channel_slug: string, endpoints?: Endpoints | null): any;
225
+
226
+ /**
227
+ * Whether an acting call worked; throws with `status` if not.
228
+ */
229
+ export function parseAction(status: number, body: string): void;
230
+
231
+ /**
232
+ * Reads an app token answer.
233
+ */
234
+ export function parseAppToken(status: number, body: string): any;
235
+
236
+ /**
237
+ * Reads a website channel answer.
238
+ */
239
+ export function parseChannel(status: number, body: string): any;
240
+
241
+ /**
242
+ * Reads a channel user answer.
243
+ */
244
+ export function parseChannelUser(status: number, body: string): any;
245
+
246
+ /**
247
+ * Reads a `/channels` answer.
248
+ */
249
+ export function parseChannels(status: number, body: string): any;
250
+
251
+ /**
252
+ * Reads either connection answer: `[{provider, url}…]`.
253
+ */
254
+ export function parseConnection(status: number, body: string): any;
255
+
256
+ /**
257
+ * A message's text and emotes.
258
+ */
259
+ export function parseContent(text: string, combine: boolean): any;
260
+
261
+ /**
262
+ * A feed event, typed: `{type: "chat_message", …}`. `data` as Kick sent it.
263
+ */
264
+ export function parseEvent(name: string, data: any): any;
265
+
266
+ /**
267
+ * Reads a history answer: `{messages, pinned}`.
268
+ */
269
+ export function parseHistory(status: number, body: string): any;
270
+
271
+ /**
272
+ * Reads a `/livestreams` answer.
273
+ */
274
+ export function parseLivestreams(status: number, body: string): any;
275
+
276
+ /**
277
+ * Reads a `me` answer.
278
+ */
279
+ export function parseMe(status: number, body: string): any;
280
+
281
+ /**
282
+ * The PEM from a public key answer.
283
+ */
284
+ export function parsePublicKey(status: number, body: string): string;
285
+
286
+ /**
287
+ * Reads a subscriptions answer.
288
+ */
289
+ export function parseSubscriptions(status: number, body: string): any;
290
+
291
+ /**
292
+ * The token from a token answer.
293
+ */
294
+ export function parseToken(status: number, body: string): string;
295
+
296
+ /**
297
+ * Reads a delivery's body by its type header, without checking anything.
298
+ * Throws when the body is not that type's shape. `body` is text or bytes.
299
+ */
300
+ export function parseWebhook(event_type: string, body: string | Uint8Array | ArrayBuffer): any;
301
+
302
+ /**
303
+ * Pins a message (the feed's data for it, whole) for 1 to 10080 minutes.
304
+ */
305
+ export function pinRequest(session: string, channel_slug: string, message: any, minutes: number, endpoints?: Endpoints | null): any;
306
+
307
+ /**
308
+ * The webhook signing key request.
309
+ */
310
+ export function publicKeyRequest(endpoints?: Endpoints | null): any;
311
+
312
+ /**
313
+ * The least to wait, ms, before reconnecting after the socket closed with
314
+ * this code: 300000 (5 minutes) for Kick's terminal codes (3500-3999 and
315
+ * 4500-4999: a bad token, a ban, a refused request), then reconnect with a
316
+ * new client id; 0, the ordinary backoff, for the rest (1006, a network
317
+ * drop, among them).
318
+ */
319
+ export function retryAfterMs(code: number): number;
320
+
321
+ /**
322
+ * Sends a message, or a reply when `replyTo` is
323
+ * `{message_id, content, sender_id, sender_username}`.
324
+ */
325
+ export function sendRequest(session: string, chatroom_id: number, text: string, message_ref: string, reply_to?: ReplyTo | null, endpoints?: Endpoints | null): any;
326
+
327
+ /**
328
+ * Subscribes the app to webhook `events` (`[{name, version?}]`, version 1
329
+ * when left out) for one channel.
330
+ */
331
+ export function subscribeRequest(token: string, broadcaster_user_id: number, events: ReadonlyArray<{ name: string; version?: number }>, endpoints?: Endpoints | null): any;
332
+
333
+ /**
334
+ * Every webhook subscription the app has.
335
+ */
336
+ export function subscriptionsRequest(token: string, endpoints?: Endpoints | null): any;
337
+
338
+ /**
339
+ * Times a user out for 1 to 10080 minutes.
340
+ */
341
+ export function timeoutRequest(session: string, channel_slug: string, username: string, minutes: number, endpoints?: Endpoints | null): any;
342
+
343
+ /**
344
+ * A guest token request for `clientId`.
345
+ */
346
+ export function tokenRequest(client_id: string, endpoints?: Endpoints | null): any;
347
+
348
+ /**
349
+ * The top live streams, overall or in a category or language: 1 to 100
350
+ * (100 by default). `sort` is `"viewer_count"` (the default) or
351
+ * `"started_at"`.
352
+ */
353
+ export function topLivestreamsRequest(token: string, category_id?: number | null, language?: string | null, sort?: 'viewer_count' | 'started_at' | null, limit?: number | null, endpoints?: Endpoints | null): any;
354
+
355
+ /**
356
+ * Lifts a ban or timeout.
357
+ */
358
+ export function unbanRequest(session: string, channel_slug: string, username: string, endpoints?: Endpoints | null): any;
359
+
360
+ /**
361
+ * Removes the pin.
362
+ */
363
+ export function unpinRequest(session: string, channel_slug: string, endpoints?: Endpoints | null): any;
364
+
365
+ /**
366
+ * Removes subscriptions, 50 per request.
367
+ */
368
+ export function unsubscribeRequests(token: string, ids: string[], endpoints?: Endpoints | null): any;
369
+
370
+ /**
371
+ * Checks a delivery and returns `{headers, event}`, or throws. `headers` as
372
+ * `[[name, value]…]`, a fetch `Headers` or an object; `body` the raw body,
373
+ * as text or bytes. The timestamp must be within 5 minutes of this
374
+ * machine's clock, unless `options` says otherwise: `now` (Unix seconds),
375
+ * `toleranceSecs`, or `skipFreshness: true` to re-check a stored delivery.
376
+ *
377
+ * A receiver checking many deliveries reads the key once, with
378
+ * `new WebhookPublicKey(pem)`, and calls its `verify`.
379
+ */
380
+ export function verifyWebhook(public_key_pem: string, headers: WebhookHeaders, body: string | Uint8Array | ArrayBuffer, options?: VerifyOptions | null): VerifiedWebhook;
381
+
382
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
383
+
384
+ export interface InitOutput {
385
+ readonly memory: WebAssembly.Memory;
386
+ readonly __wbg_backoff_free: (a: number, b: number) => void;
387
+ readonly __wbg_session_free: (a: number, b: number) => void;
388
+ readonly __wbg_webhookpublickey_free: (a: number, b: number) => void;
389
+ readonly appTokenRequest: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
390
+ readonly backoff_new: (a: number, b: number, c: number) => void;
391
+ readonly backoff_nextDelay: (a: number) => number;
392
+ readonly backoff_nextDelayFor: (a: number, b: number, c: number, d: number) => void;
393
+ readonly backoff_nextDelayJittered: (a: number, b: number, c: number) => void;
394
+ readonly backoff_reset: (a: number) => void;
395
+ readonly banRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
396
+ readonly channelRequest: (a: number, b: number, c: number, d: number) => void;
397
+ readonly channelUserRequest: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
398
+ readonly channelsByIdsRequest: (a: number, b: number, c: number, d: number, e: number) => void;
399
+ readonly channelsBySlugsRequest: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
400
+ readonly chatChannels: (a: number, b: number, c: number) => void;
401
+ readonly chatConnectionRequest: (a: number, b: number, c: number, d: number, e: number) => void;
402
+ readonly connectionRequest: (a: number, b: number, c: number, d: number) => void;
403
+ readonly deleteMessageRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
404
+ readonly emoteUrl: (a: number, b: number, c: number) => void;
405
+ readonly historyRequest: (a: number, b: number, c: number) => void;
406
+ readonly livestreamsRequests: (a: number, b: number, c: number, d: number, e: number) => void;
407
+ readonly meRequest: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
408
+ readonly parseAction: (a: number, b: number, c: number, d: number) => void;
409
+ readonly parseAppToken: (a: number, b: number, c: number, d: number) => void;
410
+ readonly parseChannel: (a: number, b: number, c: number, d: number) => void;
411
+ readonly parseChannelUser: (a: number, b: number, c: number, d: number) => void;
412
+ readonly parseChannels: (a: number, b: number, c: number, d: number) => void;
413
+ readonly parseConnection: (a: number, b: number, c: number, d: number) => void;
414
+ readonly parseContent: (a: number, b: number, c: number, d: number) => void;
415
+ readonly parseEvent: (a: number, b: number, c: number, d: number) => void;
416
+ readonly parseHistory: (a: number, b: number, c: number, d: number) => void;
417
+ readonly parseLivestreams: (a: number, b: number, c: number, d: number) => void;
418
+ readonly parseMe: (a: number, b: number, c: number, d: number) => void;
419
+ readonly parsePublicKey: (a: number, b: number, c: number, d: number) => void;
420
+ readonly parseSubscriptions: (a: number, b: number, c: number, d: number) => void;
421
+ readonly parseToken: (a: number, b: number, c: number, d: number) => void;
422
+ readonly parseWebhook: (a: number, b: number, c: number, d: number) => void;
423
+ readonly pinRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
424
+ readonly publicKeyRequest: (a: number, b: number) => void;
425
+ readonly retryAfterMs: (a: number, b: number) => void;
426
+ readonly sendRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
427
+ readonly session_closed: (a: number, b: number) => void;
428
+ readonly session_deadline: (a: number, b: number) => void;
429
+ readonly session_isConnected: (a: number) => number;
430
+ readonly session_isSubscribed: (a: number, b: number, c: number) => number;
431
+ readonly session_new: (a: number, b: number) => number;
432
+ readonly session_open: (a: number, b: number, c: number, d: number, e: number) => void;
433
+ readonly session_receive: (a: number, b: number, c: number, d: number, e: number) => void;
434
+ readonly session_refresh: (a: number, b: number, c: number, d: number, e: number) => void;
435
+ readonly session_tick: (a: number, b: number, c: number) => void;
436
+ readonly subscribeRequest: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
437
+ readonly subscriptionsRequest: (a: number, b: number, c: number, d: number) => void;
438
+ readonly timeoutRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
439
+ readonly tokenRequest: (a: number, b: number, c: number, d: number) => void;
440
+ readonly topLivestreamsRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
441
+ readonly unbanRequest: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
442
+ readonly unpinRequest: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
443
+ readonly unsubscribeRequests: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
444
+ readonly verifyWebhook: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
445
+ readonly webhookpublickey_new: (a: number, b: number, c: number) => void;
446
+ readonly webhookpublickey_verify: (a: number, b: number, c: number, d: number, e: number) => void;
447
+ readonly __wbindgen_export: (a: number, b: number) => number;
448
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
449
+ readonly __wbindgen_export3: (a: number) => void;
450
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
451
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
452
+ }
453
+
454
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
455
+
456
+ /**
457
+ * Instantiates the given `module`, which can either be bytes or
458
+ * a precompiled `WebAssembly.Module`.
459
+ *
460
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
461
+ *
462
+ * @returns {InitOutput}
463
+ */
464
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
465
+
466
+ /**
467
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
468
+ * for everything else, calls `WebAssembly.instantiate` directly.
469
+ *
470
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
471
+ *
472
+ * @returns {Promise<InitOutput>}
473
+ */
474
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;