sidechat.js 2.6.5 → 2.6.6

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.
Files changed (41) hide show
  1. package/dist/classes/SidechatAPIClient.d.ts.map +1 -1
  2. package/dist/index.cjs +75 -57
  3. package/dist/index.mjs +75 -57
  4. package/docs/sidechat.js/2.6.6/SidechatAPIClient.html +3 -0
  5. package/docs/sidechat.js/2.6.6/SidechatAPIError.html +3 -0
  6. package/docs/sidechat.js/2.6.6/SidechatColorList.html +3 -0
  7. package/docs/sidechat.js/2.6.6/classes_SidechatAPIClient.js.html +1447 -0
  8. package/docs/sidechat.js/2.6.6/classes_SidechatAPIError.js.html +16 -0
  9. package/docs/sidechat.js/2.6.6/classes_SidechatColorList.js.html +79 -0
  10. package/docs/sidechat.js/2.6.6/data/search.json +1 -0
  11. package/docs/sidechat.js/2.6.6/fonts/Inconsolata-Regular.ttf +0 -0
  12. package/docs/sidechat.js/2.6.6/fonts/OpenSans-Regular.ttf +0 -0
  13. package/docs/sidechat.js/2.6.6/fonts/WorkSans-Bold.ttf +0 -0
  14. package/docs/sidechat.js/2.6.6/global.html +3 -0
  15. package/docs/sidechat.js/2.6.6/index.html +4 -0
  16. package/docs/sidechat.js/2.6.6/scripts/core.js +726 -0
  17. package/docs/sidechat.js/2.6.6/scripts/core.min.js +23 -0
  18. package/docs/sidechat.js/2.6.6/scripts/resize.js +90 -0
  19. package/docs/sidechat.js/2.6.6/scripts/search.js +265 -0
  20. package/docs/sidechat.js/2.6.6/scripts/search.min.js +6 -0
  21. package/docs/sidechat.js/2.6.6/scripts/third-party/Apache-License-2.0.txt +202 -0
  22. package/docs/sidechat.js/2.6.6/scripts/third-party/fuse.js +9 -0
  23. package/docs/sidechat.js/2.6.6/scripts/third-party/hljs-line-num-original.js +369 -0
  24. package/docs/sidechat.js/2.6.6/scripts/third-party/hljs-line-num.js +1 -0
  25. package/docs/sidechat.js/2.6.6/scripts/third-party/hljs-original.js +5171 -0
  26. package/docs/sidechat.js/2.6.6/scripts/third-party/hljs.js +1 -0
  27. package/docs/sidechat.js/2.6.6/scripts/third-party/popper.js +5 -0
  28. package/docs/sidechat.js/2.6.6/scripts/third-party/tippy.js +1 -0
  29. package/docs/sidechat.js/2.6.6/scripts/third-party/tocbot.js +672 -0
  30. package/docs/sidechat.js/2.6.6/scripts/third-party/tocbot.min.js +1 -0
  31. package/docs/sidechat.js/2.6.6/styles/clean-jsdoc-theme-base.css +1159 -0
  32. package/docs/sidechat.js/2.6.6/styles/clean-jsdoc-theme-dark.css +412 -0
  33. package/docs/sidechat.js/2.6.6/styles/clean-jsdoc-theme-light.css +482 -0
  34. package/docs/sidechat.js/2.6.6/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  35. package/docs/sidechat.js/2.6.6/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  36. package/docs/sidechat.js/2.6.6/styles/clean-jsdoc-theme.min.css +1 -0
  37. package/docs/sidechat.js/2.6.6/tutorial-Authentication.html +14 -0
  38. package/docs/sidechat.js/2.6.6/tutorial-Email Registration.html +6 -0
  39. package/docs/sidechat.js/2.6.6/types_SidechatTypes.js.html +204 -0
  40. package/package.json +1 -1
  41. package/src/classes/SidechatAPIClient.js +75 -57
