sidechat.js 2.6.6 → 2.7.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.
- package/dist/classes/SidechatAPIClient.d.ts +166 -11
- package/dist/classes/SidechatAPIClient.d.ts.map +1 -1
- package/dist/index.cjs +853 -311
- package/dist/index.mjs +853 -311
- package/dist/types/SidechatTypes.d.ts +260 -9
- package/dist/types/SidechatTypes.d.ts.map +1 -1
- package/docs/sidechat.js/2.7.0/SidechatAPIClient.html +3 -0
- package/docs/sidechat.js/2.7.0/SidechatAPIError.html +3 -0
- package/docs/sidechat.js/2.7.0/SidechatColorList.html +3 -0
- package/docs/sidechat.js/2.7.0/classes_SidechatAPIClient.js.html +1897 -0
- package/docs/sidechat.js/2.7.0/classes_SidechatAPIError.js.html +16 -0
- package/docs/sidechat.js/2.7.0/classes_SidechatColorList.js.html +79 -0
- package/docs/sidechat.js/2.7.0/data/search.json +1 -0
- package/docs/sidechat.js/2.7.0/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/sidechat.js/2.7.0/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/sidechat.js/2.7.0/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/sidechat.js/2.7.0/global.html +3 -0
- package/docs/sidechat.js/2.7.0/index.html +4 -0
- package/docs/sidechat.js/2.7.0/scripts/core.js +726 -0
- package/docs/sidechat.js/2.7.0/scripts/core.min.js +23 -0
- package/docs/sidechat.js/2.7.0/scripts/resize.js +90 -0
- package/docs/sidechat.js/2.7.0/scripts/search.js +265 -0
- package/docs/sidechat.js/2.7.0/scripts/search.min.js +6 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/fuse.js +9 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/hljs-original.js +5171 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/hljs.js +1 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/popper.js +5 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/tippy.js +1 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/tocbot.js +672 -0
- package/docs/sidechat.js/2.7.0/scripts/third-party/tocbot.min.js +1 -0
- package/docs/sidechat.js/2.7.0/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/sidechat.js/2.7.0/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/sidechat.js/2.7.0/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/sidechat.js/2.7.0/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/sidechat.js/2.7.0/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/sidechat.js/2.7.0/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/sidechat.js/2.7.0/tutorial-Authentication.html +16 -0
- package/docs/sidechat.js/2.7.0/tutorial-Email Registration.html +6 -0
- package/docs/sidechat.js/2.7.0/tutorial-Feeds and Pagination.html +10 -0
- package/docs/sidechat.js/2.7.0/tutorial-Posting and Media.html +19 -0
- package/docs/sidechat.js/2.7.0/types_SidechatTypes.js.html +297 -0
- package/docs/tutorials/Authentication.md +63 -52
- package/docs/tutorials/Email Registration.md +19 -16
- package/docs/tutorials/Feeds and Pagination.md +45 -0
- package/docs/tutorials/Posting and Media.md +63 -0
- package/package.json +55 -55
- package/src/classes/SidechatAPIClient.js +477 -27
- package/src/types/SidechatTypes.js +294 -202
|
@@ -1,53 +1,64 @@
|
|
|
1
|
-
There are two supported methods of authenticating a Sidechat.js API client. We recommend the automatic method, but you may choose to use the manual method if your project involves multiple instances of `SidechatAPIClient`.
|
|
2
|
-
|
|
3
|
-
Go ahead and import `SidechatAPIClient` from the module:
|
|
4
|
-
|
|
5
|
-
```javascript
|
|
6
|
-
import { SidechatAPIClient } from "sidechat.js";
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
### Automatic method
|
|
11
|
-
|
|
12
|
-
First, create a new instance of the client:
|
|
13
|
-
|
|
14
|
-
```javascript
|
|
15
|
-
const API = new SidechatAPIClient();
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```javascript
|
|
28
|
-
const
|
|
29
|
-
await API.
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
If the
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```javascript
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
There are two supported methods of authenticating a Sidechat.js API client. We recommend the automatic method, but you may choose to use the manual method if your project involves multiple instances of `SidechatAPIClient`.
|
|
2
|
+
|
|
3
|
+
Go ahead and import `SidechatAPIClient` from the module:
|
|
4
|
+
|
|
5
|
+
```javascript
|
|
6
|
+
import { SidechatAPIClient } from "sidechat.js";
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Automatic method
|
|
11
|
+
|
|
12
|
+
First, create a new instance of the client:
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
const API = new SidechatAPIClient();
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The official app sends an identifier for the device along with every request, so it's a good idea to do the same. This should be something that stays the same every time your app runs on the same device:
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const deviceID = /* Stable ID for this device */;
|
|
22
|
+
API.setDeviceIdentifier(deviceID);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
For existing users, logging in is trivial. First, send the user a verification code to their phone number. Make sure the passed phone number is in a 10-digit format with no dashes, spaces, or parentheses:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
const phoneNumber = /* User's phone number */;
|
|
29
|
+
await API.loginViaSMS(phoneNumber);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
If the code never shows up, you can try sending it through Sidechat's backup SMS route by passing `true` as the second parameter. Sometimes the server will also ask for a captcha before it sends a code, in which case the response will have an `error_code` of `"captcha_required"`. sidechat.js can't solve those yet, so the best you can do is ask the user to try again later.
|
|
33
|
+
|
|
34
|
+
Then once the user has inputted the 6-character code into your application, verify it with the API. Codes can include letters, but they're not case-sensitive:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
const code = /* SMS verification code */;
|
|
38
|
+
await API.verifySMSCode(phoneNumber, code);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If the user already exists, calling those two functions will set the user token and all requests from here on out using this instance of the API client will be automatically authenticated.
|
|
42
|
+
|
|
43
|
+
If the user has not used Sidechat before, the `verifySMSCode` will return a `registrationID`, which you should store and then use to call the `setAge` function:
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
// Here "res" refers to the result of verifySMSCode()
|
|
47
|
+
const { registration_id } = res;
|
|
48
|
+
await API.setAge(18, registration_id);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`setAge` also sends the user's time zone, which defaults to the system time zone. If your code is running somewhere other than the user's device (like a server), pass their time zone as the third parameter.
|
|
52
|
+
|
|
53
|
+
Now the user should be logged in properly and future requests will be automatically authenticated. You may still need to [add an email address](tutorial-Email%20Registration.html) for most functionality.
|
|
54
|
+
|
|
55
|
+
### Manual method
|
|
56
|
+
|
|
57
|
+
You can pass a user token directly to the constructor initialization:
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
const token = /* User bearer token as a string */;
|
|
61
|
+
const API = new SidechatAPIClient(token);
|
|
62
|
+
```
|
|
63
|
+
|
|
53
64
|
All requests from here on out using this instance of the API client will automatically use the token passed to the constructor.
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
> You can only start this process once you have [authenticated as a user](tutorial-Authentication.html).
|
|
2
|
-
|
|
3
|
-
Start by sending a verification email to the user:
|
|
4
|
-
|
|
5
|
-
```javascript
|
|
6
|
-
const email = /* User's email address */;
|
|
7
|
-
await API.registerEmail(email);
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
Once the user has clicked the link in the verification email, verify that they've clicked it:
|
|
11
|
-
|
|
12
|
-
```javascript
|
|
13
|
-
await API.checkEmailVerification();
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
You should be verified!
|
|
1
|
+
> You can only start this process once you have [authenticated as a user](tutorial-Authentication.html).
|
|
2
|
+
|
|
3
|
+
Start by sending a verification email to the user:
|
|
4
|
+
|
|
5
|
+
```javascript
|
|
6
|
+
const email = /* User's email address */;
|
|
7
|
+
await API.registerEmail(email);
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Once the user has clicked the link in the verification email, verify that they've clicked it:
|
|
11
|
+
|
|
12
|
+
```javascript
|
|
13
|
+
await API.checkEmailVerification();
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
You should be verified!
|
|
17
|
+
|
|
18
|
+
> ### NOTE
|
|
19
|
+
> There's also a `verifyEmailWithThirdParty` method that verifies the user's school email by signing in with Google or Microsoft instead of clicking a link. It's experimental and I haven't tested it yet, so use it at your own risk.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
> You'll need to be [authenticated as a user](tutorial-Authentication.html) before fetching any posts.
|
|
2
|
+
|
|
3
|
+
There are two kinds of feeds: the home feed, which mixes posts from every group the user is in, and group feeds, which only show posts from one group.
|
|
4
|
+
|
|
5
|
+
### Home feed
|
|
6
|
+
|
|
7
|
+
The home feed can be sorted by `"for_you"`, `"hot"`, or `"recent"`:
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
const feed = await API.getHomeFeed("for_you");
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The official YikYak app also passes the ID of the user's school group as the second parameter. That's the group with a `group_join_type` of `"email_domain"`, which you can find with `getGroups()`.
|
|
14
|
+
|
|
15
|
+
Not everything in the home feed is a post. Each item in `feed.feed_items` has an `item_type`, and some of them are things like group suggestions instead of posts. If you only care about posts, filter the rest out:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const posts = feed.feed_items.filter((i) => i.item_type == "post").map((i) => i.post);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Group feeds
|
|
22
|
+
|
|
23
|
+
Group feeds can be sorted by `"hot"`, `"recent"`, or `"top"`:
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
const groupID = /* ID of a group */;
|
|
27
|
+
const { posts } = await API.getGroupPosts(groupID, "hot");
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Top posts can also be narrowed down to a time period of `"day"`, `"week"`, `"month"`, `"year"`, or `"all_time"`:
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
await API.getGroupPosts(groupID, "top", undefined, "week");
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Loading more
|
|
37
|
+
|
|
38
|
+
Feeds come back one page at a time along with a `cursor`. To get the next page, pass that cursor back into the same function:
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
const firstPage = await API.getGroupPosts(groupID, "recent");
|
|
42
|
+
const secondPage = await API.getGroupPosts(groupID, "recent", firstPage.cursor);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The home feed (`getHomeFeed`) and activity (`getActivity`) work the same way.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
> You'll need to be [authenticated as a user](tutorial-Authentication.html) and a member of the group you're posting in.
|
|
2
|
+
|
|
3
|
+
### Text posts
|
|
4
|
+
|
|
5
|
+
The simplest post just needs some text and a group ID:
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
const groupID = /* ID of the group to post in */;
|
|
9
|
+
const post = await API.createPost("hello world", groupID);
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`createPost` has a few more optional parameters, in this order: a list of assets, whether DMs are disabled, whether comments are disabled, whether the post is anonymous, the ID of a post to repost, a list of poll options, and a list of link attachment IDs. So an anonymous poll looks like this:
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
await API.createPost("best dining hall?", groupID, [], false, false, true, undefined, [
|
|
16
|
+
"North",
|
|
17
|
+
"South",
|
|
18
|
+
]);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Users can only make two posts a minute. If a post gets rejected, `createPost` throws a `SidechatAPIError` with the server's explanation as its message, so it's a good idea to show that message to the user.
|
|
22
|
+
|
|
23
|
+
### Comments
|
|
24
|
+
|
|
25
|
+
Commenting on a post works similarly:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
await API.createComment(post.id, "first", groupID);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Replies are where it gets a little confusing. To reply to a top-level comment, pass its ID as the fourth parameter. To reply to a reply, pass the reply's ID as the fourth parameter and the ID of the top-level comment it lives under as the fifth.
|
|
32
|
+
|
|
33
|
+
### Images and videos
|
|
34
|
+
|
|
35
|
+
Uploading media takes two steps: upload the file with `uploadAsset`, then attach it to a post. `uploadAsset` is built for React Native, so it expects a local file URI:
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
const url = await API.uploadAsset(/* local file URI */, "image/jpeg", "photo.jpg");
|
|
39
|
+
const assetID = url.split("/").pop();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then pass an asset object to `createPost`. The width and height should be the image's real dimensions:
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
await API.createPost("look at this", groupID, [
|
|
46
|
+
{ id: assetID, type: "image", content_type: "jpeg", width: 1080, height: 1350 },
|
|
47
|
+
]);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Videos work the same way, with a `type` of `"video"` and a `content_type` of `"mp4"` or `"mov"`. They have to be under 50MB. After posting, the server processes the video, which usually takes a few seconds. You can tell where it's at from the asset's `vod_status`, which goes from `not_started` to `ingest` to `complete`. Once it's complete, the asset's `url` points to an HLS stream (an `.m3u8` file), so you'll need a video player that supports HLS to play it.
|
|
51
|
+
|
|
52
|
+
### Links
|
|
53
|
+
|
|
54
|
+
Links are added as attachments. Create the attachment first, then pass its ID to `createPost`:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const attachment = await API.createLinkAttachment("https://github.com/micahlt/sidechat.js");
|
|
58
|
+
await API.createPost("cool library", groupID, [], false, false, false, undefined, undefined, [
|
|
59
|
+
attachment.id,
|
|
60
|
+
]);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The attachment comes back with a title, a shortened `display_url`, and a preview image, so you can show the user a preview before they post. YouTube links get a `type` of `"youtube"` instead of `"link"`.
|
package/package.json
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sidechat.js",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "A reverse-engineered API wrapper for Sidechat",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"source": "./src/index.js",
|
|
7
|
-
"main": "./dist/index.cjs",
|
|
8
|
-
"module": "./dist/index.mjs",
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"exports": {
|
|
11
|
-
".": {
|
|
12
|
-
"import": {
|
|
13
|
-
"types": "./dist/index.d.mts",
|
|
14
|
-
"default": "./dist/index.mjs"
|
|
15
|
-
},
|
|
16
|
-
"require": {
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"default": "./dist/index.cjs"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"./src/types": {
|
|
22
|
-
"types": "./dist/types/SidechatTypes.d.ts",
|
|
23
|
-
"default": "./src/types/SidechatTypes.js"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"scripts": {
|
|
27
|
-
"build": "rollup -c",
|
|
28
|
-
"dev": "rollup -c --watch",
|
|
29
|
-
"docs": "jsdoc --configure jsdoc.json --verbose",
|
|
30
|
-
"prepublish": "tsc",
|
|
31
|
-
"typegen": "tsc"
|
|
32
|
-
},
|
|
33
|
-
"repository": {
|
|
34
|
-
"type": "git",
|
|
35
|
-
"url": "git+https://github.com/micahlt/sidechat.js.git"
|
|
36
|
-
},
|
|
37
|
-
"author": "Micah Lindley",
|
|
38
|
-
"license": "MIT",
|
|
39
|
-
"bugs": {
|
|
40
|
-
"url": "https://github.com/micahlt/sidechat.js/issues"
|
|
41
|
-
},
|
|
42
|
-
"homepage": "https://github.com/micahlt/sidechat.js#readme",
|
|
43
|
-
"engines": {
|
|
44
|
-
"node": ">=18.0.0"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"clean-jsdoc-theme": "^4.3.0",
|
|
48
|
-
"dotenv": "^16.4.7",
|
|
49
|
-
"prompt-sync": "^4.2.0",
|
|
50
|
-
"rollup": "^2.79.2",
|
|
51
|
-
"rollup-plugin-copy": "^3.5.0",
|
|
52
|
-
"typescript": "^5.7.3"
|
|
53
|
-
},
|
|
54
|
-
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
55
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "sidechat.js",
|
|
3
|
+
"version": "2.7.0",
|
|
4
|
+
"description": "A reverse-engineered API wrapper for Sidechat",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"source": "./src/index.js",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"default": "./dist/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"./src/types": {
|
|
22
|
+
"types": "./dist/types/SidechatTypes.d.ts",
|
|
23
|
+
"default": "./src/types/SidechatTypes.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "rollup -c",
|
|
28
|
+
"dev": "rollup -c --watch",
|
|
29
|
+
"docs": "jsdoc --configure jsdoc.json --verbose",
|
|
30
|
+
"prepublish": "tsc",
|
|
31
|
+
"typegen": "tsc"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/micahlt/sidechat.js.git"
|
|
36
|
+
},
|
|
37
|
+
"author": "Micah Lindley",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/micahlt/sidechat.js/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/micahlt/sidechat.js#readme",
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"clean-jsdoc-theme": "^4.3.0",
|
|
48
|
+
"dotenv": "^16.4.7",
|
|
49
|
+
"prompt-sync": "^4.2.0",
|
|
50
|
+
"rollup": "^2.79.2",
|
|
51
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
52
|
+
"typescript": "^5.7.3"
|
|
53
|
+
},
|
|
54
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
55
|
+
}
|