UNPKG

5 kBMarkdownView Raw
1# client-typescript
2
3The official Typescript client library for the Noticebord API.
4
5# Installation
6
7To install, run the following command:
8
9NPM:
10
11
12```bash
13npm install noticebord-client
14```
15
16Yarn:
17
18```bash
19yarn add noticebord-client
20```
21
22CDN:
23
24The package is also availavable from [JsDelivr](https://www.jsdelivr.com/package/npm/noticebord-client) and [Unpkg](https://unpkg.com/browse/noticebord-client/).
25
26# Usage
27
28## NoticebordClient
29
30This is the entry point to the SDK.
31
32```ts
33const client = new NoticebordClient();
34
35// Providing a valid access token will allow you tyo perform action on behalf of users
36const client = new NoticebordClient(token);
37
38// You can also provide a custom base URL to connect to an instance of the web platform hosted elsewhere
39const client = new NoticebordClient(token, baseUrl);
40```
41
42## Tokens
43
44A token is needed to access restricted endpoints and perform actions on behalf of users.
45
46```ts
47// Use your request object to get a token from the server
48const token = await NoticebordClient.getToken({
49 email: "",
50 password: "",
51 deviceName: "",
52});
53
54// You can optionally provide a custom base url
55const token = await NoticebordClient.getToken({
56 email: "",
57 password: "",
58 deviceName: "",
59}, baseUrl);
60```
61
62## Notices
63
64This service allows you to perform operations related to notices.
65
66```ts
67// An instance of the notice service can be obtained from the Noticebord client.
68const service = client.notices
69
70// Creating a notice
71const notice = await service.createNotice({
72 title: "",
73 body: "",
74 topics: [],
75 anonymous: false,
76 public: true,
77});
78
79// Fetching notices
80const notices = await service.fetchNotices();
81
82// This endpoint is cursor-paginated, and you can optionally include a cursor to fetch results from a specific page.
83const notices = await service.fetchNotices(cursor);
84
85// Fetching a single notice
86const notices = await service.fetchNotice(noticeId);
87
88// Updating notices
89const notice = await service.updateNotice({
90 title: "",
91 body: "",
92 topics: [],
93 anonymous: false,
94 public: true,
95});
96
97// Deleting notices
98await service.deleteNotice(noticeId);
99```
100
101## Team Notices
102
103This service allows you to perform operations related to team notices.
104
105```ts
106// An instance of the team notice service can be obtained from the Noticebord client.
107const service = client.teamNotices
108
109// Creating a team notice
110const teamNotice = await service.createTeamNotice(teamId, {
111 title: "",
112 body: "",
113});
114
115// Fetching team notices
116const teamNotices = await service.fetchTeamNotices(teamId);
117
118// This endpoint is cursor-paginated, and you can include a cursor, to fetch results from a specific page.
119const teamNotices = await service.fetchTeamNotices(teamId, cursor);
120
121// Fetching a single team notice
122const teamNotice = await service.fetchTeamNotice(teamId, teamNoticeId);
123
124// Updating team notices
125const teamNotice = await service.updateTeamNotice(teamId, {
126 title: "",
127 body: "",
128});
129
130
131// Deleting team notices
132await service.deleteTeamNotice(teamId, teamNoticeId);
133```
134
135## Topics
136
137This service allows you to perform operations related to topics.
138
139```ts
140// An instance of the topic service can be obtained from the Noticebord client.
141const service = client.topics
142
143// Fetching topics
144const topics = await service.fetchTopics();
145
146// Fetching a single topic
147const topic = await service.fetchTopic(topicId);
148
149// Fetching topic notices
150const topicNotices = await service.fetchTopicNotices(topicId);
151
152// This endpoint is cursor-paginated, and you can include a cursor, to fetch results from a specific page.
153const topicNotices = await service.fetchTopicNotices(topicId, cursor);
154```
155
156## Teams
157
158This service allows you to perform operations related to teams.
159
160```ts
161// An instance of the team service can be obtained from the Noticebord client.
162const service = client.teams
163
164// Fetching teams
165const teams = await service.fetchTeams();
166
167// Fetching a single team
168const team = await service.fetchTeam(teamId);
169```
170
171## Users
172
173This service allows you to perform operations related to users.
174
175```ts
176// An instance of the user service can be obtained from the Noticebord client.
177const service = client.users
178
179// Fetching users
180const users = await service.fetchUsers();
181
182// Fetching a single user
183const user = await service.fetchUser(userId);
184
185// Fetching the current user
186const currentUser = await service.fetchCurrentUser();
187
188// Fetching user notices
189const userNotices = await service.fetchUsersNotices(UserId);
190
191// Fetching user notes (private notices)
192const userNotes = await service.fetchUserNotes(userId);
193```
194
195# Building From Source
196
197## 0. Prerequisites
198
199- Git
200
201## 1. Clone the repo from GitHub
202
203```bash
204git clone https://github.com/noticebord/client-typescript
205```
206
207## 2. Build the project
208
209NPM
210```bash
211npm run build
212```
213
214Yarn
215```bash
216yarn build
217```
218
219## 3. Running Tests
220
221NPM
222```bash
223npm run test
224```
225
226Yarn
227```bash
228yarn test
229```
230
231# Contributing
232
233This project is governed by the [Noticebord contribution guidelines](#).