@@ -0,0 +1,1447 @@
1
+ <!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source: classes/SidechatAPIClient.js</title><!--[if lt IE 9]>
2
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
3
+ <![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(baseURL=(baseURL="https://micahlindley.com/sidechat.js/").replace(/https?:\/\//i,"")).substr(baseURL.indexOf("/"))</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="dark"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">sidechat.js</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-tutorials"><div>Tutorials</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="tutorial-Authentication.html">Authentication</a></div><div class="sidebar-section-children"><a href="tutorial-Email Registration.html">Email Registration</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="SidechatAPIClient.html">SidechatAPIClient</a></div><div class="sidebar-section-children"><a href="SidechatAPIError.html">SidechatAPIError</a></div><div class="sidebar-section-children"><a href="SidechatColorList.html">SidechatColorList</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#SidechatAssetMetadata">SidechatAssetMetadata</a></div><div class="sidebar-section-children"><a href="global.html#SidechatAuthToken">SidechatAuthToken</a></div><div class="sidebar-section-children"><a href="global.html#SidechatColor">SidechatColor</a></div><div class="sidebar-section-children"><a href="global.html#SidechatCurrentUser">SidechatCurrentUser</a></div><div class="sidebar-section-children"><a href="global.html#SidechatCursorString">SidechatCursorString</a></div><div class="sidebar-section-children"><a href="global.html#SidechatDirectMessage">SidechatDirectMessage</a></div><div class="sidebar-section-children"><a href="global.html#SidechatDirectThread">SidechatDirectThread</a></div><div class="sidebar-section-children"><a href="global.html#SidechatGroup">SidechatGroup</a></div><div class="sidebar-section-children"><a href="global.html#SidechatIcon">SidechatIcon</a></div><div class="sidebar-section-children"><a href="global.html#SidechatIdentity">SidechatIdentity</a></div><div class="sidebar-section-children"><a href="global.html#SidechatLibraryAsset">SidechatLibraryAsset</a></div><div class="sidebar-section-children"><a href="global.html#SidechatMembership">SidechatMembership</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPoll">SidechatPoll</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPollChoice">SidechatPollChoice</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPostOrComment">SidechatPostOrComment</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPostsAndCursor">SidechatPostsAndCursor</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPrivateAssetURL">SidechatPrivateAssetURL</a></div><div class="sidebar-section-children"><a href="global.html#SidechatProfile">SidechatProfile</a></div><div class="sidebar-section-children"><a href="global.html#SidechatSimpleAsset">SidechatSimpleAsset</a></div><div class="sidebar-section-children"><a href="global.html#SidechatVoteString">SidechatVoteString</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://github.com/micahlt/sidechat.js" target="_blank">GitHub</a></div><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/sidechat.js" target="_blank">NPM</a></div><div class="navbar-item"><a id="" href="https://offsides.micahlindley.com" target="_blank">Offsides (Sidechat for Android)</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">classes_SidechatAPIClient.js</h1></header><article><pre class="prettyprint source lang-js"><code>import SidechatAPIError from "../classes/SidechatAPIError.js";
4
+
5
+ /** @import * as types from "../types/SidechatTypes.js" */
6
+
7
+ /**
8
+ * API client class for making requests to Sidechat's private API. You'll need to [authenticate]{@tutorial Authentication} before using most of the methods.
9
+ * @class
10
+ * @since 2.0.0-alpha.0
11
+ */
12
+ class SidechatAPIClient {
13
+ /**
14
+ * User bearer token
15
+ * @type {types.SidechatAuthToken}
16
+ * */
17
+ userToken;
18
+
19
+ /**
20
+ * Default headers for every API request
21
+ * @type {Object}
22
+ * @static
23
+ * @constant
24
+ */
25
+ defaultHeaders = {
26
+ Accept: "application/json",
27
+ "Content-Type": "application/json",
28
+ "App-Version": "6.0.0",
29
+ Dnt: 1,
30
+ };
31
+
32
+ /**
33
+ * Root URL for every API request
34
+ * @type {String}
35
+ * @default "https://api.sidechat.lol"
36
+ */
37
+ apiRoot = "https://api.sidechat.lol";
38
+
39
+ /**
40
+ * Create a new instance of the API client
41
+ * @param {types.SidechatAuthToken} [token] - user bearer token
42
+ * @param {String} rootUrl - custom API root URL for mocking or using other server
43
+ */
44
+ constructor(token = "", rootUrl = "") {
45
+ if (token) {
46
+ this.userToken = token;
47
+ }
48
+ if (rootUrl) {
49
+ this.apiRoot = rootUrl;
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Manually set the currently signed in user's token. Generally try to avoid this and instead either pass a token to the constructor or login automatically through the auth functions
55
+ * @method
56
+ * @param {types.SidechatAuthToken} token - user bearer token
57
+ */
58
+ setToken = (token) => {
59
+ this.userToken = token;
60
+ };
61
+
62
+ /**
63
+ * Manually set the root URL for all API requests. This can be used for mocking requests or redirecting them to a different server
64
+ * @method
65
+ * @param {String} url - new root URL to set
66
+ * @since 2.3.9
67
+ */
68
+ setAPIRoot = (url) => {
69
+ this.apiRoot = url;
70
+ };
71
+
72
+ /**
73
+ * Run an arbitrary API request using the current client's authentication
74
+ * @method
75
+ * @param {String} endpoint - API endpoint to request (e.g. "/v1/posts")
76
+ * @param {"GET"|"POST"|"PUT"|"DELETE"|"PATCH"|"OPTIONS"} [method] - HTTP method to use
77
+ * @param {Object} [body] - body to send with the request
78
+ * @param {Object} [headers] - custom headers to send with the request
79
+ * @param {Boolean} [stripHeaders] - remove the default headers from the request
80
+ * @since 2.4.9
81
+ */
82
+ sendRequest = (
83
+ endpoint,
84
+ method = "GET",
85
+ body = undefined,
86
+ headers = {},
87
+ stripHeaders = false,
88
+ ) => {
89
+ let requestHeaders = this.defaultHeaders;
90
+ if (stripHeaders) {
91
+ headers = {};
92
+ }
93
+ requestHeaders = { ...requestHeaders, ...headers };
94
+ return fetch(`${this.apiRoot}${endpoint}`, {
95
+ headers: { Authorization: `Bearer ${this.userToken}`, ...requestHeaders },
96
+ body: body,
97
+ method: method,
98
+ });
99
+ };
100
+
101
+ /**
102
+ * Initiate the login process with a phone number. Should be followed up with verifySMSCode().
103
+ * @method
104
+ * @since 1.0.0
105
+ * @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to
106
+ */
107
+ loginViaSMS = async (phoneNumber) => {
108
+ try {
109
+ const res = await fetch(`${this.apiRoot}/v1/login_register`, {
110
+ method: "POST",
111
+ headers: this.defaultHeaders,
112
+ body: JSON.stringify({
113
+ phone_number: `+1${phoneNumber}`,
114
+ version: 3,
115
+ }),
116
+ });
117
+ const json = await res.json();
118
+ return json;
119
+ } catch (err) {
120
+ console.error(err);
121
+ throw new SidechatAPIError("Failed to request SMS verification.");
122
+ }
123
+ };
124
+
125
+ /**
126
+ * Verify the code sent via SMS with loginViaSMS(). If this function succeeds, the user will be authenticated for future requests.
127
+ * @method
128
+ * @since 1.0.0
129
+ * @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to
130
+ * @param {String} code - the verification code
131
+ */
132
+ verifySMSCode = async (phoneNumber, code) => {
133
+ try {
134
+ const res = await fetch(`${this.apiRoot}/v1/verify_phone_number`, {
135
+ method: "POST",
136
+ headers: this.defaultHeaders,
137
+ body: JSON.stringify({
138
+ phone_number: `+1${phoneNumber}`,
139
+ code: code.toUpperCase(),
140
+ }),
141
+ });
142
+ const json = await res.json();
143
+ if (json?.logged_in_user?.token) {
144
+ this.userToken = json.logged_in_user.token;
145
+ }
146
+ return json;
147
+ } catch (err) {
148
+ console.error(err);
149
+ throw new SidechatAPIError("Failed verify this code.");
150
+ }
151
+ };
152
+
153
+ /**
154
+ * Set the user's age. If this function succeeds, the user will be authenticated for future requests.
155
+ * @method
156
+ * @since 1.0.0
157
+ * @param {Number} age - user's age in years
158
+ * @param {String} registrationID - the registration ID generated by verifySMSCode()
159
+ */
160
+ setAge = async (age, registrationID) => {
161
+ if (age &lt; 13) {
162
+ throw new SidechatAPIError("You're too young to use Offsides.");
163
+ }
164
+ try {
165
+ const res = await fetch(`${this.apiRoot}/v1/complete_registration`, {
166
+ method: "POST",
167
+ headers: this.defaultHeaders,
168
+ body: JSON.stringify({
169
+ age: Number(age),
170
+ registration_id: registrationID,
171
+ }),
172
+ });
173
+ const json = await res.json();
174
+ if (json.token) {
175
+ this.userToken = json.token;
176
+ }
177
+ return json;
178
+ } catch (err) {
179
+ console.error(err);
180
+ throw new SidechatAPIError("Failed verify this code.");
181
+ }
182
+ };
183
+
184
+ /**
185
+ * Initiate the email setup process. Should be followed up with checkEmailVerification().
186
+ * @method
187
+ * @since 1.0.0
188
+ * @param {String} email - school email address to send verification code to
189
+ * @tutorial Email Registration
190
+ */
191
+ registerEmail = async (email) => {
192
+ if (!this.userToken) {
193
+ throw new SidechatAPIError("User is not authenticated.");
194
+ }
195
+ try {
196
+ const res = await fetch(`${this.apiRoot}/v2/users/register_email`, {
197
+ method: "POST",
198
+ headers: {
199
+ ...this.defaultHeaders,
200
+ Authorization: `Bearer ${this.userToken}`,
201
+ },
202
+ body: JSON.stringify({
203
+ email: email,
204
+ }),
205
+ });
206
+ const json = await res.json();
207
+ if (json.message) {
208
+ throw new SidechatAPIError(json.message);
209
+ }
210
+ return json;
211
+ } catch (err) {
212
+ console.error(err);
213
+ throw new SidechatAPIError("Failed to request email verification.");
214
+ }
215
+ };
216
+
217
+ /**
218
+ * Check is the user's email is verified.
219
+ * @method
220
+ * @since 1.0.0
221
+ */
222
+ checkEmailVerification = async () => {
223
+ if (!this.userToken) {
224
+ throw new SidechatAPIError("User is not authenticated.");
225
+ }
226
+ try {
227
+ const res = await fetch(`${this.apiRoot}/v1/users/check_email_verified`, {
228
+ method: "GET",
229
+ headers: {
230
+ ...this.defaultHeaders,
231
+ Authorization: `Bearer ${this.userToken}`,
232
+ },
233
+ });
234
+ const json = await res.json();
235
+ if (json.verified_email_updates_response) {
236
+ return json.verified_email_updates_response;
237
+ } else if (json.changing_phone_number_verified_email_user) {
238
+ return json.changing_phone_number_verified_email_user;
239
+ } else {
240
+ throw new SidechatAPIError(json?.message || "Email is not verified.");
241
+ }
242
+ } catch (err) {
243
+ console.error(err);
244
+ throw new SidechatAPIError("Email is not verified.");
245
+ }
246
+ };
247
+
248
+ /**
249
+ * Set the device ID of the current user
250
+ * @method
251
+ * @since 1.0.0
252
+ * @param {String} deviceId - the device ID to set
253
+ */
254
+ setDeviceID = async (deviceID) => {
255
+ if (!this.userToken) {
256
+ throw new SidechatAPIError("User is not authenticated.");
257
+ }
258
+ try {
259
+ const res = await fetch(`${this.apiRoot}/v1/register_device_token`, {
260
+ method: "POST",
261
+ headers: {
262
+ ...this.defaultHeaders,
263
+ Authorization: `Bearer ${this.userToken}`,
264
+ },
265
+ body: JSON.stringify({
266
+ build_type: "release",
267
+ bundle_id: "com.flowerave.sidechat",
268
+ device_token: deviceID,
269
+ }),
270
+ });
271
+ const json = await res.json();
272
+ return json;
273
+ } catch (err) {
274
+ console.error(err);
275
+ throw new SidechatAPIError("Failed verify this code.");
276
+ }
277
+ };
278
+
279
+ /**
280
+ * Get updated status for user and group
281
+ * @method
282
+ * @since 1.0.0
283
+ * @deprecated since 2.1.0, will be removed by 3.0.0. Please use `getUpdates` instead!
284
+ * @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
285
+ */
286
+ getUserAndGroup = async (groupID = "") => {
287
+ const json = await this.getUpdates(groupID);
288
+ return json;
289
+ };
290
+
291
+ /**
292
+ * Get updated status for user and group
293
+ * @method
294
+ * @since 2.1.0
295
+ * @param {String} [groupID] - ID of a specific group to retrieve info from. Falls back to user's primary group.
296
+ */
297
+ getUpdates = async (groupID = "") => {
298
+ if (!this.userToken) {
299
+ throw new SidechatAPIError("User is not authenticated.");
300
+ }
301
+ try {
302
+ const res = await fetch(
303
+ `${this.apiRoot}/v1/updates?group_id=${groupID}`,
304
+ {
305
+ method: "GET",
306
+ headers: {
307
+ ...this.defaultHeaders,
308
+ Authorization: `Bearer ${this.userToken}`,
309
+ },
310
+ },
311
+ );
312
+ const json = await res.json();
313
+ return json;
314
+ } catch (err) {
315
+ console.error(err);
316
+ throw new SidechatAPIError(`Failed to get posts from group.`);
317
+ }
318
+ };
319
+
320
+ /**
321
+ * Fetches posts from the specified category in a group
322
+ * @method
323
+ * @since 1.0.0
324
+ * @param {String} groupID - group ID
325
+ * @param {"hot"|"recent"|"top"} category - category to filter posts
326
+ * @param {types.SidechatCursorString} [cursor] - cursor string
327
+ * @returns {Promise&lt;types.SidechatPostsAndCursor>} List of posts and cursor
328
+ */
329
+ getGroupPosts = async (groupID, category = "hot", cursor) => {
330
+ if (!this.userToken) {
331
+ throw new SidechatAPIError("User is not authenticated.");
332
+ }
333
+ try {
334
+ const res = await fetch(
335
+ `${this.apiRoot}/v1/posts?${
336
+ cursor ? "cursor=" + encodeURIComponent(cursor) + "&amp;" : ""
337
+ }group_id=${groupID}&amp;type=${category}&amp;cacheBust=${Date.now()}`,
338
+ {
339
+ method: "GET",
340
+ headers: {
341
+ ...this.defaultHeaders,
342
+ Authorization: `Bearer ${this.userToken}`,
343
+ },
344
+ },
345
+ );
346
+ const json = await res.json();
347
+ return json;
348
+ } catch (err) {
349
+ console.error(err);
350
+ throw new SidechatAPIError(`Failed to get posts from group.`);
351
+ }
352
+ };
353
+
354
+ /**
355
+ * Upvote or downvote, or unvote a post
356
+ * @method
357
+ * @since 2.0.0-alpha.0
358
+ * @param {String} postID - post ID to vote on
359
+ * @param {types.SidechatVoteString} action - whether to upvote, downvote, or reset vote
360
+ */
361
+ setVote = async (postID, action) => {
362
+ if (!this.userToken) {
363
+ throw new SidechatAPIError("User is not authenticated.");
364
+ }
365
+ try {
366
+ const res = await fetch(`${this.apiRoot}/v1/posts/set_vote`, {
367
+ method: "POST",
368
+ headers: {
369
+ ...this.defaultHeaders,
370
+ Authorization: `Bearer ${this.userToken}`,
371
+ },
372
+ body: JSON.stringify({
373
+ post_id: postID,
374
+ vote_status: action,
375
+ }),
376
+ });
377
+ const json = await res.json();
378
+ return json;
379
+ } catch (err) {
380
+ console.error(err);
381
+ throw new SidechatAPIError(`Failed to change the vote on post.`);
382
+ }
383
+ };
384
+
385
+ /**
386
+ * Fetches a single post with just its ID
387
+ * @method
388
+ * @since 2.3.0
389
+ * @param {String} postID - ID of post to fetch
390
+ * @param {Boolean} includeDeleted - undocumented
391
+ * @returns {Promise&lt;types.SidechatPostOrComment>} post object
392
+ */
393
+ getPost = async (postID, includeDeleted = false) => {
394
+ if (!this.userToken) {
395
+ throw new SidechatAPIError("User is not authenticated.");
396
+ }
397
+ try {
398
+ const res = await fetch(
399
+ `${this.apiRoot}/v1/posts/get?include_deleted=${includeDeleted}&amp;post_id=${postID}&amp;cacheBust=${Date.now()}`,
400
+ {
401
+ method: "GET",
402
+ headers: {
403
+ ...this.defaultHeaders,
404
+ Authorization: `Bearer ${this.userToken}`,
405
+ },
406
+ },
407
+ );
408
+ const json = await res.json();
409
+ return json.post;
410
+ } catch (err) {
411
+ console.error(err);
412
+ throw new SidechatAPIError(`Failed to get post from ID.`);
413
+ }
414
+ };
415
+
416
+ /**
417
+ * Fetches the posts or comments that the user has created
418
+ * @method
419
+ * @since 2.3.5
420
+ * @param {"posts"|"comments"} contentType - type of user content to fetch
421
+ * @returns {Promise&lt;types.SidechatPostOrComment[]>} post object
422
+ */
423
+ getUserContent = async (contentType) => {
424
+ if (!this.userToken) {
425
+ throw new SidechatAPIError("User is not authenticated.");
426
+ }
427
+ if (contentType == "posts") {
428
+ contentType = "my_posts";
429
+ } else if (contentType == "comments") {
430
+ contentType = "my_comments";
431
+ }
432
+ try {
433
+ const res = await fetch(`${this.apiRoot}/v1/posts&amp;type=${contentType}`, {
434
+ method: "GET",
435
+ headers: {
436
+ ...this.defaultHeaders,
437
+ Authorization: `Bearer ${this.userToken}`,
438
+ },
439
+ });
440
+ const json = await res.json();
441
+ return json.posts;
442
+ } catch (err) {
443
+ console.error(err);
444
+ throw new SidechatAPIError(`Failed to get content from user.`);
445
+ }
446
+ };
447
+
448
+ /**
449
+ * Get all the commments on a post
450
+ * @method
451
+ * @since 2.0.0-alpha.0
452
+ * @param {String} postID - post ID to get comments for
453
+ * @returns {Promise&lt;types.SidechatPostOrComment[]>} list of comments
454
+ */
455
+ getPostComments = async (postID) => {
456
+ if (!this.userToken) {
457
+ throw new SidechatAPIError("User is not authenticated.");
458
+ }
459
+ try {
460
+ const res = await fetch(
461
+ `${this.apiRoot}/v1/posts/comments/?post_id=${postID}&amp;cacheBust=${Date.now()}`,
462
+ {
463
+ method: "GET",
464
+ headers: {
465
+ ...this.defaultHeaders,
466
+ Authorization: `Bearer ${this.userToken}`,
467
+ },
468
+ },
469
+ );
470
+ const json = await res.json();
471
+ // Function to preprocess the comments and organize them into a nested structure
472
+ function preprocessComments(apiComments) {
473
+ // Map to store comments by their IDs for efficient lookup
474
+ const commentMap = new Map();
475
+ // List to store top-level comments
476
+ const topLevelComments = [];
477
+
478
+ // Iterate through the API comments
479
+ apiComments.forEach((comment) => {
480
+ // Store the comment in the map with its ID as the key
481
+ commentMap.set(comment.id, comment);
482
+ // Get the parent comment using the reply_post_id
483
+ const parentComment = commentMap.get(comment.reply_post_id);
484
+ // Check if the comment is a top-level comment
485
+ if (
486
+ !parentComment ||
487
+ comment.reply_post_id === comment.parent_post_id
488
+ ) {
489
+ // If it's a top-level comment, push it to the topLevelComments array
490
+ topLevelComments.push(comment);
491
+ } else {
492
+ // If it's a reply, add it to the parent comment's replies array
493
+ if (!parentComment.replies) parentComment.replies = [];
494
+ parentComment.replies.push(comment);
495
+ }
496
+ });
497
+
498
+ // Flatten the nested structure and return a single list of comments
499
+ return flattenComments(topLevelComments);
500
+ }
501
+
502
+ // Function to flatten nested comments into a single list
503
+ function flattenComments(comments) {
504
+ // Use reduce to flatten the nested comments array into a single list
505
+ return comments.reduce((flatComments, comment) => {
506
+ // Push the current comment to the flatComments array
507
+ flatComments.push(comment);
508
+ // If the current comment has replies, recursively flatten them and push to the flatComments array
509
+ if (comment.replies)
510
+ flatComments.push(...flattenComments(comment.replies));
511
+ // Return the flatComments array
512
+ return flatComments;
513
+ }, []);
514
+ }
515
+
516
+ const sortedComments = preprocessComments(json.posts);
517
+ return sortedComments;
518
+ } catch (err) {
519
+ console.error(err);
520
+ throw new SidechatAPIError(`Failed to get comments on post.`);
521
+ }
522
+ };
523
+
524
+ /**
525
+ * Gets groups to be displayed on the "Explore Groups" page
526
+ * @method
527
+ * @since 2.0.0-alpha.0
528
+ * @param {Boolean} onePage - whether or not results should be returned as a single page
529
+ * @returns {Promise&lt;types.SidechatGroup[]>}
530
+ */
531
+ getAvailableGroups = async (onePage = true) => {
532
+ if (!this.userToken) {
533
+ throw new SidechatAPIError("User is not authenticated.");
534
+ }
535
+ try {
536
+ const res = await fetch(`${this.apiRoot}/v1/groups/explore`, {
537
+ method: "GET",
538
+ headers: {
539
+ ...this.defaultHeaders,
540
+ "App-Version": onePage ? "0" : this.defaultHeaders["App-Version"],
541
+ Authorization: `Bearer ${this.userToken}`,
542
+ },
543
+ });
544
+ const json = await res.json();
545
+ return await json.groups;
546
+ } catch (err) {
547
+ console.error(err);
548
+ throw new SidechatAPIError(`Failed to get groups from explore.`);
549
+ }
550
+ };
551
+
552
+ /**
553
+ * Searches for new groups based on a query keyword
554
+ * @method
555
+ * @since 2.6.0
556
+ * @param {String} query - the string to search for. This will be encoded, so strings with spaces and special characters are okay.
557
+ * @returns {Promise&lt;types.SidechatGroup[]>}
558
+ */
559
+ searchAvailableGroups = async (query) => {
560
+ if (!this.userToken) {
561
+ throw new SidechatAPIError("User is not authenticated.");
562
+ }
563
+ try {
564
+ const res = await fetch(
565
+ `${this.apiRoot}/v1/groups/explore/search?term=${encodeURIComponent(query)}`,
566
+ {
567
+ method: "GET",
568
+ headers: {
569
+ ...this.defaultHeaders,
570
+ Authorization: `Bearer ${this.userToken}`,
571
+ },
572
+ },
573
+ );
574
+ const json = await res.json();
575
+ return await json.results;
576
+ } catch (err) {
577
+ console.error(err);
578
+ throw new SidechatAPIError(`Failed to search groups.`);
579
+ }
580
+ };
581
+
582
+ /**
583
+ * 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.
584
+ * @method
585
+ * @since 2.0.6
586
+ * @returns {Promise&lt;types.SidechatLibraryAsset[]>}
587
+ */
588
+ getAssetLibrary = async () => {
589
+ if (!this.userToken) {
590
+ throw new SidechatAPIError("User is not authenticated.");
591
+ }
592
+ try {
593
+ const res = await fetch(`${this.apiRoot}/v1/assets/library`, {
594
+ method: "GET",
595
+ headers: {
596
+ ...this.defaultHeaders,
597
+ Authorization: `Bearer ${this.userToken}`,
598
+ },
599
+ });
600
+ const json = await res.json();
601
+ return await json.items;
602
+ } catch (err) {
603
+ console.error(err);
604
+ throw new SidechatAPIError(`Failed to get asset library.`);
605
+ }
606
+ };
607
+
608
+ /**
609
+ * Gets the current authenticated user and a list of the groups of which they are members.
610
+ * @method
611
+ * @since 2.1.0
612
+ * @returns {Promise&lt;types.SidechatCurrentUser>}
613
+ */
614
+ getCurrentUser = async () => {
615
+ if (!this.userToken) {
616
+ throw new SidechatAPIError("User is not authenticated.");
617
+ }
618
+ try {
619
+ const res = await fetch(`${this.apiRoot}/v1/users/me`, {
620
+ method: "GET",
621
+ headers: {
622
+ ...this.defaultHeaders,
623
+ Authorization: `Bearer ${this.userToken}`,
624
+ },
625
+ });
626
+ const json = await res.json();
627
+ return await json;
628
+ } catch (err) {
629
+ console.error(err);
630
+ throw new SidechatAPIError(`Failed to get asset library.`);
631
+ }
632
+ };
633
+
634
+ /**
635
+ * Gets the metadata of a group from its ID
636
+ * @method
637
+ * @since 2.1.0
638
+ * @param {String} [groupID] - alphanumeric ID of a group to get. Falls back to user's primary group.
639
+ * @returns {Promise&lt;types.SidechatGroup>}
640
+ */
641
+ getGroupMetadata = async (groupID = "") => {
642
+ if (!this.userToken) {
643
+ throw new SidechatAPIError("User is not authenticated.");
644
+ }
645
+ try {
646
+ const res = await fetch(`${this.apiRoot}/v1/groups/${groupID}`, {
647
+ method: "GET",
648
+ headers: {
649
+ ...this.defaultHeaders,
650
+ Authorization: `Bearer ${this.userToken}`,
651
+ },
652
+ });
653
+ const json = await res.json();
654
+ return await json.group;
655
+ } catch (err) {
656
+ console.error(err);
657
+ throw new SidechatAPIError(`Failed to get group metadata.`);
658
+ }
659
+ };
660
+
661
+ /**
662
+ * Joins or leaves a group
663
+ * @method
664
+ * @param {String} groupID - alphanumeric ID of group to join or leave
665
+ * @param {Boolean} isMember - whether or not the user should be a member of the group
666
+ * @since 2.3.8
667
+ */
668
+ setGroupMembership = async (groupID, isMember) => {
669
+ if (!this.userToken) {
670
+ throw new SidechatAPIError("User is not authenticated.");
671
+ }
672
+ try {
673
+ const res = await fetch(
674
+ `${this.apiRoot}/v1/groups/${isMember ? "join" : "leave"}`,
675
+ {
676
+ method: "POST",
677
+ headers: {
678
+ ...this.defaultHeaders,
679
+ Authorization: `Bearer ${this.userToken}`,
680
+ },
681
+ body: JSON.stringify({
682
+ group_id: groupID,
683
+ }),
684
+ },
685
+ );
686
+ const json = await res.json();
687
+ return await json;
688
+ } catch (err) {
689
+ console.error(err);
690
+ throw new SidechatAPIError(`Failed to modify group membership.`);
691
+ }
692
+ };
693
+
694
+ /**
695
+ * Creates a comment on a post
696
+ * @method
697
+ * @since 2.2.0
698
+ * @param {String} parentPostID - alphanumeric ID of post on which this comment is made
699
+ * @param {String} text - text content of comment
700
+ * @param {String} groupID - alphanumeric ID of group in which the parent post resides
701
+ * @param {String} [replyCommentID] - alphanumeric ID of comment to reply to. Falls back to parentPostID
702
+ * @param {String} [topLevelReplyID] - alphanumeric ID of the top-level comment to reply to. Used only when replying to replies. Falls back to parentPostID
703
+ * @param {types.SidechatSimpleAsset[]} [assetList] - list of assets to attach
704
+ * @param {Boolean} [disableDMs] - prevent direct messages being sent to comment's author
705
+ * @param {Boolean} [anonymous] - whether or not to hide user's name and icon on comment
706
+ * @returns {Promise&lt;types.SidechatPostOrComment>} created comment
707
+ */
708
+ createComment = async (
709
+ parentPostID,
710
+ text,
711
+ groupID,
712
+ replyCommentID,
713
+ topLevelReplyID,
714
+ assetList = [],
715
+ disableDMs = false,
716
+ anonymous = false,
717
+ ) => {
718
+ if (!this.userToken) {
719
+ throw new SidechatAPIError("User is not authenticated.");
720
+ }
721
+ try {
722
+ const res = await fetch(`${this.apiRoot}/v1/posts`, {
723
+ method: "POST",
724
+ headers: {
725
+ ...this.defaultHeaders,
726
+ Authorization: `Bearer ${this.userToken}`,
727
+ },
728
+ body: JSON.stringify({
729
+ type: "comment",
730
+ assets: assetList,
731
+ group_ids: [groupID],
732
+ text: text,
733
+ reply_post_id: topLevelReplyID || replyCommentID || parentPostID,
734
+ reply_comment_post_id: replyCommentID || parentPostID,
735
+ parent_post_id: parentPostID,
736
+ dms_disabled: disableDMs,
737
+ using_identity: !anonymous,
738
+ }),
739
+ });
740
+ const json = await res.json();
741
+ return await json.comment;
742
+ } catch (err) {
743
+ console.error(err);
744
+ throw new SidechatAPIError(`Failed to post comment.`);
745
+ }
746
+ };
747
+
748
+ /**
749
+ * Creates a new post in the specified group
750
+ * @method
751
+ * @since 2.2.0
752
+ * @param {String} text - text content of comment
753
+ * @param {String} groupID - alphanumeric ID of group in which the parent post resides
754
+ * @param {types.SidechatSimpleAsset[]} [assetList] - list of assets to attach.
755
+ * @param {Boolean} [disableDMs] - prevent direct messages from being sent to post's author
756
+ * @param {Boolean} [disableComments] - whether or not comments should be disabled on post
757
+ * @param {Boolean} [anonymous] - whether or not to hide user's name and icon on post
758
+ * @param {Array&lt;String>} [pollOptions] - List of poll options. If provided, a poll will be created with these options.
759
+ * @returns {Promise&lt;types.SidechatPostOrComment>} the created post
760
+ */
761
+ createPost = async (
762
+ text,
763
+ groupID,
764
+ assetList = [],
765
+ disableDMs = false,
766
+ disableComments = false,
767
+ anonymous = false,
768
+ repostId = undefined,
769
+ pollOptions = undefined,
770
+ ) => {
771
+ if (!this.userToken) {
772
+ throw new SidechatAPIError("User is not authenticated.");
773
+ }
774
+ try {
775
+ // Build the request body
776
+ const body = {
777
+ type: "post",
778
+ assets: assetList,
779
+ group_ids: [groupID],
780
+ text: text,
781
+ attachments: [],
782
+ dms_disabled: disableDMs,
783
+ comments_disabled: disableComments,
784
+ using_identity: !anonymous,
785
+ quote_post_id: repostId,
786
+ };
787
+ // If pollOptions is provided and is a non-empty array, add poll_request
788
+ if (Array.isArray(pollOptions) &amp;&amp; pollOptions.length > 0) {
789
+ body.poll_request = {
790
+ allows_view_results: true,
791
+ choices: pollOptions,
792
+ };
793
+ }
794
+ const res = await fetch(`${this.apiRoot}/v1/posts`, {
795
+ method: "POST",
796
+ headers: {
797
+ ...this.defaultHeaders,
798
+ Authorization: `Bearer ${this.userToken}`,
799
+ },
800
+ body: JSON.stringify(body),
801
+ });
802
+ const json = await res.json();
803
+ return await json.posts[0];
804
+ } catch (err) {
805
+ console.error(err);
806
+ throw new SidechatAPIError(`Failed to make post.`);
807
+ }
808
+ };
809
+
810
+ /**
811
+ * Deletes a post or comment that the user created
812
+ * @method
813
+ * @since 2.2.0
814
+ * @param {String} postOrCommentID - alphanumeric ID of post to delete
815
+ */
816
+ deletePostOrComment = async (postOrCommentID) => {
817
+ if (!this.userToken) {
818
+ throw new SidechatAPIError("User is not authenticated.");
819
+ }
820
+ try {
821
+ const res = await fetch(`${this.apiRoot}/v1/posts/delete`, {
822
+ method: "POST",
823
+ headers: {
824
+ ...this.defaultHeaders,
825
+ Authorization: `Bearer ${this.userToken}`,
826
+ },
827
+ body: JSON.stringify({
828
+ post_id: postOrCommentID,
829
+ }),
830
+ });
831
+ const json = await res.json();
832
+ return await json;
833
+ } catch (err) {
834
+ console.error(err);
835
+ throw new SidechatAPIError(`Failed to delete post.`);
836
+ }
837
+ };
838
+
839
+ /**
840
+ * Votes on a poll attached to a post
841
+ * @method
842
+ * @param {String} pollId - alphanumeric ID of poll to vote on
843
+ * @param {Number} choiceIndex - index of the choice to vote on
844
+ * @since 2.5.4
845
+ */
846
+ voteOnPoll = async (pollId, choiceIndex) => {
847
+ if (!this.userToken) {
848
+ throw new SidechatAPIError("User is not authenticated.");
849
+ }
850
+ try {
851
+ const res = await fetch(`${this.apiRoot}/v1/polls/vote`, {
852
+ method: "POST",
853
+ headers: {
854
+ ...this.defaultHeaders,
855
+ Authorization: `Bearer ${this.userToken}`,
856
+ },
857
+ body: JSON.stringify({
858
+ poll_id: pollId,
859
+ choice: choiceIndex,
860
+ }),
861
+ });
862
+ const json = await res.json();
863
+ return await json;
864
+ } catch (err) {
865
+ console.error(err);
866
+ throw new SidechatAPIError(`Failed to vote on poll`);
867
+ }
868
+ };
869
+
870
+ /**
871
+ * Marks that the user has viewed results on a poll. Note that this does not actually return the results of the poll.
872
+ * @method
873
+ * @param {String} pollId - alphanumeric ID of poll to vote on
874
+ * @since 2.5.4
875
+ */
876
+ viewPollResults = async (pollId) => {
877
+ if (!this.userToken) {
878
+ throw new SidechatAPIError("User is not authenticated.");
879
+ }
880
+ try {
881
+ const res = await fetch(
882
+ `${this.apiRoot}/v1/polls/view_results&amp;cacheBust=${Date.now()}`,
883
+ {
884
+ method: "POST",
885
+ headers: {
886
+ ...this.defaultHeaders,
887
+ Authorization: `Bearer ${this.userToken}`,
888
+ },
889
+ body: JSON.stringify({
890
+ poll_id: pollId,
891
+ }),
892
+ },
893
+ );
894
+ const json = await res.json();
895
+ return await json;
896
+ } catch (err) {
897
+ console.error(err);
898
+ throw new SidechatAPIError(`Failed to mark poll results as viewed.`);
899
+ }
900
+ };
901
+
902
+ /**
903
+ * Uploads an asset to AWS S3 for use in posts and comments. Currently photos only
904
+ * @method
905
+ * @param {String} uri - URI of the asset to upload
906
+ * @param {String} mimeType - mimetype of the asset (e.g. "image/png")
907
+ * @param {String} [name] - filename of the asset
908
+ * @returns {Promise&lt;String>} URL of the uploaded asset
909
+ * @since 2.5.1
910
+ */
911
+ uploadAsset = async (uri, mimeType, name = "") => {
912
+ if (!this.userToken) {
913
+ throw new SidechatAPIError("User is not authenticated.");
914
+ }
915
+
916
+ let imageType = mimeType.split("/")[1];
917
+ if (!["png", "jpeg", "gif"].includes(imageType)) {
918
+ throw new SidechatAPIError("Unsupported image format.");
919
+ }
920
+
921
+ const data = new FormData();
922
+ data.append("image", {
923
+ name: name,
924
+ type: mimeType,
925
+ uri: uri,
926
+ });
927
+
928
+ const urlReq = await this.sendRequest(
929
+ `/v1/assets/upload_url?content_type=${imageType}`,
930
+ );
931
+ const urlJson = await urlReq.json();
932
+
933
+ try {
934
+ const uploadReq = await fetch(urlJson.upload_url, {
935
+ body: data.getAll("image")[0],
936
+ method: "PUT",
937
+ headers: {
938
+ "Content-Type": mimeType,
939
+ },
940
+ });
941
+ if (uploadReq.status == 200) {
942
+ return `${this.apiRoot}/v1/assets/library/${urlJson.asset_id}`;
943
+ } else {
944
+ throw new SidechatAPIError(
945
+ `Couldn't upload image - error ${uploadReq.status}`,
946
+ );
947
+ }
948
+ } catch (e) {
949
+ throw new SidechatAPIError(e.message);
950
+ }
951
+ };
952
+
953
+ /**
954
+ * Sets the conversation icon of a user
955
+ * @method
956
+ * @since 2.2.1
957
+ * @param {String} userID - alphanumeric ID of user
958
+ * @param {String} emoji - emoji to set as icon
959
+ * @param {String} primaryColor - hex string (including #) of primary color
960
+ * @param {String} secondaryColor - hex string (including #) of secondary color
961
+ */
962
+ setUserIcon = async (userID, emoji, primaryColor, secondaryColor) => {
963
+ if (!this.userToken) {
964
+ throw new SidechatAPIError("User is not authenticated.");
965
+ }
966
+ try {
967
+ const res = await fetch(`${this.apiRoot}/v1/users/${userID}`, {
968
+ method: "PATCH",
969
+ headers: {
970
+ ...this.defaultHeaders,
971
+ "App-Version": "0",
972
+ Authorization: `Bearer ${this.userToken}`,
973
+ },
974
+ body: JSON.stringify({
975
+ conversation_icon: {
976
+ emoji: emoji,
977
+ secondary_color: secondaryColor,
978
+ is_migrated: true,
979
+ color: primaryColor,
980
+ },
981
+ }),
982
+ });
983
+ const json = await res.json();
984
+ return await json;
985
+ } catch (err) {
986
+ console.error(err);
987
+ throw new SidechatAPIError(`Failed to set icon.`);
988
+ }
989
+ };
990
+
991
+ /**
992
+ * Sets the bio text of a user
993
+ * @method
994
+ * @since 2.5.6
995
+ * @param {String} userID - alphanumeric ID of user
996
+ * @param {String} bio - text to set as bio
997
+ */
998
+ setUserBio = async (userID, bio) => {
999
+ if (!this.userToken) {
1000
+ throw new SidechatAPIError("User is not authenticated.");
1001
+ }
1002
+ try {
1003
+ const res = await fetch(`${this.apiRoot}/v1/users/${userID}`, {
1004
+ method: "PATCH",
1005
+ headers: {
1006
+ ...this.defaultHeaders,
1007
+ "App-Version": "5.4.22",
1008
+ Authorization: `Bearer ${this.userToken}`,
1009
+ },
1010
+ body: JSON.stringify({
1011
+ bio: bio,
1012
+ }),
1013
+ });
1014
+ const json = await res.json();
1015
+ return await json;
1016
+ } catch (err) {
1017
+ console.error(err);
1018
+ throw new SidechatAPIError(`Failed to set bio.`);
1019
+ }
1020
+ };
1021
+
1022
+ /**
1023
+ * Checks if user can set their username to a string
1024
+ * @method
1025
+ * @since 2.3.6
1026
+ * @param {String} username - string to check
1027
+ * @returns {Promise&lt;Boolean>} whether or not username is valid and unused
1028
+ */
1029
+ checkUsername = async (username) => {
1030
+ if (!this.userToken) {
1031
+ throw new SidechatAPIError("User is not authenticated.");
1032
+ }
1033
+ try {
1034
+ const res = await fetch(
1035
+ `${this.apiRoot}/v1/users/username?username=${username}`,
1036
+ {
1037
+ method: "GET",
1038
+ headers: {
1039
+ ...this.defaultHeaders,
1040
+ Authorization: `Bearer ${this.userToken}`,
1041
+ },
1042
+ },
1043
+ );
1044
+ if (res?.status == 200 || res?.status == 204) {
1045
+ return true;
1046
+ } else {
1047
+ return false;
1048
+ }
1049
+ } catch (err) {
1050
+ console.error(err);
1051
+ throw new SidechatAPIError(`Failed to check username.`);
1052
+ }
1053
+ };
1054
+
1055
+ /**
1056
+ * Changes the username of the current user
1057
+ * @method
1058
+ * @since 2.3.6
1059
+ * @param {String} userID - alphanumeric ID of user
1060
+ * @param {String} username - new username to set
1061
+ */
1062
+ setUsername = async (userID, username) => {
1063
+ if (!this.userToken) {
1064
+ throw new SidechatAPIError("User is not authenticated.");
1065
+ }
1066
+ try {
1067
+ const res = await fetch(`${this.apiRoot}/v1/users/${userID}`, {
1068
+ method: "PATCH",
1069
+ headers: {
1070
+ ...this.defaultHeaders,
1071
+ Authorization: `Bearer ${this.userToken}`,
1072
+ },
1073
+ body: JSON.stringify({
1074
+ username: username,
1075
+ }),
1076
+ });
1077
+ const json = await res.json();
1078
+ return await json.user;
1079
+ } catch (err) {
1080
+ console.error(err);
1081
+ throw new SidechatAPIError(`Failed to set icon.`);
1082
+ }
1083
+ };
1084
+
1085
+ /**
1086
+ * Fetches a public user profile
1087
+ * @method
1088
+ * @since 2.6.0
1089
+ * @param {String} username - username of the user to fetch
1090
+ * @returns {Promise&lt;types.SidechatProfile>}
1091
+ */
1092
+ getUserProfile = async (username) => {
1093
+ if (!this.userToken) {
1094
+ throw new SidechatAPIError("User is not authenticated.");
1095
+ }
1096
+ try {
1097
+ const res = await fetch(
1098
+ `${this.apiRoot}/v1/groups/username?username=${username}&amp;cacheBust=${Date.now()}`,
1099
+ {
1100
+ method: "GET",
1101
+ headers: {
1102
+ ...this.defaultHeaders,
1103
+ Authorization: `Bearer ${this.userToken}`,
1104
+ },
1105
+ },
1106
+ );
1107
+ const json = await res.json();
1108
+ return await json.group;
1109
+ } catch (err) {
1110
+ console.error(err);
1111
+ throw new SidechatAPIError(`Failed to set icon.`);
1112
+ }
1113
+ };
1114
+
1115
+ /**
1116
+ * Fetches a public user's posts
1117
+ * @method
1118
+ * @since 2.6.0
1119
+ * @param {String} username - username of the user to fetch
1120
+ * @returns {Promise&lt;types.SidechatPostOrComment[]>}
1121
+ */
1122
+ getUserPosts = async (username) => {
1123
+ if (!this.userToken) {
1124
+ throw new SidechatAPIError("User is not authenticated.");
1125
+ }
1126
+ try {
1127
+ const res = await fetch(
1128
+ `${this.apiRoot}/v1/users/posts?username=${username}`,
1129
+ {
1130
+ method: "GET",
1131
+ headers: {
1132
+ ...this.defaultHeaders,
1133
+ Authorization: `Bearer ${this.userToken}`,
1134
+ },
1135
+ },
1136
+ );
1137
+ const json = await res.json();
1138
+ return await json.posts;
1139
+ } catch (err) {
1140
+ console.error(err);
1141
+ throw new SidechatAPIError(`Failed to set icon.`);
1142
+ }
1143
+ };
1144
+
1145
+ /**
1146
+ * Marks an activity item as read
1147
+ * @method
1148
+ * @since 2.3.2
1149
+ * @param {String} activityID - alphanumeric ID of activity object
1150
+ */
1151
+ readActivity = async (activityID) => {
1152
+ if (!this.userToken) {
1153
+ throw new SidechatAPIError("User is not authenticated.");
1154
+ }
1155
+ try {
1156
+ const res = await fetch(`${this.apiRoot}/v1/activity/seen`, {
1157
+ method: "POST",
1158
+ headers: {
1159
+ ...this.defaultHeaders,
1160
+ Authorization: `Bearer ${this.userToken}`,
1161
+ },
1162
+ body: JSON.stringify({
1163
+ ids: [activityID],
1164
+ }),
1165
+ });
1166
+ const json = await res.json();
1167
+ return await json;
1168
+ } catch (err) {
1169
+ console.error(err);
1170
+ throw new SidechatAPIError(`Failed to mark activity as read.`);
1171
+ }
1172
+ };
1173
+
1174
+ /**
1175
+ * Retrieves joinable group chats
1176
+ * @method
1177
+ * @since 2.3.5
1178
+ */
1179
+ getGroupChats = async () => {
1180
+ if (!this.userToken) {
1181
+ throw new SidechatAPIError("User is not authenticated.");
1182
+ }
1183
+ try {
1184
+ const res = await fetch(
1185
+ `${this.apiRoot}/v1/chats/explore&amp;cacheBust=${Date.now()}`,
1186
+ {
1187
+ method: "GET",
1188
+ headers: {
1189
+ ...this.defaultHeaders,
1190
+ Authorization: `Bearer ${this.userToken}`,
1191
+ },
1192
+ },
1193
+ );
1194
+ const json = await res.json();
1195
+ return await json.chats;
1196
+ } catch (err) {
1197
+ console.error(err);
1198
+ throw new SidechatAPIError(`Failed to get groupchats.`);
1199
+ }
1200
+ };
1201
+
1202
+ /**
1203
+ * Joins a group chat. To mimic the official client, use the user's display name and icon by default.
1204
+ * @method
1205
+ * @param {String} groupChatID - alphanumeric ID of group chat to join
1206
+ * @param {String} displayName - display name to use in chat
1207
+ * @param {String} emoji - emoji to use as icon
1208
+ * @param {String} primaryColor - hex string of primary color
1209
+ * @param {String} secondaryColor - hex string of secondary color
1210
+ * @since 2.3.5
1211
+ */
1212
+ joinGroupChat = async (
1213
+ groupChatID,
1214
+ displayName,
1215
+ emoji,
1216
+ primaryColor,
1217
+ secondaryColor,
1218
+ ) => {
1219
+ if (!this.userToken) {
1220
+ throw new SidechatAPIError("User is not authenticated.");
1221
+ }
1222
+ try {
1223
+ const res = await fetch(`${this.apiRoot}/v1/chats/groups/join`, {
1224
+ method: "POST",
1225
+ headers: {
1226
+ ...this.defaultHeaders,
1227
+ Authorization: `Bearer ${this.userToken}`,
1228
+ },
1229
+ body: JSON.stringify({
1230
+ chat_id: groupChatID,
1231
+ identity: {
1232
+ display_name: displayName,
1233
+ emoji: emoji,
1234
+ secondary_color: secondaryColor,
1235
+ color: primaryColor,
1236
+ },
1237
+ }),
1238
+ });
1239
+ const json = await res.json();
1240
+ return await json;
1241
+ } catch (err) {
1242
+ console.error(err);
1243
+ throw new SidechatAPIError(`Failed to join groupchat.`);
1244
+ }
1245
+ };
1246
+
1247
+ /**
1248
+ * Gets a list of the user's direct messages
1249
+ * @method
1250
+ * @returns {Promise&lt;types.SidechatDirectThread[]>}
1251
+ * @since 2.4.4
1252
+ */
1253
+ getDMs = async () => {
1254
+ if (!this.userToken) {
1255
+ throw new SidechatAPIError("User is not authenticated.");
1256
+ }
1257
+ try {
1258
+ const res = await fetch(`${this.apiRoot}/v1/chats`, {
1259
+ method: "GET",
1260
+ headers: {
1261
+ ...this.defaultHeaders,
1262
+ Authorization: `Bearer ${this.userToken}`,
1263
+ },
1264
+ });
1265
+ const json = await res.json();
1266
+ const list = await json.chats;
1267
+ let r = [];
1268
+ list.forEach((o) => {
1269
+ r.push(o.chat);
1270
+ });
1271
+ return await r;
1272
+ } catch (err) {
1273
+ console.error(err);
1274
+ throw new SidechatAPIError(`Failed to fetch DMs.`);
1275
+ }
1276
+ };
1277
+
1278
+ /**
1279
+ * Gets a single direct message thread
1280
+ * @method
1281
+ * @param {String} id - alphanumeric ID of the chat to fetch
1282
+ * @returns {Promise&lt;types.SidechatDirectThread>}
1283
+ * @since 2.4.4
1284
+ */
1285
+ getDMThread = async (id) => {
1286
+ if (!this.userToken) {
1287
+ throw new SidechatAPIError("User is not authenticated.");
1288
+ }
1289
+ try {
1290
+ const res = await fetch(
1291
+ `${this.apiRoot}/v1/chats/messages?chat_id=${id}`,
1292
+ {
1293
+ method: "GET",
1294
+ headers: {
1295
+ ...this.defaultHeaders,
1296
+ Authorization: `Bearer ${this.userToken}`,
1297
+ },
1298
+ },
1299
+ );
1300
+ const json = await res.json();
1301
+ return await json.chat;
1302
+ } catch (err) {
1303
+ console.error(err);
1304
+ throw new SidechatAPIError(`Failed to fetch DM thread.`);
1305
+ }
1306
+ };
1307
+
1308
+ /**
1309
+ * Sends a message to an existing direct message thread - note that you must first use startDM() to start a thread.
1310
+ * @method
1311
+ * @param {String} chatID - alphanumeric ID of the chat to send to
1312
+ * @param {String} text - text content of message
1313
+ * @param {String} clientID - alphanumeric device ID
1314
+ * @param {types.SidechatAsset[]} assets - array of assets to send
1315
+ * @param {Boolean} anonymous - whether the DM should be sent anonymously
1316
+ * @since 2.4.4
1317
+ */
1318
+ sendDM = async (chatID, text, clientID, assets = [], anonymous = false) => {
1319
+ if (!this.userToken) {
1320
+ throw new SidechatAPIError("User is not authenticated.");
1321
+ }
1322
+ try {
1323
+ const res = await fetch(`${this.apiRoot}/v1/chats/send`, {
1324
+ method: "POST",
1325
+ headers: {
1326
+ ...this.defaultHeaders,
1327
+ Authorization: `Bearer ${this.userToken}`,
1328
+ },
1329
+ body: JSON.stringify({
1330
+ chat_id: chatID,
1331
+ text: text,
1332
+ client_id: clientID,
1333
+ anonymous: anonymous,
1334
+ assets: assets,
1335
+ }),
1336
+ });
1337
+ const json = await res.json();
1338
+ return await json;
1339
+ } catch (err) {
1340
+ console.error(err);
1341
+ throw new SidechatAPIError(`Failed to send message.`);
1342
+ }
1343
+ };
1344
+
1345
+ /**
1346
+ * Creates a new direct message thread
1347
+ * @method
1348
+ * @param {String} text - text content of message
1349
+ * @param {String} clientID - alphanumeric ID of devide
1350
+ * @param {String} postID - alphanumeric ID of post or comment
1351
+ * @param {Boolean} anonymous - whether the DM should be sent anonymously
1352
+ * @param {"feed"} postContext - context of post (mostly undocumented, defaults to "feed")
1353
+ * @since 2.4.4
1354
+ */
1355
+ startDM = async (
1356
+ text,
1357
+ clientID,
1358
+ postID,
1359
+ anonymous = false,
1360
+ postContext = "feed",
1361
+ ) => {
1362
+ if (!this.userToken) {
1363
+ throw new SidechatAPIError("User is not authenticated.");
1364
+ }
1365
+ try {
1366
+ const res = await fetch(`${this.apiRoot}/v1/chats/start`, {
1367
+ method: "POST",
1368
+ headers: {
1369
+ ...this.defaultHeaders,
1370
+ Authorization: `Bearer ${this.userToken}`,
1371
+ },
1372
+ body: JSON.stringify({
1373
+ text: text,
1374
+ client_id: clientID,
1375
+ post_id: postID,
1376
+ anonymous: anonymous,
1377
+ post_context: postContext,
1378
+ }),
1379
+ });
1380
+ const json = await res.json();
1381
+ return await json;
1382
+ } catch (err) {
1383
+ console.error(err);
1384
+ throw new SidechatAPIError(`Failed to start DM.`);
1385
+ }
1386
+ };
1387
+
1388
+ /**
1389
+ * Hides posts from user
1390
+ * @method
1391
+ * @param {String} postID - alphanumeric ID of post to hide
1392
+ * @since 2.6.2
1393
+ */
1394
+ hidePostsFromUser = async (postID) => {
1395
+ if (!this.userToken) {
1396
+ throw new SidechatAPIError("User is not authenticated.");
1397
+ }
1398
+ try {
1399
+ const res = await fetch(`${this.apiRoot}/v1/posts/hide_posts_from_user`, {
1400
+ method: "POST",
1401
+ headers: {
1402
+ ...this.defaultHeaders,
1403
+ Authorization: `Bearer ${this.userToken}`,
1404
+ },
1405
+ body: JSON.stringify({
1406
+ post_id: postID,
1407
+ post_context: "feed",
1408
+ report: false,
1409
+ }),
1410
+ });
1411
+ const json = await res.json();
1412
+ return await json;
1413
+ } catch (err) {
1414
+ console.error(err);
1415
+ throw new SidechatAPIError(`Failed to hide post.`);
1416
+ }
1417
+ };
1418
+
1419
+ /**
1420
+ * Unhides all posts from all users
1421
+ * @method
1422
+ * @since 2.6.2
1423
+ */
1424
+ unhidePostsFromAllUsers = async () => {
1425
+ if (!this.userToken) {
1426
+ throw new SidechatAPIError("User is not authenticated.");
1427
+ }
1428
+ try {
1429
+ const res = await fetch(`${this.apiRoot}/v1/users/unhide_all`, {
1430
+ method: "POST",
1431
+ headers: {
1432
+ ...this.defaultHeaders,
1433
+ Authorization: `Bearer ${this.userToken}`,
1434
+ },
1435
+ body: JSON.stringify({}),
1436
+ });
1437
+ const json = await res.json();
1438
+ return await json;
1439
+ } catch (err) {
1440
+ console.error(err);
1441
+ throw new SidechatAPIError(`Failed to unhide post.`);
1442
+ }
1443
+ };
1444
+ }
1445
+
1446
+ export default SidechatAPIClient;
1447
+ </code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">sidechat.js</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://github.com/micahlt/sidechat.js" target="_blank">GitHub</a></div><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/sidechat.js" target="_blank">NPM</a></div><div class="navbar-item"><a id="" href="https://offsides.micahlindley.com" target="_blank">Offsides (Sidechat for Android)</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-tutorials"><div>Tutorials</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="tutorial-Authentication.html">Authentication</a></div><div class="sidebar-section-children"><a href="tutorial-Email Registration.html">Email Registration</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="SidechatAPIClient.html">SidechatAPIClient</a></div><div class="sidebar-section-children"><a href="SidechatAPIError.html">SidechatAPIError</a></div><div class="sidebar-section-children"><a href="SidechatColorList.html">SidechatColorList</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#SidechatAssetMetadata">SidechatAssetMetadata</a></div><div class="sidebar-section-children"><a href="global.html#SidechatAuthToken">SidechatAuthToken</a></div><div class="sidebar-section-children"><a href="global.html#SidechatColor">SidechatColor</a></div><div class="sidebar-section-children"><a href="global.html#SidechatCurrentUser">SidechatCurrentUser</a></div><div class="sidebar-section-children"><a href="global.html#SidechatCursorString">SidechatCursorString</a></div><div class="sidebar-section-children"><a href="global.html#SidechatDirectMessage">SidechatDirectMessage</a></div><div class="sidebar-section-children"><a href="global.html#SidechatDirectThread">SidechatDirectThread</a></div><div class="sidebar-section-children"><a href="global.html#SidechatGroup">SidechatGroup</a></div><div class="sidebar-section-children"><a href="global.html#SidechatIcon">SidechatIcon</a></div><div class="sidebar-section-children"><a href="global.html#SidechatIdentity">SidechatIdentity</a></div><div class="sidebar-section-children"><a href="global.html#SidechatLibraryAsset">SidechatLibraryAsset</a></div><div class="sidebar-section-children"><a href="global.html#SidechatMembership">SidechatMembership</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPoll">SidechatPoll</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPollChoice">SidechatPollChoice</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPostOrComment">SidechatPostOrComment</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPostsAndCursor">SidechatPostsAndCursor</a></div><div class="sidebar-section-children"><a href="global.html#SidechatPrivateAssetURL">SidechatPrivateAssetURL</a></div><div class="sidebar-section-children"><a href="global.html#SidechatProfile">SidechatProfile</a></div><div class="sidebar-section-children"><a href="global.html#SidechatSimpleAsset">SidechatSimpleAsset</a></div><div class="sidebar-section-children"><a href="global.html#SidechatVoteString">SidechatVoteString</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>