Skip to content

Commit 29f23ca

Browse files
committed
Adding all type definitions to main zulip-js project, updated babel to copy type definition files to lib/ in build script
1 parent 43892b8 commit 29f23ca

17 files changed

+1012
-1
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"sinon": "^7.5.0"
3434
},
3535
"scripts": {
36-
"build": "babel -d lib/ src/",
36+
"build": "babel -D -d lib/ src/",
3737
"prepare": "npm run build",
3838
"prepublish": "npm run build",
3939
"lint": "eslint src test examples",

src/api.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Config } from "./zuliprc";
2+
import { ZulipSuccessResponse, ZulipErrorResponse } from "./types";
3+
4+
export function api(
5+
baseUrl: string,
6+
config: Config,
7+
method: any,
8+
params: any
9+
): Promise<ZulipSuccessResponse | ZulipErrorResponse>;

src/helper.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import fetch from "isomorphic-fetch";
2+
import FormData from "isomorphic-form-data";
3+
4+
export {
5+
fetch,
6+
FormData,
7+
}

src/index.d.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Config } from "./zuliprc";
2+
import { AccountsClient } from "./resources/accounts";
3+
import { StreamsClient } from "./resources/streams";
4+
import { QueuesClient } from "./resources/queues";
5+
import { EventsClient } from "./resources/events";
6+
import { UsersClient } from "./resources/users";
7+
import { EmojisClient } from "./resources/emojis";
8+
import { TypingClient } from "./resources/typing";
9+
import { ReactionsClient } from "./resources/reactions";
10+
import { ServerClient } from "./resources/server";
11+
import { FiltersClient } from "./resources/filters";
12+
import { MessagesClient } from "./resources/messages";
13+
14+
export type HttpMethod =
15+
| "GET"
16+
| "HEAD"
17+
| "POST"
18+
| "PUT"
19+
| "DELETE"
20+
| "TRACE"
21+
| "OPTIONS"
22+
| "CONNECT"
23+
| "PATCH";
24+
25+
export interface Params {
26+
[key: string]: any;
27+
[key: number]: any;
28+
}
29+
30+
export interface ZuliprcConfig {
31+
zuliprc: string;
32+
}
33+
34+
export interface ZulipClient {
35+
config: Config;
36+
callEndpoint: typeof callEndpoint;
37+
accounts: AccountsClient;
38+
streams: StreamsClient;
39+
messages: MessagesClient;
40+
queues: QueuesClient;
41+
events: EventsClient;
42+
users: UsersClient;
43+
emojis: EmojisClient;
44+
typing: TypingClient;
45+
reactions: ReactionsClient;
46+
server: ServerClient;
47+
filters: FiltersClient;
48+
}
49+
50+
export type InitialConfig = ZuliprcConfig | Pick<Config, "realm">;
51+
52+
export function getCallEndpoint(config: Config): typeof callEndpoint;
53+
54+
export function callEndpoint(endpoint: string, method: HttpMethod, params: Params): Promise<unknown>;
55+
56+
export function resources(config: Config): ZulipClient;
57+
58+
export function zulip(initialConfig: Partial<InitialConfig>): Promise<ZulipClient>;
59+
60+
export * from "./types";

src/resources/accounts.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Config } from "../zuliprc";
2+
import { RetrieverClient, ZulipSuccessResponse, ZulipErrorResponse } from "../types";
3+
4+
export type AccountsClient = RetrieverClient;
5+
6+
// SECTION GET ACCOUNTS
7+
// TODO Find documentation on Get Accounts
8+
export interface GetAccountsParams { }
9+
export type GetAccountsResponse = GetAccountsSuccess | GetAccountsError;
10+
export interface GetAccountsSuccess extends ZulipSuccessResponse { }
11+
export interface GetAccountsError extends ZulipErrorResponse { }
12+
13+
export default function accounts(config: Config): AccountsClient;

src/resources/emojis.d.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Config } from "../zuliprc";
2+
import { RetrieverClient, ZulipSuccessResponse, ZulipErrorResponse } from "../types";
3+
4+
export type EmojisClient = RetrieverClient;
5+
6+
// SECTION GET EMOJIS
7+
export interface GetEmojisParams { }
8+
9+
export type GetEmojisResponse = GetEmojisSuccess | GetEmojisError;
10+
11+
export interface GetEmojisSuccess extends ZulipSuccessResponse {
12+
emoji: {
13+
[key: number]: Emoji;
14+
}
15+
}
16+
17+
export interface Emoji {
18+
author: {
19+
email: string;
20+
full_name: string;
21+
id: number;
22+
},
23+
deactivated: boolean;
24+
id: string;
25+
name: string;
26+
source_url: string;
27+
}
28+
29+
export interface GetEmojisError extends ZulipErrorResponse { }
30+
31+
// SECTION UPLOAD EMOJIS
32+
// TODO Find documentation on Get Emojis
33+
export interface UploadEmojisParams { }
34+
35+
export type UploadEmojisResponse = UploadEmojisSuccess | UploadEmojisError;
36+
37+
export interface UploadEmojisSuccess extends ZulipSuccessResponse { }
38+
39+
export interface UploadEmojisError extends ZulipErrorResponse { }
40+
41+
42+
export default function emojis(config: Config): EmojisClient;

src/resources/events.d.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Config } from "../zuliprc";
2+
import { RetrieverClient, ZulipSuccessResponse, ZulipErrorResponse } from "../types";
3+
4+
export type EventsClient = RetrieverClient;
5+
6+
// SECTION GET EVENTS
7+
export interface GetEventsParams {
8+
/** "1375801870:2942" No The ID of a queue that you registered via POST /api/v1/register (see Register a queue). */
9+
queue_id?: string;
10+
/** -1 No The highest event ID in this queue that you've received and wish to acknowledge. See the code for call_on_each_event in the zulip Python module for an example implementation of correctly processing each event exactly once. */
11+
last_event_id?: number;
12+
/** true No Set to true if the client is requesting a nonblocking reply. If not specified, the request will block until either a new event is available or a few minutes have passed, in which case the server will send the client a heartbeat event. Defaults to false. */
13+
dont_block?: boolean;
14+
}
15+
16+
export type GetEventsResponse = GetEventsSuccess | GetEventsError;
17+
18+
export interface GetEventsSuccess extends ZulipSuccessResponse {
19+
events: Event[]
20+
}
21+
22+
export type Event = MessageEvent | any;
23+
24+
export interface MessageEvent {
25+
avatar_url: string;
26+
client: string;
27+
content: string;
28+
content_type: string;
29+
display_recipient: string;
30+
id: number;
31+
recipient_id: number;
32+
sender_email: string;
33+
sender_full_name: string;
34+
sender_id: number;
35+
sender_realm_str: string;
36+
sender_short_name: string;
37+
subject: string;
38+
subject_links: string[],
39+
timestamp: number;
40+
type: string;
41+
}
42+
43+
export interface GetEventsError extends ZulipErrorResponse {
44+
code: string;
45+
queue_id: string;
46+
}
47+
48+
export function events(config: Config): EventsClient;

src/resources/filters.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Config } from "../zuliprc";
2+
import { RetrieverClient } from "../types";
3+
4+
export type FiltersClient = RetrieverClient;
5+
6+
// SECTION GET FILTERS FOR REALM
7+
// TODO Find documentation on Get Filters for Realm
8+
9+
export function filters(config: Config): FiltersClient;

0 commit comments

Comments
 (0)