sidechat.js 2.0.5 → 2.1.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 +45 -3
- package/dist/classes/SidechatAPIClient.d.ts.map +1 -1
- package/dist/index.cjs +106 -3
- package/dist/index.mjs +106 -3
- package/dist/types/SidechatTypes.d.ts +96 -7
- package/dist/types/SidechatTypes.d.ts.map +1 -1
- package/docs/sidechat.js/2.0.6/SidechatAPIClient.html +3 -0
- package/docs/sidechat.js/2.0.6/SidechatAPIError.html +3 -0
- package/docs/sidechat.js/2.0.6/classes_SidechatAPIClient.js.html +462 -0
- package/docs/sidechat.js/2.0.6/classes_SidechatAPIError.js.html +16 -0
- package/docs/sidechat.js/2.0.6/data/search.json +1 -0
- package/docs/sidechat.js/2.0.6/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/sidechat.js/2.0.6/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/sidechat.js/2.0.6/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/sidechat.js/2.0.6/global.html +3 -0
- package/docs/sidechat.js/2.0.6/index.html +4 -0
- package/docs/sidechat.js/2.0.6/scripts/core.js +702 -0
- package/docs/sidechat.js/2.0.6/scripts/core.min.js +23 -0
- package/docs/sidechat.js/2.0.6/scripts/resize.js +90 -0
- package/docs/sidechat.js/2.0.6/scripts/search.js +265 -0
- package/docs/sidechat.js/2.0.6/scripts/search.min.js +6 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/fuse.js +9 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/hljs-original.js +5171 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/hljs.js +1 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/popper.js +5 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/tippy.js +1 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/tocbot.js +672 -0
- package/docs/sidechat.js/2.0.6/scripts/third-party/tocbot.min.js +1 -0
- package/docs/sidechat.js/2.0.6/styles/clean-jsdoc-theme-base.css +975 -0
- package/docs/sidechat.js/2.0.6/styles/clean-jsdoc-theme-dark.css +407 -0
- package/docs/sidechat.js/2.0.6/styles/clean-jsdoc-theme-light.css +388 -0
- package/docs/sidechat.js/2.0.6/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/sidechat.js/2.0.6/tutorial-Authentication.html +13 -0
- package/docs/sidechat.js/2.0.6/tutorial-Email Registration.html +6 -0
- package/docs/sidechat.js/2.0.6/types_SidechatTypes.js.html +114 -0
- package/docs/sidechat.js/2.1.0/SidechatAPIClient.html +3 -0
- package/docs/sidechat.js/2.1.0/SidechatAPIError.html +3 -0
- package/docs/sidechat.js/2.1.0/classes_SidechatAPIClient.js.html +528 -0
- package/docs/sidechat.js/2.1.0/classes_SidechatAPIError.js.html +16 -0
- package/docs/sidechat.js/2.1.0/data/search.json +1 -0
- package/docs/sidechat.js/2.1.0/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/sidechat.js/2.1.0/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/sidechat.js/2.1.0/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/sidechat.js/2.1.0/global.html +3 -0
- package/docs/sidechat.js/2.1.0/index.html +4 -0
- package/docs/sidechat.js/2.1.0/scripts/core.js +702 -0
- package/docs/sidechat.js/2.1.0/scripts/core.min.js +23 -0
- package/docs/sidechat.js/2.1.0/scripts/resize.js +90 -0
- package/docs/sidechat.js/2.1.0/scripts/search.js +265 -0
- package/docs/sidechat.js/2.1.0/scripts/search.min.js +6 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/fuse.js +9 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/hljs-original.js +5171 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/hljs.js +1 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/popper.js +5 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/tippy.js +1 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/tocbot.js +672 -0
- package/docs/sidechat.js/2.1.0/scripts/third-party/tocbot.min.js +1 -0
- package/docs/sidechat.js/2.1.0/styles/clean-jsdoc-theme-base.css +975 -0
- package/docs/sidechat.js/2.1.0/styles/clean-jsdoc-theme-dark.css +407 -0
- package/docs/sidechat.js/2.1.0/styles/clean-jsdoc-theme-light.css +388 -0
- package/docs/sidechat.js/2.1.0/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/sidechat.js/2.1.0/tutorial-Authentication.html +13 -0
- package/docs/sidechat.js/2.1.0/tutorial-Email Registration.html +6 -0
- package/docs/sidechat.js/2.1.0/types_SidechatTypes.js.html +134 -0
- package/package.json +54 -53
- package/src/classes/SidechatAPIClient.js +106 -3
- package/src/index.js +1 -1
- package/src/tests/basicTest.js +6 -4
- package/src/types/SidechatTypes.js +44 -6
|
@@ -19,6 +19,7 @@ declare class SidechatAPIClient {
|
|
|
19
19
|
* Default headers for every API request
|
|
20
20
|
* @type {Object}
|
|
21
21
|
* @static
|
|
22
|
+
* @constant
|
|
22
23
|
*/
|
|
23
24
|
defaultHeaders: any;
|
|
24
25
|
/**
|
|
@@ -30,19 +31,22 @@ declare class SidechatAPIClient {
|
|
|
30
31
|
/**
|
|
31
32
|
* Initiate the login process with a phone number. Should be followed up with verifySMSCode().
|
|
32
33
|
* @method
|
|
34
|
+
* @since 1.0.0
|
|
33
35
|
* @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to
|
|
34
36
|
*/
|
|
35
37
|
loginViaSMS: (phoneNumber: number) => Promise<any>;
|
|
36
38
|
/**
|
|
37
|
-
* Verify the code sent via SMS with loginViaSMS().
|
|
39
|
+
* Verify the code sent via SMS with loginViaSMS(). If this function succeeds, the user will be authenticated for future requests.
|
|
38
40
|
* @method
|
|
41
|
+
* @since 1.0.0
|
|
39
42
|
* @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to
|
|
40
43
|
* @param {String} code - the verification code
|
|
41
44
|
*/
|
|
42
45
|
verifySMSCode: (phoneNumber: number, code: string) => Promise<any>;
|
|
43
46
|
/**
|
|
44
|
-
* Set the user's age
|
|
47
|
+
* Set the user's age. If this function succeeds, the user will be authenticated for future requests.
|
|
45
48
|
* @method
|
|
49
|
+
* @since 1.0.0
|
|
46
50
|
* @param {Number} age - user's age in years
|
|
47
51
|
* @param {String} registrationID - the registration ID generated by verifySMSCode()
|
|
48
52
|
*/
|
|
@@ -50,6 +54,7 @@ declare class SidechatAPIClient {
|
|
|
50
54
|
/**
|
|
51
55
|
* Initiate the email setup process. Should be followed up with checkEmailVerification().
|
|
52
56
|
* @method
|
|
57
|
+
* @since 1.0.0
|
|
53
58
|
* @param {String} email - school email address to send verification code to
|
|
54
59
|
* @tutorial Email Registration
|
|
55
60
|
*/
|
|
@@ -57,23 +62,35 @@ declare class SidechatAPIClient {
|
|
|
57
62
|
/**
|
|
58
63
|
* Check is the user's email is verified.
|
|
59
64
|
* @method
|
|
65
|
+
* @since 1.0.0
|
|
60
66
|
*/
|
|
61
67
|
checkEmailVerification: () => Promise<any>;
|
|
62
68
|
/**
|
|
63
69
|
* Set the device ID of the current user
|
|
64
70
|
* @method
|
|
71
|
+
* @since 1.0.0
|
|
65
72
|
* @param {String} deviceId - the device ID to set
|
|
66
73
|
*/
|
|
67
74
|
setDeviceID: (deviceID: any) => Promise<any>;
|
|
68
75
|
/**
|
|
69
76
|
* Get updated status for user and group
|
|
70
77
|
* @method
|
|
71
|
-
* @
|
|
78
|
+
* @since 1.0.0
|
|
79
|
+
* @deprecated since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
|
|
80
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
72
81
|
*/
|
|
73
82
|
getUserAndGroup: (groupID?: string) => Promise<any>;
|
|
83
|
+
/**
|
|
84
|
+
* Get updated status for user and group
|
|
85
|
+
* @method
|
|
86
|
+
* @since 2.1.0
|
|
87
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
88
|
+
*/
|
|
89
|
+
getUpdates: (groupID?: string) => Promise<any>;
|
|
74
90
|
/**
|
|
75
91
|
* Fetches posts from the specified category in a group
|
|
76
92
|
* @method
|
|
93
|
+
* @since 1.0.0
|
|
77
94
|
* @param {String} groupID - group ID
|
|
78
95
|
* @param {"hot"|"recent"|"top"} category - category to filter posts
|
|
79
96
|
* @param {SidechatCursorString} [cursor] - cursor string
|
|
@@ -83,6 +100,7 @@ declare class SidechatAPIClient {
|
|
|
83
100
|
/**
|
|
84
101
|
* Upvote or downvote, or unvote a post
|
|
85
102
|
* @method
|
|
103
|
+
* @since 2.0.0-alpha.0
|
|
86
104
|
* @param {String} postID - post ID to vote on
|
|
87
105
|
* @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote
|
|
88
106
|
*/
|
|
@@ -90,6 +108,7 @@ declare class SidechatAPIClient {
|
|
|
90
108
|
/**
|
|
91
109
|
* Get all the commments on a post
|
|
92
110
|
* @method
|
|
111
|
+
* @since 2.0.0-alpha.0
|
|
93
112
|
* @param {String} postID - post ID to get comments for
|
|
94
113
|
* @returns {SidechatPostOrComment[]} list of comments
|
|
95
114
|
*/
|
|
@@ -97,8 +116,31 @@ declare class SidechatAPIClient {
|
|
|
97
116
|
/**
|
|
98
117
|
* Gets groups to be displayed on the "Explore Groups" page
|
|
99
118
|
* @method
|
|
119
|
+
* @since 2.0.0-alpha.0
|
|
100
120
|
* @returns {SidechatGroup[]}
|
|
101
121
|
*/
|
|
102
122
|
getAvailableGroups: () => SidechatGroup[];
|
|
123
|
+
/**
|
|
124
|
+
* Retrieves the entire accessible asset library. Be warned that as of the time of this documentation, it's a 1.5MB JSON download and this request is very expensive.
|
|
125
|
+
* @method
|
|
126
|
+
* @since 2.0.6
|
|
127
|
+
* @returns {SidechatLibraryAsset[]}
|
|
128
|
+
*/
|
|
129
|
+
getAssetLibrary: () => SidechatLibraryAsset[];
|
|
130
|
+
/**
|
|
131
|
+
* Gets the current authenticated user and a list of the groups of which they are members.
|
|
132
|
+
* @method
|
|
133
|
+
* @since 2.1.0
|
|
134
|
+
* @returns {SidechatCurrentUser}
|
|
135
|
+
*/
|
|
136
|
+
getCurrentUser: () => SidechatCurrentUser;
|
|
137
|
+
/**
|
|
138
|
+
* Gets the metadata of a group from its ID
|
|
139
|
+
* @method
|
|
140
|
+
* @since 2.1.0
|
|
141
|
+
* @param {String} [groupID] - alphanumeric ID of a group to get. Falls back to user's primary group.
|
|
142
|
+
* @returns {SidechatGroup}
|
|
143
|
+
*/
|
|
144
|
+
getGroupMetadata: (groupID?: string) => SidechatGroup;
|
|
103
145
|
}
|
|
104
146
|
//# sourceMappingURL=SidechatAPIClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidechatAPIClient.d.ts","sourceRoot":"","sources":["../../src/classes/SidechatAPIClient.js"],"names":[],"mappings":";AAGA;;;;GAIG;AACH;
|
|
1
|
+
{"version":3,"file":"SidechatAPIClient.d.ts","sourceRoot":"","sources":["../../src/classes/SidechatAPIClient.js"],"names":[],"mappings":";AAGA;;;;GAIG;AACH;IAiBE;;;OAGG;IACH,uCAIC;IAxBD;;;SAGK;IACL,6BAAU;IACV;;;;;OAKG;IACH,oBAGE;IAYF;;;;OAIG;IACH,6CAEE;IAEF;;;;;OAKG;IACH,mDAgBE;IAEF;;;;;;OAMG;IACH,mEAsBE;IAEF;;;;;;OAMG;IACH,8DAyBE;IAEF;;;;;;OAMG;IACH,+CA2BE;IAEF;;;;OAIG;IACH,2CAyBE;IAEF;;;;;OAKG;IACH,6CA2BE;IAEF;;;;;;OAMG;IACH,oDAGE;IAEF;;;;;OAKG;IACH,+CAqBE;IAEF;;;;;;;;OAQG;IACH,4CAJW,KAAK,GAAC,QAAQ,GAAC,KAAK,2DA2B7B;IAEF;;;;;;OAMG;IACH,sEAsBE;IAEF;;;;;;OAMG;IACH,qCAFa,uBAAuB,CAqElC;IAEF;;;;;OAKG;IACH,0BAFa,eAAe,CAoB1B;IAEF;;;;;OAKG;IACH,uBAFa,sBAAsB,CAoBjC;IAEF;;;;;OAKG;IACH,0CAkBE;IAEF;;;;;;OAMG;IACH,sDAkBE;CACH"}
|
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ class SidechatAPIClient {
|
|
|
29
29
|
* Default headers for every API request
|
|
30
30
|
* @type {Object}
|
|
31
31
|
* @static
|
|
32
|
+
* @constant
|
|
32
33
|
*/
|
|
33
34
|
defaultHeaders = {
|
|
34
35
|
Accept: "application/json",
|
|
@@ -57,6 +58,7 @@ class SidechatAPIClient {
|
|
|
57
58
|
/**
|
|
58
59
|
* Initiate the login process with a phone number. Should be followed up with verifySMSCode().
|
|
59
60
|
* @method
|
|
61
|
+
* @since 1.0.0
|
|
60
62
|
* @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to
|
|
61
63
|
*/
|
|
62
64
|
loginViaSMS = async (phoneNumber) => {
|
|
@@ -78,8 +80,9 @@ class SidechatAPIClient {
|
|
|
78
80
|
};
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
|
-
* Verify the code sent via SMS with loginViaSMS().
|
|
83
|
+
* Verify the code sent via SMS with loginViaSMS(). If this function succeeds, the user will be authenticated for future requests.
|
|
82
84
|
* @method
|
|
85
|
+
* @since 1.0.0
|
|
83
86
|
* @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to
|
|
84
87
|
* @param {String} code - the verification code
|
|
85
88
|
*/
|
|
@@ -108,8 +111,9 @@ class SidechatAPIClient {
|
|
|
108
111
|
};
|
|
109
112
|
|
|
110
113
|
/**
|
|
111
|
-
* Set the user's age
|
|
114
|
+
* Set the user's age. If this function succeeds, the user will be authenticated for future requests.
|
|
112
115
|
* @method
|
|
116
|
+
* @since 1.0.0
|
|
113
117
|
* @param {Number} age - user's age in years
|
|
114
118
|
* @param {String} registrationID - the registration ID generated by verifySMSCode()
|
|
115
119
|
*/
|
|
@@ -143,6 +147,7 @@ class SidechatAPIClient {
|
|
|
143
147
|
/**
|
|
144
148
|
* Initiate the email setup process. Should be followed up with checkEmailVerification().
|
|
145
149
|
* @method
|
|
150
|
+
* @since 1.0.0
|
|
146
151
|
* @param {String} email - school email address to send verification code to
|
|
147
152
|
* @tutorial Email Registration
|
|
148
153
|
*/
|
|
@@ -178,6 +183,7 @@ class SidechatAPIClient {
|
|
|
178
183
|
/**
|
|
179
184
|
* Check is the user's email is verified.
|
|
180
185
|
* @method
|
|
186
|
+
* @since 1.0.0
|
|
181
187
|
*/
|
|
182
188
|
checkEmailVerification = async () => {
|
|
183
189
|
if (!this.userToken) {
|
|
@@ -209,6 +215,7 @@ class SidechatAPIClient {
|
|
|
209
215
|
/**
|
|
210
216
|
* Set the device ID of the current user
|
|
211
217
|
* @method
|
|
218
|
+
* @since 1.0.0
|
|
212
219
|
* @param {String} deviceId - the device ID to set
|
|
213
220
|
*/
|
|
214
221
|
setDeviceID = async (deviceID) => {
|
|
@@ -243,9 +250,22 @@ class SidechatAPIClient {
|
|
|
243
250
|
/**
|
|
244
251
|
* Get updated status for user and group
|
|
245
252
|
* @method
|
|
246
|
-
* @
|
|
253
|
+
* @since 1.0.0
|
|
254
|
+
* @deprecated since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
|
|
255
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
247
256
|
*/
|
|
248
257
|
getUserAndGroup = async (groupID = "") => {
|
|
258
|
+
const json = await this.getUpdates(groupID);
|
|
259
|
+
return json;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Get updated status for user and group
|
|
264
|
+
* @method
|
|
265
|
+
* @since 2.1.0
|
|
266
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
267
|
+
*/
|
|
268
|
+
getUpdates = async (groupID = "") => {
|
|
249
269
|
if (!this.userToken) {
|
|
250
270
|
throw new SidechatAPIError("User is not authenticated.");
|
|
251
271
|
}
|
|
@@ -271,6 +291,7 @@ class SidechatAPIClient {
|
|
|
271
291
|
/**
|
|
272
292
|
* Fetches posts from the specified category in a group
|
|
273
293
|
* @method
|
|
294
|
+
* @since 1.0.0
|
|
274
295
|
* @param {String} groupID - group ID
|
|
275
296
|
* @param {"hot"|"recent"|"top"} category - category to filter posts
|
|
276
297
|
* @param {SidechatCursorString} [cursor] - cursor string
|
|
@@ -304,6 +325,7 @@ class SidechatAPIClient {
|
|
|
304
325
|
/**
|
|
305
326
|
* Upvote or downvote, or unvote a post
|
|
306
327
|
* @method
|
|
328
|
+
* @since 2.0.0-alpha.0
|
|
307
329
|
* @param {String} postID - post ID to vote on
|
|
308
330
|
* @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote
|
|
309
331
|
*/
|
|
@@ -334,6 +356,7 @@ class SidechatAPIClient {
|
|
|
334
356
|
/**
|
|
335
357
|
* Get all the commments on a post
|
|
336
358
|
* @method
|
|
359
|
+
* @since 2.0.0-alpha.0
|
|
337
360
|
* @param {String} postID - post ID to get comments for
|
|
338
361
|
* @returns {SidechatPostOrComment[]} list of comments
|
|
339
362
|
*/
|
|
@@ -409,6 +432,7 @@ class SidechatAPIClient {
|
|
|
409
432
|
/**
|
|
410
433
|
* Gets groups to be displayed on the "Explore Groups" page
|
|
411
434
|
* @method
|
|
435
|
+
* @since 2.0.0-alpha.0
|
|
412
436
|
* @returns {SidechatGroup[]}
|
|
413
437
|
*/
|
|
414
438
|
getAvailableGroups = async () => {
|
|
@@ -430,6 +454,85 @@ class SidechatAPIClient {
|
|
|
430
454
|
throw new SidechatAPIError(`Failed to get groups from explore.`);
|
|
431
455
|
}
|
|
432
456
|
};
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Retrieves the entire accessible asset library. Be warned that as of the time of this documentation, it's a 1.5MB JSON download and this request is very expensive.
|
|
460
|
+
* @method
|
|
461
|
+
* @since 2.0.6
|
|
462
|
+
* @returns {SidechatLibraryAsset[]}
|
|
463
|
+
*/
|
|
464
|
+
getAssetLibrary = async () => {
|
|
465
|
+
if (!this.userToken) {
|
|
466
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
467
|
+
}
|
|
468
|
+
try {
|
|
469
|
+
const res = await fetch(`https://api.sidechat.lol/v1/assets/library`, {
|
|
470
|
+
method: "GET",
|
|
471
|
+
headers: {
|
|
472
|
+
...this.defaultHeaders,
|
|
473
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
474
|
+
},
|
|
475
|
+
});
|
|
476
|
+
const json = await res.json();
|
|
477
|
+
return await json.items;
|
|
478
|
+
} catch (err) {
|
|
479
|
+
console.error(err);
|
|
480
|
+
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Gets the current authenticated user and a list of the groups of which they are members.
|
|
486
|
+
* @method
|
|
487
|
+
* @since 2.1.0
|
|
488
|
+
* @returns {SidechatCurrentUser}
|
|
489
|
+
*/
|
|
490
|
+
getCurrentUser = async () => {
|
|
491
|
+
if (!this.userToken) {
|
|
492
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
493
|
+
}
|
|
494
|
+
try {
|
|
495
|
+
const res = await fetch(`https://api.sidechat.lol/v1/users/me`, {
|
|
496
|
+
method: "GET",
|
|
497
|
+
headers: {
|
|
498
|
+
...this.defaultHeaders,
|
|
499
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
500
|
+
},
|
|
501
|
+
});
|
|
502
|
+
const json = await res.json();
|
|
503
|
+
return await json;
|
|
504
|
+
} catch (err) {
|
|
505
|
+
console.error(err);
|
|
506
|
+
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Gets the metadata of a group from its ID
|
|
512
|
+
* @method
|
|
513
|
+
* @since 2.1.0
|
|
514
|
+
* @param {String} [groupID] - alphanumeric ID of a group to get. Falls back to user's primary group.
|
|
515
|
+
* @returns {SidechatGroup}
|
|
516
|
+
*/
|
|
517
|
+
getGroupMetadata = async (groupID = "") => {
|
|
518
|
+
if (!this.userToken) {
|
|
519
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
520
|
+
}
|
|
521
|
+
try {
|
|
522
|
+
const res = await fetch(`https://api.sidechat.lol/v1/groups/${groupID}`, {
|
|
523
|
+
method: "GET",
|
|
524
|
+
headers: {
|
|
525
|
+
...this.defaultHeaders,
|
|
526
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
const json = await res.json();
|
|
530
|
+
return await json.group;
|
|
531
|
+
} catch (err) {
|
|
532
|
+
console.error(err);
|
|
533
|
+
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
433
536
|
}
|
|
434
537
|
|
|
435
538
|
exports.SidechatAPIClient = SidechatAPIClient;
|
package/dist/index.mjs
CHANGED
|
@@ -25,6 +25,7 @@ class SidechatAPIClient {
|
|
|
25
25
|
* Default headers for every API request
|
|
26
26
|
* @type {Object}
|
|
27
27
|
* @static
|
|
28
|
+
* @constant
|
|
28
29
|
*/
|
|
29
30
|
defaultHeaders = {
|
|
30
31
|
Accept: "application/json",
|
|
@@ -53,6 +54,7 @@ class SidechatAPIClient {
|
|
|
53
54
|
/**
|
|
54
55
|
* Initiate the login process with a phone number. Should be followed up with verifySMSCode().
|
|
55
56
|
* @method
|
|
57
|
+
* @since 1.0.0
|
|
56
58
|
* @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to
|
|
57
59
|
*/
|
|
58
60
|
loginViaSMS = async (phoneNumber) => {
|
|
@@ -74,8 +76,9 @@ class SidechatAPIClient {
|
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
/**
|
|
77
|
-
* Verify the code sent via SMS with loginViaSMS().
|
|
79
|
+
* Verify the code sent via SMS with loginViaSMS(). If this function succeeds, the user will be authenticated for future requests.
|
|
78
80
|
* @method
|
|
81
|
+
* @since 1.0.0
|
|
79
82
|
* @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to
|
|
80
83
|
* @param {String} code - the verification code
|
|
81
84
|
*/
|
|
@@ -104,8 +107,9 @@ class SidechatAPIClient {
|
|
|
104
107
|
};
|
|
105
108
|
|
|
106
109
|
/**
|
|
107
|
-
* Set the user's age
|
|
110
|
+
* Set the user's age. If this function succeeds, the user will be authenticated for future requests.
|
|
108
111
|
* @method
|
|
112
|
+
* @since 1.0.0
|
|
109
113
|
* @param {Number} age - user's age in years
|
|
110
114
|
* @param {String} registrationID - the registration ID generated by verifySMSCode()
|
|
111
115
|
*/
|
|
@@ -139,6 +143,7 @@ class SidechatAPIClient {
|
|
|
139
143
|
/**
|
|
140
144
|
* Initiate the email setup process. Should be followed up with checkEmailVerification().
|
|
141
145
|
* @method
|
|
146
|
+
* @since 1.0.0
|
|
142
147
|
* @param {String} email - school email address to send verification code to
|
|
143
148
|
* @tutorial Email Registration
|
|
144
149
|
*/
|
|
@@ -174,6 +179,7 @@ class SidechatAPIClient {
|
|
|
174
179
|
/**
|
|
175
180
|
* Check is the user's email is verified.
|
|
176
181
|
* @method
|
|
182
|
+
* @since 1.0.0
|
|
177
183
|
*/
|
|
178
184
|
checkEmailVerification = async () => {
|
|
179
185
|
if (!this.userToken) {
|
|
@@ -205,6 +211,7 @@ class SidechatAPIClient {
|
|
|
205
211
|
/**
|
|
206
212
|
* Set the device ID of the current user
|
|
207
213
|
* @method
|
|
214
|
+
* @since 1.0.0
|
|
208
215
|
* @param {String} deviceId - the device ID to set
|
|
209
216
|
*/
|
|
210
217
|
setDeviceID = async (deviceID) => {
|
|
@@ -239,9 +246,22 @@ class SidechatAPIClient {
|
|
|
239
246
|
/**
|
|
240
247
|
* Get updated status for user and group
|
|
241
248
|
* @method
|
|
242
|
-
* @
|
|
249
|
+
* @since 1.0.0
|
|
250
|
+
* @deprecated since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
|
|
251
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
243
252
|
*/
|
|
244
253
|
getUserAndGroup = async (groupID = "") => {
|
|
254
|
+
const json = await this.getUpdates(groupID);
|
|
255
|
+
return json;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Get updated status for user and group
|
|
260
|
+
* @method
|
|
261
|
+
* @since 2.1.0
|
|
262
|
+
* @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
|
|
263
|
+
*/
|
|
264
|
+
getUpdates = async (groupID = "") => {
|
|
245
265
|
if (!this.userToken) {
|
|
246
266
|
throw new SidechatAPIError("User is not authenticated.");
|
|
247
267
|
}
|
|
@@ -267,6 +287,7 @@ class SidechatAPIClient {
|
|
|
267
287
|
/**
|
|
268
288
|
* Fetches posts from the specified category in a group
|
|
269
289
|
* @method
|
|
290
|
+
* @since 1.0.0
|
|
270
291
|
* @param {String} groupID - group ID
|
|
271
292
|
* @param {"hot"|"recent"|"top"} category - category to filter posts
|
|
272
293
|
* @param {SidechatCursorString} [cursor] - cursor string
|
|
@@ -300,6 +321,7 @@ class SidechatAPIClient {
|
|
|
300
321
|
/**
|
|
301
322
|
* Upvote or downvote, or unvote a post
|
|
302
323
|
* @method
|
|
324
|
+
* @since 2.0.0-alpha.0
|
|
303
325
|
* @param {String} postID - post ID to vote on
|
|
304
326
|
* @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote
|
|
305
327
|
*/
|
|
@@ -330,6 +352,7 @@ class SidechatAPIClient {
|
|
|
330
352
|
/**
|
|
331
353
|
* Get all the commments on a post
|
|
332
354
|
* @method
|
|
355
|
+
* @since 2.0.0-alpha.0
|
|
333
356
|
* @param {String} postID - post ID to get comments for
|
|
334
357
|
* @returns {SidechatPostOrComment[]} list of comments
|
|
335
358
|
*/
|
|
@@ -405,6 +428,7 @@ class SidechatAPIClient {
|
|
|
405
428
|
/**
|
|
406
429
|
* Gets groups to be displayed on the "Explore Groups" page
|
|
407
430
|
* @method
|
|
431
|
+
* @since 2.0.0-alpha.0
|
|
408
432
|
* @returns {SidechatGroup[]}
|
|
409
433
|
*/
|
|
410
434
|
getAvailableGroups = async () => {
|
|
@@ -426,6 +450,85 @@ class SidechatAPIClient {
|
|
|
426
450
|
throw new SidechatAPIError(`Failed to get groups from explore.`);
|
|
427
451
|
}
|
|
428
452
|
};
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Retrieves the entire accessible asset library. Be warned that as of the time of this documentation, it's a 1.5MB JSON download and this request is very expensive.
|
|
456
|
+
* @method
|
|
457
|
+
* @since 2.0.6
|
|
458
|
+
* @returns {SidechatLibraryAsset[]}
|
|
459
|
+
*/
|
|
460
|
+
getAssetLibrary = async () => {
|
|
461
|
+
if (!this.userToken) {
|
|
462
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
463
|
+
}
|
|
464
|
+
try {
|
|
465
|
+
const res = await fetch(`https://api.sidechat.lol/v1/assets/library`, {
|
|
466
|
+
method: "GET",
|
|
467
|
+
headers: {
|
|
468
|
+
...this.defaultHeaders,
|
|
469
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
470
|
+
},
|
|
471
|
+
});
|
|
472
|
+
const json = await res.json();
|
|
473
|
+
return await json.items;
|
|
474
|
+
} catch (err) {
|
|
475
|
+
console.error(err);
|
|
476
|
+
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Gets the current authenticated user and a list of the groups of which they are members.
|
|
482
|
+
* @method
|
|
483
|
+
* @since 2.1.0
|
|
484
|
+
* @returns {SidechatCurrentUser}
|
|
485
|
+
*/
|
|
486
|
+
getCurrentUser = async () => {
|
|
487
|
+
if (!this.userToken) {
|
|
488
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
489
|
+
}
|
|
490
|
+
try {
|
|
491
|
+
const res = await fetch(`https://api.sidechat.lol/v1/users/me`, {
|
|
492
|
+
method: "GET",
|
|
493
|
+
headers: {
|
|
494
|
+
...this.defaultHeaders,
|
|
495
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
const json = await res.json();
|
|
499
|
+
return await json;
|
|
500
|
+
} catch (err) {
|
|
501
|
+
console.error(err);
|
|
502
|
+
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Gets the metadata of a group from its ID
|
|
508
|
+
* @method
|
|
509
|
+
* @since 2.1.0
|
|
510
|
+
* @param {String} [groupID] - alphanumeric ID of a group to get. Falls back to user's primary group.
|
|
511
|
+
* @returns {SidechatGroup}
|
|
512
|
+
*/
|
|
513
|
+
getGroupMetadata = async (groupID = "") => {
|
|
514
|
+
if (!this.userToken) {
|
|
515
|
+
throw new SidechatAPIError("User is not authenticated.");
|
|
516
|
+
}
|
|
517
|
+
try {
|
|
518
|
+
const res = await fetch(`https://api.sidechat.lol/v1/groups/${groupID}`, {
|
|
519
|
+
method: "GET",
|
|
520
|
+
headers: {
|
|
521
|
+
...this.defaultHeaders,
|
|
522
|
+
Authorization: `Bearer ${this.userToken}`,
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
const json = await res.json();
|
|
526
|
+
return await json.group;
|
|
527
|
+
} catch (err) {
|
|
528
|
+
console.error(err);
|
|
529
|
+
throw new SidechatAPIError(`Failed to get asset library.`);
|
|
530
|
+
}
|
|
531
|
+
};
|
|
429
532
|
}
|
|
430
533
|
|
|
431
534
|
export { SidechatAPIClient, SidechatAPIError };
|
|
@@ -45,9 +45,9 @@ export type SidechatPostOrComment = {
|
|
|
45
45
|
*/
|
|
46
46
|
vote_status: SidechatVoteString;
|
|
47
47
|
/**
|
|
48
|
-
* - array of assets attached to post or comment
|
|
48
|
+
* - array of simple assets attached to post or comment
|
|
49
49
|
*/
|
|
50
|
-
assets:
|
|
50
|
+
assets: SidechatSimpleAsset[];
|
|
51
51
|
/**
|
|
52
52
|
* - undocumented
|
|
53
53
|
*/
|
|
@@ -102,7 +102,7 @@ export type SidechatPostOrComment = {
|
|
|
102
102
|
context?: string;
|
|
103
103
|
};
|
|
104
104
|
/**
|
|
105
|
-
* A group object, containing metadata about a group as well as its join conditions and states
|
|
105
|
+
* A group object, containing metadata about a group as well as its join conditions and states. Some properties vary based on the endpoint the object came from.
|
|
106
106
|
*/
|
|
107
107
|
export type SidechatGroup = {
|
|
108
108
|
/**
|
|
@@ -161,7 +161,7 @@ export type SidechatGroup = {
|
|
|
161
161
|
/**
|
|
162
162
|
* An asset object, containing information about an image within a post or comment
|
|
163
163
|
*/
|
|
164
|
-
export type
|
|
164
|
+
export type SidechatSimpleAsset = {
|
|
165
165
|
/**
|
|
166
166
|
* - alphanumeric ID of asset
|
|
167
167
|
*/
|
|
@@ -175,11 +175,11 @@ export type SidechatAsset = {
|
|
|
175
175
|
*/
|
|
176
176
|
content_type: "jpeg" | "png" | "gif";
|
|
177
177
|
/**
|
|
178
|
-
* -
|
|
178
|
+
* - width of asset
|
|
179
179
|
*/
|
|
180
180
|
width: number;
|
|
181
181
|
/**
|
|
182
|
-
* -
|
|
182
|
+
* - height of asset
|
|
183
183
|
*/
|
|
184
184
|
height: number;
|
|
185
185
|
/**
|
|
@@ -188,7 +188,49 @@ export type SidechatAsset = {
|
|
|
188
188
|
url: SidechatPrivateAssetURL;
|
|
189
189
|
};
|
|
190
190
|
/**
|
|
191
|
-
*
|
|
191
|
+
* An asset object, containing information about an image from the asset library
|
|
192
|
+
*/
|
|
193
|
+
export type SidechatLibraryAsset = {
|
|
194
|
+
/**
|
|
195
|
+
* - alphanumeric ID of asset
|
|
196
|
+
*/
|
|
197
|
+
id: string;
|
|
198
|
+
/**
|
|
199
|
+
* - date string of asset creation time
|
|
200
|
+
*/
|
|
201
|
+
created_at: string;
|
|
202
|
+
/**
|
|
203
|
+
* - metadata associated with asset
|
|
204
|
+
*/
|
|
205
|
+
metadata: SidechatAssetMetadata;
|
|
206
|
+
/**
|
|
207
|
+
* - URL string of asset's location
|
|
208
|
+
*/
|
|
209
|
+
url: SidechatPrivateAssetURL;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* An asset object, containing information about an image from the asset library
|
|
213
|
+
*/
|
|
214
|
+
export type SidechatAssetMetadata = {
|
|
215
|
+
/**
|
|
216
|
+
* - width of asset
|
|
217
|
+
*/
|
|
218
|
+
width: number;
|
|
219
|
+
/**
|
|
220
|
+
* - height of asset
|
|
221
|
+
*/
|
|
222
|
+
height: number;
|
|
223
|
+
/**
|
|
224
|
+
* - undocumented
|
|
225
|
+
*/
|
|
226
|
+
type: "image";
|
|
227
|
+
/**
|
|
228
|
+
* - file type of asset
|
|
229
|
+
*/
|
|
230
|
+
content_type: "jpeg" | "png" | "gif";
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* A user's anonymous identity information
|
|
192
234
|
*/
|
|
193
235
|
export type SidechatIdentity = {
|
|
194
236
|
/**
|
|
@@ -200,6 +242,53 @@ export type SidechatIdentity = {
|
|
|
200
242
|
*/
|
|
201
243
|
posted_with_username: boolean;
|
|
202
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* The current user's information
|
|
247
|
+
*/
|
|
248
|
+
export type SidechatCurrentUser = {
|
|
249
|
+
/**
|
|
250
|
+
* - alphanumeric ID of current user
|
|
251
|
+
*/
|
|
252
|
+
id: string;
|
|
253
|
+
/**
|
|
254
|
+
* - verified email of current user in an unreadable hashed form
|
|
255
|
+
*/
|
|
256
|
+
hashedVerifiedEmail: string;
|
|
257
|
+
/**
|
|
258
|
+
* - whether or not user is a moderator
|
|
259
|
+
*/
|
|
260
|
+
isGlobalModerator: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* - whether or not user is an admin
|
|
263
|
+
*/
|
|
264
|
+
isGlobalAdmin: boolean;
|
|
265
|
+
memberships: SidechatMembership[];
|
|
266
|
+
/**
|
|
267
|
+
* - undocumented
|
|
268
|
+
*/
|
|
269
|
+
roles: any[];
|
|
270
|
+
/**
|
|
271
|
+
* - domain of verified email address on account
|
|
272
|
+
*/
|
|
273
|
+
emailDomain: string;
|
|
274
|
+
/**
|
|
275
|
+
* - domain of verified email address on account, preceeded by *. to support subdomains
|
|
276
|
+
*/
|
|
277
|
+
wildcardEmailDomain: string;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Representation of a group membership
|
|
281
|
+
*/
|
|
282
|
+
export type SidechatMembership = {
|
|
283
|
+
/**
|
|
284
|
+
* - alphanumeric ID of group
|
|
285
|
+
*/
|
|
286
|
+
groupId: string;
|
|
287
|
+
/**
|
|
288
|
+
* - role of current user in group
|
|
289
|
+
*/
|
|
290
|
+
type: string;
|
|
291
|
+
};
|
|
203
292
|
/**
|
|
204
293
|
* An asset URL that can only be accessed by making a request with a user's bearer token attached in the Authorization header
|
|
205
294
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidechatTypes.d.ts","sourceRoot":"","sources":["../../src/types/SidechatTypes.js"],"names":[],"mappings":";;;;;;;;;UAGU,MAAM,GAAC,SAAS;;;;;;;;;;;;;;;;;;;;WAKhB,aAAa;;;;;;;;;;;;;;;;iBAIb,kBAAkB;;;;YAClB,
|
|
1
|
+
{"version":3,"file":"SidechatTypes.d.ts","sourceRoot":"","sources":["../../src/types/SidechatTypes.js"],"names":[],"mappings":";;;;;;;;;UAGU,MAAM,GAAC,SAAS;;;;;;;;;;;;;;;;;;;;WAKhB,aAAa;;;;;;;;;;;;;;;;iBAIb,kBAAkB;;;;YAClB,mBAAmB,EAAE;;;;;;;;;;;;;;;;cAIrB,gBAAgB;;;;;;;;;;;;mBAGhB,WAAW,GAAC,eAAe;;;;kBAC3B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAcP,YAAY,GAAC,QAAQ;;;;;;;;qBAErB,MAAM,GAAC,QAAQ,GAAC,cAAc;;;;sBAC9B,SAAS,GAAC,eAAe,GAAC,mBAAmB;;;;8BAC7C,MAAM,GAAC,MAAM;;;;;;;;;;;;eAGb,uBAAuB;;;;;;;;;;;;;;;;;;;;;UASvB,OAAO;;;;kBACP,MAAM,GAAC,KAAK,GAAC,KAAK;;;;;;;;;;;;SAGlB,uBAAuB;;;;;;;;;;;;;;;;;cAQvB,qBAAqB;;;;SACrB,uBAAuB;;;;;;;;;;;;;;;;;UAQvB,OAAO;;;;kBACP,MAAM,GAAC,KAAK,GAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiBlB,kBAAkB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAyBjB,QAAQ,GAAC,UAAU,GAAC,MAAM;;;;;;;;;WAW7B,qBAAqB,EAAE;YACvB,oBAAoB"}
|