sidechat.js 1.0.0 → 2.0.0-alpha.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.
Files changed (50) hide show
  1. package/.github/workflows/static.yml +51 -0
  2. package/README.md +15 -1
  3. package/dist/sidechat.cjs +1 -1
  4. package/dist/sidechat.cjs.map +1 -1
  5. package/dist/sidechat.modern.js +1 -1
  6. package/dist/sidechat.modern.js.map +1 -1
  7. package/dist/sidechat.module.js +1 -1
  8. package/dist/sidechat.module.js.map +1 -1
  9. package/dist/sidechat.umd.js +1 -1
  10. package/dist/sidechat.umd.js.map +1 -1
  11. package/docs/sidechat.js/1.0.0/global.html +1 -1
  12. package/docs/sidechat.js/1.0.0/index.html +2 -1
  13. package/docs/sidechat.js/1.0.0/index.js.html +1 -3
  14. package/docs/sidechat.js/1.0.0/types_SidechatTypes.js.html +1 -1
  15. package/docs/sidechat.js/2.0.0-alpha.0/SidechatAPIClient.html +3 -0
  16. package/docs/sidechat.js/2.0.0-alpha.0/classes_SidechatAPIClient.js.html +374 -0
  17. package/docs/sidechat.js/2.0.0-alpha.0/data/search.json +1 -0
  18. package/docs/sidechat.js/2.0.0-alpha.0/fonts/Inconsolata-Regular.ttf +0 -0
  19. package/docs/sidechat.js/2.0.0-alpha.0/fonts/OpenSans-Regular.ttf +0 -0
  20. package/docs/sidechat.js/2.0.0-alpha.0/fonts/WorkSans-Bold.ttf +0 -0
  21. package/docs/sidechat.js/2.0.0-alpha.0/global.html +3 -0
  22. package/docs/sidechat.js/2.0.0-alpha.0/index.html +4 -0
  23. package/docs/sidechat.js/2.0.0-alpha.0/scripts/core.js +702 -0
  24. package/docs/sidechat.js/2.0.0-alpha.0/scripts/core.min.js +23 -0
  25. package/docs/sidechat.js/2.0.0-alpha.0/scripts/resize.js +90 -0
  26. package/docs/sidechat.js/2.0.0-alpha.0/scripts/search.js +265 -0
  27. package/docs/sidechat.js/2.0.0-alpha.0/scripts/search.min.js +6 -0
  28. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/Apache-License-2.0.txt +202 -0
  29. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/fuse.js +9 -0
  30. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/hljs-line-num-original.js +369 -0
  31. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/hljs-line-num.js +1 -0
  32. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/hljs-original.js +5171 -0
  33. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/hljs.js +1 -0
  34. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/popper.js +5 -0
  35. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/tippy.js +1 -0
  36. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/tocbot.js +672 -0
  37. package/docs/sidechat.js/2.0.0-alpha.0/scripts/third-party/tocbot.min.js +1 -0
  38. package/docs/sidechat.js/2.0.0-alpha.0/styles/clean-jsdoc-theme-base.css +975 -0
  39. package/docs/sidechat.js/2.0.0-alpha.0/styles/clean-jsdoc-theme-dark.css +407 -0
  40. package/docs/sidechat.js/2.0.0-alpha.0/styles/clean-jsdoc-theme-light.css +388 -0
  41. package/docs/sidechat.js/2.0.0-alpha.0/styles/clean-jsdoc-theme.min.css +1 -0
  42. package/docs/sidechat.js/2.0.0-alpha.0/types_SidechatTypes.js.html +82 -0
  43. package/jsdoc.json +7 -4
  44. package/package.json +3 -3
  45. package/src/classes/SidechatAPIClient.js +371 -0
  46. package/src/index.js +4 -0
  47. package/index.js +0 -362
  48. /package/{classes → src/classes}/SidechatAPIError.js +0 -0
  49. /package/{tests → src/tests}/basicTest.js +0 -0
  50. /package/{types → src/types}/SidechatTypes.js +0 -0
@@ -0,0 +1,51 @@
1
+ # Simple workflow for deploying static content to GitHub Pages
2
+ name: Deploy docs site to Pages
3
+
4
+ on:
5
+ # Runs on pushes targeting the default branch
6
+ push:
7
+ branches: ["master"]
8
+
9
+ # Allows you to run this workflow manually from the Actions tab
10
+ workflow_dispatch:
11
+
12
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13
+ permissions:
14
+ contents: read
15
+ pages: write
16
+ id-token: write
17
+
18
+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19
+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20
+ concurrency:
21
+ group: "pages"
22
+ cancel-in-progress: false
23
+
24
+ jobs:
25
+ # Single deploy job since we're just deploying
26
+ deploy:
27
+ environment:
28
+ name: JSDoc Site
29
+ url: ${{ steps.deployment.outputs.page_url }}
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - name: Checkout
33
+ uses: actions/checkout@v4
34
+ - name: Install Node.js
35
+ uses: actions/setup-node@v4
36
+ with:
37
+ node-version: "20.x"
38
+ - name: Generate documentation
39
+ run: npm install && npm run docs
40
+ - name: Package.json info
41
+ uses: rexdefuror/read-package-json@v1.0.5
42
+ - name: Setup Pages
43
+ uses: actions/configure-pages@v4
44
+ - name: Upload artifact
45
+ uses: actions/upload-pages-artifact@v3
46
+ with:
47
+ # Upload entire repository
48
+ path: "./docs/sidechat.js/${{ env.PACKAGE_VERSION }}/"
49
+ - name: Deploy to GitHub Pages
50
+ id: deployment
51
+ uses: actions/deploy-pages@v4
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
1
  # sidechat.js
2
2
 
3
- A reverse-engineered API wrapper for [Sidechat](https://sidechat.lol). Easy to use, documented with JSDoc, and kept up to date as much as possible. Designed for [Offsides](https://github.com/micahlt/offsides), a third-party Sidechat client for Android devices.
3
+ [![NPM Downloads](https://img.shields.io/npm/dt/sidechat.js?label=downloads%20on%20npm)](https://npmjs.com/package/sidechat.js)
4
+
5
+ A reverse-engineered API wrapper for [Sidechat](https://sidechat.lol) in Node. Easy to use, documented with JSDoc, and kept up to date as much as possible. Designed for [Offsides](https://github.com/micahlt/offsides), a third-party Sidechat client for Android devices.
6
+
7
+ ## Getting Started
8
+
9
+ > Note: sidechat.js uses the Fetch API released in Node.js 18. If you're attempting to use it in a lower version of Node you will have to polyfill the fetch requests yourself.
10
+
11
+ Install sidechat.js with your preferred package manager:
12
+
13
+ ```bash
14
+ $ npm install sidechat.js
15
+ ```
16
+
17
+ No further setup should be needed. Just `import` or `require` sidechat.js into your code wherever you plan on using Sidechat's API. Extensive documentation can be found [here](https://micahlindley.com/sidechat.js).
package/dist/sidechat.cjs CHANGED
@@ -1,2 +1,2 @@
1
- function e(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(e=function(){return!!r})()}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},r.apply(this,arguments)}function t(e){return t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},t(e)}function o(e,r){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},o(e,r)}function n(r){var i="function"==typeof Map?new Map:void 0;return n=function(r){if(null===r||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(r){return"function"==typeof e}}(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(r))return i.get(r);i.set(r,n)}function n(){return function(r,t,n){if(e())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,t);var s=new(r.bind.apply(r,i));return n&&o(s,n.prototype),s}(r,arguments,t(this).constructor)}return n.prototype=Object.create(r.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,r)},n(r)}var i=/*#__PURE__*/function(e){var r,t;function n(r){var t;return(t=e.call(this,r)||this).name="SidechatAPIError",t}return t=e,(r=n).prototype=Object.create(t.prototype),r.prototype.constructor=r,o(r,t),n}(/*#__PURE__*/n(Error));function s(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}var c={Accept:"application/json","Content-Type":"application/json"};exports.checkEmailVerification=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/users/check_email_verified",{method:"GET",headers:r({},c,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.verified_email_updates_response)return e.verified_email_updates_response;throw new i((null==e?void 0:e.message)||"Email is not verified.")})})},function(){throw console.error(error),new i("Email is not verified.")}))}catch(e){return Promise.reject(e)}},exports.getAvailableGroups=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/groups/explore",{method:"GET",headers:r({},c,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.groups})})},function(e){throw console.error(e),new i("Failed to get groups from explore.")}))}catch(e){return Promise.reject(e)}},exports.getGroupPosts=function(e,t,o,n){void 0===o&&(o="hot");try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts?group_id="+e+"&type="+o+(n?"&cursor="+n:""),{method:"GET",headers:r({},c,{Authorization:"Bearer "+t})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},exports.getPostComments=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/comments/?post_id="+e,{method:"GET",headers:r({},c,{Authorization:"Bearer "+t})})).then(function(e){function r(e){var r=new Map,o=[];return e.forEach(function(e){r.set(e.id,e);var t=r.get(e.reply_post_id);t&&e.reply_post_id!==e.parent_post_id?(t.replies||(t.replies=[]),t.replies.push(e)):o.push(e)}),t(o)}function t(e){return e.reduce(function(e,r){return e.push(r),r.replies&&e.push.apply(e,t(r.replies)),e},[])}return Promise.resolve(e.json()).then(function(e){return r(e.posts)})})},function(e){throw console.error(e),new i("Failed to get comments on post.")}))}catch(e){return Promise.reject(e)}},exports.getUserAndGroup=function(e,t){void 0===t&&(t="");try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/updates?group_id="+t,{method:"GET",headers:r({},c,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},exports.loginViaSMS=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/login_register",{method:"POST",headers:c,body:JSON.stringify({phone_number:"+1"+e,version:3})})).then(function(e){return Promise.resolve(e.json())})},function(){throw console.error(error),new i("Failed to request SMS verification.")}))}catch(e){return Promise.reject(e)}},exports.registerEmail=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v2/users/register_email",{method:"POST",headers:r({},c,{Authorization:"Bearer "+t}),body:JSON.stringify({email:e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.message)throw new i(e.message);return e})})},function(){throw console.error(error),new i("Failed to request email verification.")}))}catch(e){return Promise.reject(e)}},exports.setAge=function(e,r){try{if(e<13)throw new i("You're too young to use Offsides.");return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/complete_registration",{method:"POST",headers:c,body:JSON.stringify({age:Number(e),registration_id:r})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},exports.setDeviceID=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/register_device_token",{method:"POST",headers:r({},c,{Authorization:"Bearer "+t}),body:JSON.stringify({build_type:"release",bundle_id:"com.flowerave.sidechat",device_token:e})})).then(function(r){return Promise.resolve(r.json()).then(function(r){return Promise.resolve(AsyncStorage.setItem("deviceID",e)).then(function(){return r})})})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},exports.setVote=function(e,t,o){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/set_vote",{method:"POST",headers:r({},c,{Authorization:"Bearer "+t}),body:JSON.stringify({post_id:e,vote_status:o})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to change the vote on post.")}))}catch(e){return Promise.reject(e)}},exports.verifySMSCode=function(e,r){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/verify_phone_number",{method:"POST",headers:c,body:JSON.stringify({phone_number:"+1"+e,code:r.toUpperCase()})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}};
1
+ function e(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(e=function(){return!!r})()}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},r.apply(this,arguments)}function t(e){return t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},t(e)}function o(e,r){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},o(e,r)}function n(r){var i="function"==typeof Map?new Map:void 0;return n=function(r){if(null===r||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(r){return"function"==typeof e}}(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(r))return i.get(r);i.set(r,n)}function n(){return function(r,t,n){if(e())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,t);var s=new(r.bind.apply(r,i));return n&&o(s,n.prototype),s}(r,arguments,t(this).constructor)}return n.prototype=Object.create(r.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,r)},n(r)}var i=/*#__PURE__*/function(e){var r,t;function n(r){var t;return(t=e.call(this,r)||this).name="SidechatAPIError",t}return t=e,(r=n).prototype=Object.create(t.prototype),r.prototype.constructor=r,o(r,t),n}(/*#__PURE__*/n(Error));function s(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}var u=function(){};u.defaultHeaders={Accept:"application/json","Content-Type":"application/json"},u.loginViaSMS=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/login_register",{method:"POST",headers:defaultHeaders,body:JSON.stringify({phone_number:"+1"+e,version:3})})).then(function(e){return Promise.resolve(e.json())})},function(){throw console.error(error),new i("Failed to request SMS verification.")}))}catch(e){return Promise.reject(e)}},u.verifySMSCode=function(e,r){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/verify_phone_number",{method:"POST",headers:defaultHeaders,body:JSON.stringify({phone_number:"+1"+e,code:r.toUpperCase()})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},u.setAge=function(e,r){try{if(e<13)throw new i("You're too young to use Offsides.");return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/complete_registration",{method:"POST",headers:defaultHeaders,body:JSON.stringify({age:Number(e),registration_id:r})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},u.registerEmail=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v2/users/register_email",{method:"POST",headers:r({},defaultHeaders,{Authorization:"Bearer "+t}),body:JSON.stringify({email:e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.message)throw new i(e.message);return e})})},function(){throw console.error(error),new i("Failed to request email verification.")}))}catch(e){return Promise.reject(e)}},u.checkEmailVerification=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/users/check_email_verified",{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.verified_email_updates_response)return e.verified_email_updates_response;throw new i((null==e?void 0:e.message)||"Email is not verified.")})})},function(){throw console.error(error),new i("Email is not verified.")}))}catch(e){return Promise.reject(e)}},u.setDeviceID=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/register_device_token",{method:"POST",headers:r({},defaultHeaders,{Authorization:"Bearer "+t}),body:JSON.stringify({build_type:"release",bundle_id:"com.flowerave.sidechat",device_token:e})})).then(function(r){return Promise.resolve(r.json()).then(function(r){return Promise.resolve(AsyncStorage.setItem("deviceID",e)).then(function(){return r})})})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},u.getUserAndGroup=function(e,t){void 0===t&&(t="");try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/updates?group_id="+t,{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},u.getGroupPosts=function(e,t,o,n){void 0===o&&(o="hot");try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts?group_id="+e+"&type="+o+(n?"&cursor="+n:""),{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+t})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},u.setVote=function(e,t,o){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/set_vote",{method:"POST",headers:r({},defaultHeaders,{Authorization:"Bearer "+t}),body:JSON.stringify({post_id:e,vote_status:o})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to change the vote on post.")}))}catch(e){return Promise.reject(e)}},u.getPostComments=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/comments/?post_id="+e,{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+t})})).then(function(e){function r(e){var r=new Map,o=[];return e.forEach(function(e){r.set(e.id,e);var t=r.get(e.reply_post_id);t&&e.reply_post_id!==e.parent_post_id?(t.replies||(t.replies=[]),t.replies.push(e)):o.push(e)}),t(o)}function t(e){return e.reduce(function(e,r){return e.push(r),r.replies&&e.push.apply(e,t(r.replies)),e},[])}return Promise.resolve(e.json()).then(function(e){return r(e.posts)})})},function(e){throw console.error(e),new i("Failed to get comments on post.")}))}catch(e){return Promise.reject(e)}},u.getAvailableGroups=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/groups/explore",{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.groups})})},function(e){throw console.error(e),new i("Failed to get groups from explore.")}))}catch(e){return Promise.reject(e)}},exports.SidechatAPIClient=u,exports.SidechatAPIError=i;
2
2
  //# sourceMappingURL=sidechat.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"sidechat.cjs","sources":["../classes/SidechatAPIError.js","../index.js"],"sourcesContent":["class SidechatAPIError extends Error {\r\n constructor(message) {\r\n super(message);\r\n this.name = \"SidechatAPIError\";\r\n }\r\n}\r\n\r\nexport default SidechatAPIError;\r\n","import \"./types/SidechatTypes.js\";\r\nimport SidechatAPIError from \"./classes/SidechatAPIError.js\";\r\nconst defaultHeaders = {\r\n Accept: \"application/json\",\r\n \"Content-Type\": \"application/json\",\r\n};\r\n\r\n/**\r\n * Initiate the login process with a phone number. Should be followed up with verifySMSCode().\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to\r\n */\r\nconst loginViaSMS = async (phoneNumber) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/login_register`, {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n version: 3,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request SMS verification.\");\r\n }\r\n};\r\n\r\n/**\r\n * Verify the code sent via SMS with loginViaSMS().\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to\r\n * @param {String} code - the verification code\r\n */\r\nconst verifySMSCode = async (phoneNumber, code) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/verify_phone_number`, {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n code: code.toUpperCase(),\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n};\r\n\r\n/**\r\n * Set the user's age\r\n * @param {Number} age - user's age in years\r\n * @param {String} registrationID - the registration ID generated by verifySMSCode()\r\n */\r\nconst setAge = async (age, registrationID) => {\r\n if (age < 13) {\r\n throw new SidechatAPIError(\"You're too young to use Offsides.\");\r\n }\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/complete_registration`,\r\n {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n age: Number(age),\r\n registration_id: registrationID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n};\r\n\r\n/**\r\n * Initiate the email setup process. Should be followed up with checkEmailVerification().\r\n * @param {String} email - school email address to send verification code to\r\n * @param {String} token - user bearer token\r\n */\r\nconst registerEmail = async (email, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v2/users/register_email`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n email: email,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.message) {\r\n throw new SidechatAPIError(json.message);\r\n }\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request email verification.\");\r\n }\r\n};\r\n\r\n/**\r\n * Check is the user's email is verified.\r\n * @param {String} token - user bearer token\r\n */\r\nconst checkEmailVerification = async (token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/users/check_email_verified`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.verified_email_updates_response) {\r\n return json.verified_email_updates_response;\r\n } else {\r\n throw new SidechatAPIError(json?.message || \"Email is not verified.\");\r\n }\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Email is not verified.\");\r\n }\r\n};\r\n\r\n/**\r\n * Set the device ID of the current user\r\n * @param {String} deviceId - the device ID to set\r\n * @param {String} token - the user bearer token\r\n */\r\nconst setDeviceID = async (deviceID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/register_device_token`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n build_type: \"release\",\r\n bundle_id: \"com.flowerave.sidechat\",\r\n device_token: deviceID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n await AsyncStorage.setItem(\"deviceID\", deviceID);\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n};\r\n\r\n/**\r\n * Get updated status for user and group\r\n * @param {String} token - user bearer token\r\n * @param {String} [groupID] - ID of a specific group to retrieve info from\r\n * @returns\r\n */\r\nconst getUserAndGroup = async (token, groupID = \"\") => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/updates?group_id=${groupID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n};\r\n\r\n/**\r\n * Fetches posts from the specified category in a group\r\n * @param {String} groupID - group ID\r\n * @param {String} token - user bearer token\r\n * @param {\"hot\"|\"recent\"|\"top\"} category - category to filter posts\r\n * @param {SidechatCursorString} [cursor] - cursor string\r\n * @returns {{posts: SidechatPostOrComment[], cursor: SidechatCursorString}} List of posts and cursor\r\n */\r\nconst getGroupPosts = async (groupID, token, category = \"hot\", cursor) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts?group_id=${groupID}&type=${category}${\r\n cursor ? \"&cursor=\" + cursor : \"\"\r\n }`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n};\r\n\r\n/**\r\n * Upvote or downvote, or unvote a post\r\n * @param {String} postID - post ID to vote on\r\n * @param {String} token - user bearer token\r\n * @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote\r\n * @returns\r\n */\r\nconst setVote = async (postID, token, action) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/posts/set_vote`, {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n post_id: postID,\r\n vote_status: action,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to change the vote on post.`);\r\n }\r\n};\r\n\r\n/**\r\n * Get all the commments on a post\r\n * @param {String} postID - post ID to get comments for\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatPostOrComment[]} list of comments\r\n */\r\nconst getPostComments = async (postID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts/comments/?post_id=${postID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n // Function to preprocess the comments and organize them into a nested structure\r\n function preprocessComments(apiComments) {\r\n // Map to store comments by their IDs for efficient lookup\r\n const commentMap = new Map();\r\n // List to store top-level comments\r\n const topLevelComments = [];\r\n\r\n // Iterate through the API comments\r\n apiComments.forEach((comment) => {\r\n // Store the comment in the map with its ID as the key\r\n commentMap.set(comment.id, comment);\r\n // Get the parent comment using the reply_post_id\r\n const parentComment = commentMap.get(comment.reply_post_id);\r\n // Check if the comment is a top-level comment\r\n if (\r\n !parentComment ||\r\n comment.reply_post_id === comment.parent_post_id\r\n ) {\r\n // If it's a top-level comment, push it to the topLevelComments array\r\n topLevelComments.push(comment);\r\n } else {\r\n // If it's a reply, add it to the parent comment's replies array\r\n if (!parentComment.replies) parentComment.replies = [];\r\n parentComment.replies.push(comment);\r\n }\r\n });\r\n\r\n // Flatten the nested structure and return a single list of comments\r\n return flattenComments(topLevelComments);\r\n }\r\n\r\n // Function to flatten nested comments into a single list\r\n function flattenComments(comments) {\r\n // Use reduce to flatten the nested comments array into a single list\r\n return comments.reduce((flatComments, comment) => {\r\n // Push the current comment to the flatComments array\r\n flatComments.push(comment);\r\n // If the current comment has replies, recursively flatten them and push to the flatComments array\r\n if (comment.replies)\r\n flatComments.push(...flattenComments(comment.replies));\r\n // Return the flatComments array\r\n return flatComments;\r\n }, []);\r\n }\r\n\r\n const sortedComments = preprocessComments(json.posts);\r\n return sortedComments;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get comments on post.`);\r\n }\r\n};\r\n\r\n/**\r\n * Gets groups to be displayed on the \"Explore Groups\" page\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatGroup}\r\n */\r\nconst getAvailableGroups = async (token) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/groups/explore`, {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n });\r\n const json = await res.json();\r\n return json.groups;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get groups from explore.`);\r\n }\r\n};\r\n\r\nexport {\r\n loginViaSMS,\r\n verifySMSCode,\r\n setAge,\r\n setDeviceID,\r\n registerEmail,\r\n checkEmailVerification,\r\n getUserAndGroup,\r\n getGroupPosts,\r\n setVote,\r\n getPostComments,\r\n getAvailableGroups,\r\n};\r\n"],"names":["SidechatAPIError","_Error","message","_this","call","name","_wrapNativeSuper","Error","_catch","body","recover","result","e","then","defaultHeaders","Accept","token","Promise","resolve","fetch","method","headers","_extends","Authorization","res","json","verified_email_updates_response","console","error","reject","groups","err","groupID","category","cursor","postID","preprocessComments","apiComments","commentMap","Map","topLevelComments","forEach","comment","set","id","parentComment","get","reply_post_id","parent_post_id","replies","push","flattenComments","comments","reduce","flatComments","apply","posts","phoneNumber","JSON","stringify","phone_number","version","email","age","registrationID","Number","registration_id","deviceID","build_type","bundle_id","device_token","AsyncStorage","setItem","action","post_id","vote_status","code","toUpperCase"],"mappings":"g0CAAMA,wBAAgBC,WACpB,SAAAD,EAAYE,GAASC,IAAAA,EAEY,OAD/BA,EAAAF,EAAAG,UAAMF,UACDG,KAAO,mBAAmBF,CACjC,CAAC,SAJmBF,KAAAD,yEAInBA,CAAA,eAAAM,EAJ4BC,QCkjBxB,SAASC,EAAOC,EAAMC,GAC5B,IACC,IAAIC,EAASF,GACd,CAAE,MAAMG,GACP,OAAOF,EAAQE,EAChB,CACA,OAAID,GAAUA,EAAOE,KACbF,EAAOE,UAAK,EAAQH,GAErBC,CACR,CA1jBA,IAAMG,EAAiB,CACrBC,OAAQ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C,QAASP,EACTL,KAAMiD,KAAKC,UAAU,CACnBC,aAAY,KAAOH,EACnBmB,KAAMA,EAAKC,mBAEbhE,KAPIW,SAAAA,UAAGP,QAAAC,QAQUM,EAAIC,OAEzB,EAAA,WAASM,GAEP,MADAJ,QAAQC,MAAMG,GACJ,IAAA/B,EAAiB,2BAC7B,GACF,CAAC,MAAAY,UAAAK,QAAAY,OAAAjB,EAOD,CAAA"}
1
+ {"version":3,"file":"sidechat.cjs","sources":["../src/classes/SidechatAPIError.js","../src/classes/SidechatAPIClient.js"],"sourcesContent":["class SidechatAPIError extends Error {\r\n constructor(message) {\r\n super(message);\r\n this.name = \"SidechatAPIError\";\r\n }\r\n}\r\n\r\nexport default SidechatAPIError;\r\n","import \"../types/SidechatTypes.js\";\r\nimport SidechatAPIError from \"../classes/SidechatAPIError.js\";\r\n\r\n/**\r\n * API client class for making requests to Sidechat's private API. As of now all methods are static.\r\n * @class\r\n * @since 2.0.0-alpha.0\r\n * @todo Add functionality for constructing a client with or without a token and having it keep track of requests/caching, etc\r\n */\r\nclass SidechatAPIClient {\r\n static defaultHeaders = {\r\n Accept: \"application/json\",\r\n \"Content-Type\": \"application/json\",\r\n };\r\n\r\n /**\r\n * Initiate the login process with a phone number. Should be followed up with verifySMSCode().\r\n * @method\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to\r\n */\r\n static loginViaSMS = async (phoneNumber) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/login_register`, {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n version: 3,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request SMS verification.\");\r\n }\r\n };\r\n\r\n /**\r\n * Verify the code sent via SMS with loginViaSMS().\r\n * @method\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to\r\n * @param {String} code - the verification code\r\n */\r\n static verifySMSCode = async (phoneNumber, code) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/verify_phone_number`,\r\n {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n code: code.toUpperCase(),\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n };\r\n\r\n /**\r\n * Set the user's age\r\n * @method\r\n * @param {Number} age - user's age in years\r\n * @param {String} registrationID - the registration ID generated by verifySMSCode()\r\n */\r\n static setAge = async (age, registrationID) => {\r\n if (age < 13) {\r\n throw new SidechatAPIError(\"You're too young to use Offsides.\");\r\n }\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/complete_registration`,\r\n {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n age: Number(age),\r\n registration_id: registrationID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n };\r\n\r\n /**\r\n * Initiate the email setup process. Should be followed up with checkEmailVerification().\r\n * @method\r\n * @param {String} email - school email address to send verification code to\r\n * @param {String} token - user bearer token\r\n */\r\n static registerEmail = async (email, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v2/users/register_email`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n email: email,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.message) {\r\n throw new SidechatAPIError(json.message);\r\n }\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request email verification.\");\r\n }\r\n };\r\n\r\n /**\r\n * Check is the user's email is verified.\r\n * @method\r\n * @param {String} token - user bearer token\r\n */\r\n static checkEmailVerification = async (token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/users/check_email_verified`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.verified_email_updates_response) {\r\n return json.verified_email_updates_response;\r\n } else {\r\n throw new SidechatAPIError(json?.message || \"Email is not verified.\");\r\n }\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Email is not verified.\");\r\n }\r\n };\r\n\r\n /**\r\n * Set the device ID of the current user\r\n * @method\r\n * @param {String} deviceId - the device ID to set\r\n * @param {String} token - the user bearer token\r\n */\r\n static setDeviceID = async (deviceID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/register_device_token`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n build_type: \"release\",\r\n bundle_id: \"com.flowerave.sidechat\",\r\n device_token: deviceID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n await AsyncStorage.setItem(\"deviceID\", deviceID);\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n };\r\n\r\n /**\r\n * Get updated status for user and group\r\n * @method\r\n * @param {String} token - user bearer token\r\n * @param {String} [groupID] - ID of a specific group to retrieve info from\r\n */\r\n static getUserAndGroup = async (token, groupID = \"\") => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/updates?group_id=${groupID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n };\r\n\r\n /**\r\n * Fetches posts from the specified category in a group\r\n * @method\r\n * @param {String} groupID - group ID\r\n * @param {String} token - user bearer token\r\n * @param {\"hot\"|\"recent\"|\"top\"} category - category to filter posts\r\n * @param {SidechatCursorString} [cursor] - cursor string\r\n * @returns {{posts: SidechatPostOrComment[], cursor: SidechatCursorString}} List of posts and cursor\r\n */\r\n static getGroupPosts = async (groupID, token, category = \"hot\", cursor) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts?group_id=${groupID}&type=${category}${\r\n cursor ? \"&cursor=\" + cursor : \"\"\r\n }`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n };\r\n\r\n /**\r\n * Upvote or downvote, or unvote a post\r\n * @method\r\n * @param {String} postID - post ID to vote on\r\n * @param {String} token - user bearer token\r\n * @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote\r\n */\r\n static setVote = async (postID, token, action) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/posts/set_vote`, {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n post_id: postID,\r\n vote_status: action,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to change the vote on post.`);\r\n }\r\n };\r\n\r\n /**\r\n * Get all the commments on a post\r\n * @method\r\n * @param {String} postID - post ID to get comments for\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatPostOrComment[]} list of comments\r\n */\r\n static getPostComments = async (postID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts/comments/?post_id=${postID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n // Function to preprocess the comments and organize them into a nested structure\r\n function preprocessComments(apiComments) {\r\n // Map to store comments by their IDs for efficient lookup\r\n const commentMap = new Map();\r\n // List to store top-level comments\r\n const topLevelComments = [];\r\n\r\n // Iterate through the API comments\r\n apiComments.forEach((comment) => {\r\n // Store the comment in the map with its ID as the key\r\n commentMap.set(comment.id, comment);\r\n // Get the parent comment using the reply_post_id\r\n const parentComment = commentMap.get(comment.reply_post_id);\r\n // Check if the comment is a top-level comment\r\n if (\r\n !parentComment ||\r\n comment.reply_post_id === comment.parent_post_id\r\n ) {\r\n // If it's a top-level comment, push it to the topLevelComments array\r\n topLevelComments.push(comment);\r\n } else {\r\n // If it's a reply, add it to the parent comment's replies array\r\n if (!parentComment.replies) parentComment.replies = [];\r\n parentComment.replies.push(comment);\r\n }\r\n });\r\n\r\n // Flatten the nested structure and return a single list of comments\r\n return flattenComments(topLevelComments);\r\n }\r\n\r\n // Function to flatten nested comments into a single list\r\n function flattenComments(comments) {\r\n // Use reduce to flatten the nested comments array into a single list\r\n return comments.reduce((flatComments, comment) => {\r\n // Push the current comment to the flatComments array\r\n flatComments.push(comment);\r\n // If the current comment has replies, recursively flatten them and push to the flatComments array\r\n if (comment.replies)\r\n flatComments.push(...flattenComments(comment.replies));\r\n // Return the flatComments array\r\n return flatComments;\r\n }, []);\r\n }\r\n\r\n const sortedComments = preprocessComments(json.posts);\r\n return sortedComments;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get comments on post.`);\r\n }\r\n };\r\n\r\n /**\r\n * Gets groups to be displayed on the \"Explore Groups\" page\r\n * @method\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatGroup}\r\n */\r\n static getAvailableGroups = async (token) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/groups/explore`, {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n });\r\n const json = await res.json();\r\n return json.groups;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get groups from explore.`);\r\n }\r\n };\r\n}\r\n\r\nexport default SidechatAPIClient;\r\n"],"names":["SidechatAPIError","_Error","message","_this","call","name","_wrapNativeSuper","Error","_catch","body","recover","result","e","then","SidechatAPIClient","defaultHeaders","Accept","loginViaSMS","phoneNumber","Promise","resolve","fetch","method","headers","JSON","stringify","phone_number","version","res","json","console","error","reject","verifySMSCode","code","toUpperCase","err","setAge","age","registrationID","Number","registration_id","registerEmail","email","token","_extends","Authorization","checkEmailVerification","verified_email_updates_response","setDeviceID","deviceID","build_type","bundle_id","device_token","AsyncStorage","setItem","getUserAndGroup","groupID","getGroupPosts","category","cursor","setVote","postID","action","post_id","vote_status","getPostComments","preprocessComments","apiComments","commentMap","Map","topLevelComments","forEach","comment","set","id","parentComment","get","reply_post_id","parent_post_id","replies","push","flattenComments","comments","reduce","flatComments","apply","posts","getAvailableGroups","groups"],"mappings":"4zCAAM,IAAAA,wBAAgBC,WACpB,SAAAD,EAAYE,GAASC,IAAAA,EAEY,OAD/BA,EAAAF,EAAAG,UAAMF,UACDG,KAAO,mBAAmBF,CACjC,CAAC,SAJmBF,KAAAD,yEAInBA,CAAA,eAAAM,EAJ4BC,QCkjBxB,SAASC,EAAOC,EAAMC,GAC5B,IACC,IAAIC,EAASF,GACd,CAAE,MAAMG,GACP,OAAOF,EAAQE,EAChB,CACA,OAAID,GAAUA,EAAOE,KACbF,EAAOE,UAAK,EAAQH,GAErBC,CACR,CAnjBM,IAAAG,EAAiB,aAAjBA,EACGC,eAAiB,CACtBC,OAAQ,mBACR,eAAgB,oBAHdF,EAWGG,YAAW,SAAUC,GAAW,WAAKC,QAAAC,QAAAZ,aACtCW,OAAAA,QAAAC,QACgBC,MAAK,6CAA+C,CACpEC,OAAQ,OACRC,QAASR,eACTN,KAAMe,KAA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/UGE,CAAAA,EAAAA,EAuVG0E,mBAAkB,SAAU5C,GAAU,IAAA,OAAAzB,QAAAC,QAAAZ,aACvCW,OAAAA,QAAAC,QACgBC,MAAK,6CAA+C,CACpEC,OAAQ,MACRC,QAAOsB,EAAA,CAAA,EACF9B,eAAc,CACjB+B,cAAyBF,UAAAA,OAE3B/B,KAAA,SANIe,GAAG,OAAAT,QAAAC,QAOUQ,EAAIC,QAAMhB,cAAvBgB,GACN,OAAOA,EAAK4D,MAAO,EAAA,EACrB,EAAC,SAAQrD,GAEP,MADAN,QAAQC,MAAMK,OACJpC,uCACZ,GACF,CAAC,MAAAY,GAAAO,OAAAA,QAAAa,OAAApB,EAGH,CAAA"}
@@ -1,2 +1,2 @@
1
- function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},e.apply(this,arguments)}class t extends Error{constructor(e){super(e),this.name="SidechatAPIError"}}const r={Accept:"application/json","Content-Type":"application/json"},o=async e=>{try{const t=await fetch("https://api.sidechat.lol/v1/login_register",{method:"POST",headers:r,body:JSON.stringify({phone_number:`+1${e}`,version:3})});return await t.json()}catch(e){throw console.error(error),new t("Failed to request SMS verification.")}},s=async(e,o)=>{try{const t=await fetch("https://api.sidechat.lol/v1/verify_phone_number",{method:"POST",headers:r,body:JSON.stringify({phone_number:`+1${e}`,code:o.toUpperCase()})});return await t.json()}catch(e){throw console.error(e),new t("Failed verify this code.")}},a=async(e,o)=>{if(e<13)throw new t("You're too young to use Offsides.");try{const t=await fetch("https://api.sidechat.lol/v1/complete_registration",{method:"POST",headers:r,body:JSON.stringify({age:Number(e),registration_id:o})});return await t.json()}catch(e){throw console.error(e),new t("Failed verify this code.")}},i=async(o,s)=>{try{const a=await fetch("https://api.sidechat.lol/v2/users/register_email",{method:"POST",headers:e({},r,{Authorization:`Bearer ${s}`}),body:JSON.stringify({email:o})}),i=await a.json();if(i.message)throw new t(i.message);return i}catch(e){throw console.error(error),new t("Failed to request email verification.")}},n=async o=>{try{const s=await fetch("https://api.sidechat.lol/v1/users/check_email_verified",{method:"GET",headers:e({},r,{Authorization:`Bearer ${o}`})}),a=await s.json();if(a.verified_email_updates_response)return a.verified_email_updates_response;throw new t((null==a?void 0:a.message)||"Email is not verified.")}catch(e){throw console.error(error),new t("Email is not verified.")}},c=async(o,s)=>{try{const t=await fetch("https://api.sidechat.lol/v1/register_device_token",{method:"POST",headers:e({},r,{Authorization:`Bearer ${s}`}),body:JSON.stringify({build_type:"release",bundle_id:"com.flowerave.sidechat",device_token:o})}),a=await t.json();return await AsyncStorage.setItem("deviceID",o),a}catch(e){throw console.error(e),new t("Failed verify this code.")}},h=async(o,s="")=>{try{const t=await fetch(`https://api.sidechat.lol/v1/updates?group_id=${s}`,{method:"GET",headers:e({},r,{Authorization:`Bearer ${o}`})});return await t.json()}catch(e){throw console.error(e),new t("Failed to get posts from group.")}},d=async(o,s,a="hot",i)=>{try{const t=await fetch(`https://api.sidechat.lol/v1/posts?group_id=${o}&type=${a}${i?"&cursor="+i:""}`,{method:"GET",headers:e({},r,{Authorization:`Bearer ${s}`})});return await t.json()}catch(e){throw console.error(e),new t("Failed to get posts from group.")}},p=async(o,s,a)=>{try{const t=await fetch("https://api.sidechat.lol/v1/posts/set_vote",{method:"POST",headers:e({},r,{Authorization:`Bearer ${s}`}),body:JSON.stringify({post_id:o,vote_status:a})});return await t.json()}catch(e){throw console.error(e),new t("Failed to change the vote on post.")}},l=async(o,s)=>{try{const a=await fetch(`https://api.sidechat.lol/v1/posts/comments/?post_id=${o}`,{method:"GET",headers:e({},r,{Authorization:`Bearer ${s}`})});function i(e){const t=new Map,r=[];return e.forEach(e=>{t.set(e.id,e);const o=t.get(e.reply_post_id);o&&e.reply_post_id!==e.parent_post_id?(o.replies||(o.replies=[]),o.replies.push(e)):r.push(e)}),n(r)}function n(e){return e.reduce((e,t)=>(e.push(t),t.replies&&e.push(...n(t.replies)),e),[])}return i((await a.json()).posts)}catch(c){throw console.error(c),new t("Failed to get comments on post.")}},u=async o=>{try{const t=await fetch("https://api.sidechat.lol/v1/groups/explore",{method:"GET",headers:e({},r,{Authorization:`Bearer ${o}`})});return(await t.json()).groups}catch(e){throw console.error(e),new t("Failed to get groups from explore.")}};export{n as checkEmailVerification,u as getAvailableGroups,d as getGroupPosts,l as getPostComments,h as getUserAndGroup,o as loginViaSMS,i as registerEmail,a as setAge,c as setDeviceID,p as setVote,s as verifySMSCode};
1
+ function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},e.apply(this,arguments)}class t extends Error{constructor(e){super(e),this.name="SidechatAPIError"}}class r{}r.defaultHeaders={Accept:"application/json","Content-Type":"application/json"},r.loginViaSMS=async e=>{try{const t=await fetch("https://api.sidechat.lol/v1/login_register",{method:"POST",headers:defaultHeaders,body:JSON.stringify({phone_number:`+1${e}`,version:3})});return await t.json()}catch(e){throw console.error(error),new t("Failed to request SMS verification.")}},r.verifySMSCode=async(e,r)=>{try{const t=await fetch("https://api.sidechat.lol/v1/verify_phone_number",{method:"POST",headers:defaultHeaders,body:JSON.stringify({phone_number:`+1${e}`,code:r.toUpperCase()})});return await t.json()}catch(e){throw console.error(e),new t("Failed verify this code.")}},r.setAge=async(e,r)=>{if(e<13)throw new t("You're too young to use Offsides.");try{const t=await fetch("https://api.sidechat.lol/v1/complete_registration",{method:"POST",headers:defaultHeaders,body:JSON.stringify({age:Number(e),registration_id:r})});return await t.json()}catch(e){throw console.error(e),new t("Failed verify this code.")}},r.registerEmail=async(r,o)=>{try{const a=await fetch("https://api.sidechat.lol/v2/users/register_email",{method:"POST",headers:e({},defaultHeaders,{Authorization:`Bearer ${o}`}),body:JSON.stringify({email:r})}),s=await a.json();if(s.message)throw new t(s.message);return s}catch(e){throw console.error(error),new t("Failed to request email verification.")}},r.checkEmailVerification=async r=>{try{const o=await fetch("https://api.sidechat.lol/v1/users/check_email_verified",{method:"GET",headers:e({},defaultHeaders,{Authorization:`Bearer ${r}`})}),a=await o.json();if(a.verified_email_updates_response)return a.verified_email_updates_response;throw new t((null==a?void 0:a.message)||"Email is not verified.")}catch(e){throw console.error(error),new t("Email is not verified.")}},r.setDeviceID=async(r,o)=>{try{const t=await fetch("https://api.sidechat.lol/v1/register_device_token",{method:"POST",headers:e({},defaultHeaders,{Authorization:`Bearer ${o}`}),body:JSON.stringify({build_type:"release",bundle_id:"com.flowerave.sidechat",device_token:r})}),a=await t.json();return await AsyncStorage.setItem("deviceID",r),a}catch(e){throw console.error(e),new t("Failed verify this code.")}},r.getUserAndGroup=async(r,o="")=>{try{const t=await fetch(`https://api.sidechat.lol/v1/updates?group_id=${o}`,{method:"GET",headers:e({},defaultHeaders,{Authorization:`Bearer ${r}`})});return await t.json()}catch(e){throw console.error(e),new t("Failed to get posts from group.")}},r.getGroupPosts=async(r,o,a="hot",s)=>{try{const t=await fetch(`https://api.sidechat.lol/v1/posts?group_id=${r}&type=${a}${s?"&cursor="+s:""}`,{method:"GET",headers:e({},defaultHeaders,{Authorization:`Bearer ${o}`})});return await t.json()}catch(e){throw console.error(e),new t("Failed to get posts from group.")}},r.setVote=async(r,o,a)=>{try{const t=await fetch("https://api.sidechat.lol/v1/posts/set_vote",{method:"POST",headers:e({},defaultHeaders,{Authorization:`Bearer ${o}`}),body:JSON.stringify({post_id:r,vote_status:a})});return await t.json()}catch(e){throw console.error(e),new t("Failed to change the vote on post.")}},r.getPostComments=async(r,o)=>{try{const a=await fetch(`https://api.sidechat.lol/v1/posts/comments/?post_id=${r}`,{method:"GET",headers:e({},defaultHeaders,{Authorization:`Bearer ${o}`})});function s(e){const t=new Map,r=[];return e.forEach(e=>{t.set(e.id,e);const o=t.get(e.reply_post_id);o&&e.reply_post_id!==e.parent_post_id?(o.replies||(o.replies=[]),o.replies.push(e)):r.push(e)}),i(r)}function i(e){return e.reduce((e,t)=>(e.push(t),t.replies&&e.push(...i(t.replies)),e),[])}return s((await a.json()).posts)}catch(n){throw console.error(n),new t("Failed to get comments on post.")}},r.getAvailableGroups=async r=>{try{const t=await fetch("https://api.sidechat.lol/v1/groups/explore",{method:"GET",headers:e({},defaultHeaders,{Authorization:`Bearer ${r}`})});return(await t.json()).groups}catch(e){throw console.error(e),new t("Failed to get groups from explore.")}};export{r as SidechatAPIClient,t as SidechatAPIError};
2
2
  //# sourceMappingURL=sidechat.modern.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sidechat.modern.js","sources":["../classes/SidechatAPIError.js","../index.js"],"sourcesContent":["class SidechatAPIError extends Error {\r\n constructor(message) {\r\n super(message);\r\n this.name = \"SidechatAPIError\";\r\n }\r\n}\r\n\r\nexport default SidechatAPIError;\r\n","import \"./types/SidechatTypes.js\";\r\nimport SidechatAPIError from \"./classes/SidechatAPIError.js\";\r\nconst defaultHeaders = {\r\n Accept: \"application/json\",\r\n \"Content-Type\": \"application/json\",\r\n};\r\n\r\n/**\r\n * Initiate the login process with a phone number. Should be followed up with verifySMSCode().\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to\r\n */\r\nconst loginViaSMS = async (phoneNumber) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/login_register`, {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n version: 3,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request SMS verification.\");\r\n }\r\n};\r\n\r\n/**\r\n * Verify the code sent via SMS with loginViaSMS().\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to\r\n * @param {String} code - the verification code\r\n */\r\nconst verifySMSCode = async (phoneNumber, code) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/verify_phone_number`, {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n code: code.toUpperCase(),\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n};\r\n\r\n/**\r\n * Set the user's age\r\n * @param {Number} age - user's age in years\r\n * @param {String} registrationID - the registration ID generated by verifySMSCode()\r\n */\r\nconst setAge = async (age, registrationID) => {\r\n if (age < 13) {\r\n throw new SidechatAPIError(\"You're too young to use Offsides.\");\r\n }\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/complete_registration`,\r\n {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n age: Number(age),\r\n registration_id: registrationID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n};\r\n\r\n/**\r\n * Initiate the email setup process. Should be followed up with checkEmailVerification().\r\n * @param {String} email - school email address to send verification code to\r\n * @param {String} token - user bearer token\r\n */\r\nconst registerEmail = async (email, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v2/users/register_email`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n email: email,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.message) {\r\n throw new SidechatAPIError(json.message);\r\n }\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request email verification.\");\r\n }\r\n};\r\n\r\n/**\r\n * Check is the user's email is verified.\r\n * @param {String} token - user bearer token\r\n */\r\nconst checkEmailVerification = async (token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/users/check_email_verified`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.verified_email_updates_response) {\r\n return json.verified_email_updates_response;\r\n } else {\r\n throw new SidechatAPIError(json?.message || \"Email is not verified.\");\r\n }\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Email is not verified.\");\r\n }\r\n};\r\n\r\n/**\r\n * Set the device ID of the current user\r\n * @param {String} deviceId - the device ID to set\r\n * @param {String} token - the user bearer token\r\n */\r\nconst setDeviceID = async (deviceID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/register_device_token`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n build_type: \"release\",\r\n bundle_id: \"com.flowerave.sidechat\",\r\n device_token: deviceID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n await AsyncStorage.setItem(\"deviceID\", deviceID);\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n};\r\n\r\n/**\r\n * Get updated status for user and group\r\n * @param {String} token - user bearer token\r\n * @param {String} [groupID] - ID of a specific group to retrieve info from\r\n * @returns\r\n */\r\nconst getUserAndGroup = async (token, groupID = \"\") => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/updates?group_id=${groupID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n};\r\n\r\n/**\r\n * Fetches posts from the specified category in a group\r\n * @param {String} groupID - group ID\r\n * @param {String} token - user bearer token\r\n * @param {\"hot\"|\"recent\"|\"top\"} category - category to filter posts\r\n * @param {SidechatCursorString} [cursor] - cursor string\r\n * @returns {{posts: SidechatPostOrComment[], cursor: SidechatCursorString}} List of posts and cursor\r\n */\r\nconst getGroupPosts = async (groupID, token, category = \"hot\", cursor) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts?group_id=${groupID}&type=${category}${\r\n cursor ? \"&cursor=\" + cursor : \"\"\r\n }`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n};\r\n\r\n/**\r\n * Upvote or downvote, or unvote a post\r\n * @param {String} postID - post ID to vote on\r\n * @param {String} token - user bearer token\r\n * @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote\r\n * @returns\r\n */\r\nconst setVote = async (postID, token, action) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/posts/set_vote`, {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n post_id: postID,\r\n vote_status: action,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to change the vote on post.`);\r\n }\r\n};\r\n\r\n/**\r\n * Get all the commments on a post\r\n * @param {String} postID - post ID to get comments for\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatPostOrComment[]} list of comments\r\n */\r\nconst getPostComments = async (postID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts/comments/?post_id=${postID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n // Function to preprocess the comments and organize them into a nested structure\r\n function preprocessComments(apiComments) {\r\n // Map to store comments by their IDs for efficient lookup\r\n const commentMap = new Map();\r\n // List to store top-level comments\r\n const topLevelComments = [];\r\n\r\n // Iterate through the API comments\r\n apiComments.forEach((comment) => {\r\n // Store the comment in the map with its ID as the key\r\n commentMap.set(comment.id, comment);\r\n // Get the parent comment using the reply_post_id\r\n const parentComment = commentMap.get(comment.reply_post_id);\r\n // Check if the comment is a top-level comment\r\n if (\r\n !parentComment ||\r\n comment.reply_post_id === comment.parent_post_id\r\n ) {\r\n // If it's a top-level comment, push it to the topLevelComments array\r\n topLevelComments.push(comment);\r\n } else {\r\n // If it's a reply, add it to the parent comment's replies array\r\n if (!parentComment.replies) parentComment.replies = [];\r\n parentComment.replies.push(comment);\r\n }\r\n });\r\n\r\n // Flatten the nested structure and return a single list of comments\r\n return flattenComments(topLevelComments);\r\n }\r\n\r\n // Function to flatten nested comments into a single list\r\n function flattenComments(comments) {\r\n // Use reduce to flatten the nested comments array into a single list\r\n return comments.reduce((flatComments, comment) => {\r\n // Push the current comment to the flatComments array\r\n flatComments.push(comment);\r\n // If the current comment has replies, recursively flatten them and push to the flatComments array\r\n if (comment.replies)\r\n flatComments.push(...flattenComments(comment.replies));\r\n // Return the flatComments array\r\n return flatComments;\r\n }, []);\r\n }\r\n\r\n const sortedComments = preprocessComments(json.posts);\r\n return sortedComments;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get comments on post.`);\r\n }\r\n};\r\n\r\n/**\r\n * Gets groups to be displayed on the \"Explore Groups\" page\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatGroup}\r\n */\r\nconst getAvailableGroups = async (token) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/groups/explore`, {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n });\r\n const json = await res.json();\r\n return json.groups;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get groups from explore.`);\r\n }\r\n};\r\n\r\nexport {\r\n loginViaSMS,\r\n verifySMSCode,\r\n setAge,\r\n setDeviceID,\r\n registerEmail,\r\n checkEmailVerification,\r\n getUserAndGroup,\r\n getGroupPosts,\r\n setVote,\r\n getPostComments,\r\n getAvailableGroups,\r\n};\r\n"],"names":["SidechatAPIError","Error","constructor","message","super","this","name","defaultHeaders","Accept","loginViaSMS","async","res","fetch","method","headers","body","JSON","stringify","phone_number","phoneNumber","version","json","err","console","error","verifySMSCode","code","toUpperCase","setAge","age","registrationID","Number","registration_id","registerEmail","email","token","_extends","Authorization","checkEmailVerification","verified_email_updates_response","setDeviceID","deviceID","build_type","bundle_id","device_token","AsyncStorage","setItem","getUserAndGroup","groupID","getGroupPosts","category","cursor","setVote","postID","action","post_id","vote_status","getPostComments","preprocessComments","apiComments","commentMap","Map","topLevelComments","forEach","comment","set","id","parentComment","get","reply_post_id","parent_post_id","replies","push","flattenComments","comments","reduce","flatComments","posts","getAvailableGroups","groups"],"mappings":"oOAAA,MAAMA,UAAyBC,MAC7BC,WAAAA,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,kBACd,ECFF,MAAMC,EAAiB,CACrBC,OAAQ,mBACR,eAAgB,oBAOZC,EAAcC,UAClB,IACE,MAAMC,QAAYC,MAAO,6CAA6C,CACpEC,OAAQ,OACRC,QAASP,EACTQ,KAAMC,KAAKC,UAAU,CACnBC,aAAe,KAAIC,IACnBC,QAAS,MAIb,aADmBT,EAAIU,MAEzB,CAAE,MAAOC,GAEP,MADAC,QAAQC,MAAMA,OACJ,IAAAxB,EAAiB,sCAC7B,GAQIyB,EAAgBf,MAAOS,EAAaO,KACxC,IACE,MAAMf,QAAYC,MAAO,kDAAkD,CACzEC,OAAQ,OACRC,QAASP,EACTQ,KAAMC,KAAKC,UAAU,CACnBC,aAAe,KAAIC,IACnBO,KAAMA,EAAKC,kBAIf,aADmBhB,EAAIU,MAEzB,CAAE,MAAOC,GAEP,MADAC,QAAQC,MAAMF,GACJ,IAAAtB,EAAiB,2BAC7B,GAQI4B,EAASlB,MA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K,IAAID,EAAQE,GAAIF,GAE3B,MAAMG,EAAgBP,EAAWQ,IAAIJ,EAAQK,eAG1CF,GACDH,EAAQK,gBAAkBL,EAAQM,gBAM7BH,EAAcI,UAASJ,EAAcI,QAAU,IACpDJ,EAAcI,QAAQC,KAAKR,IAJ3BF,EAAiBU,KAAKR,EAKxB,GAIKS,EAAgBX,EACzB,CAGA,SAASW,EAAgBC,GAEvB,OAAOA,EAASC,OAAO,CAACC,EAAcZ,KAEpCY,EAAaJ,KAAKR,GAEdA,EAAQO,SACVK,EAAaJ,QAAQC,EAAgBT,EAAQO,UAExCK,GACN,GACL,CAGA,OADuBlB,SA9CJ/C,EAAIU,QA8CwBwD,MAEjD,CAAE,MAAOvD,GAEP,MADAC,QAAQC,MAAMF,GACJ,IAAAtB,EAAkB,kCAC9B,GAQI8E,EAAqBpE,UACzB,IACE,MAAMC,QAAYC,MAAO,6CAA6C,CACpEC,OAAQ,MACRC,QAAOsB,EAAA,CAAA,EACF7B,EACH8B,CAAAA,cAAgB,UAASF,QAI7B,aADmBxB,EAAIU,QACX0D,MACd,CAAE,MAAOzD,GAEP,MADAC,QAAQC,MAAMF,GACJ,IAAAtB,EAAkB,qCAC9B"}
1
+ {"version":3,"file":"sidechat.modern.js","sources":["../src/classes/SidechatAPIError.js","../src/classes/SidechatAPIClient.js"],"sourcesContent":["class SidechatAPIError extends Error {\r\n constructor(message) {\r\n super(message);\r\n this.name = \"SidechatAPIError\";\r\n }\r\n}\r\n\r\nexport default SidechatAPIError;\r\n","import \"../types/SidechatTypes.js\";\r\nimport SidechatAPIError from \"../classes/SidechatAPIError.js\";\r\n\r\n/**\r\n * API client class for making requests to Sidechat's private API. As of now all methods are static.\r\n * @class\r\n * @since 2.0.0-alpha.0\r\n * @todo Add functionality for constructing a client with or without a token and having it keep track of requests/caching, etc\r\n */\r\nclass SidechatAPIClient {\r\n static defaultHeaders = {\r\n Accept: \"application/json\",\r\n \"Content-Type\": \"application/json\",\r\n };\r\n\r\n /**\r\n * Initiate the login process with a phone number. Should be followed up with verifySMSCode().\r\n * @method\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to\r\n */\r\n static loginViaSMS = async (phoneNumber) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/login_register`, {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n version: 3,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request SMS verification.\");\r\n }\r\n };\r\n\r\n /**\r\n * Verify the code sent via SMS with loginViaSMS().\r\n * @method\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to\r\n * @param {String} code - the verification code\r\n */\r\n static verifySMSCode = async (phoneNumber, code) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/verify_phone_number`,\r\n {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n code: code.toUpperCase(),\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n };\r\n\r\n /**\r\n * Set the user's age\r\n * @method\r\n * @param {Number} age - user's age in years\r\n * @param {String} registrationID - the registration ID generated by verifySMSCode()\r\n */\r\n static setAge = async (age, registrationID) => {\r\n if (age < 13) {\r\n throw new SidechatAPIError(\"You're too young to use Offsides.\");\r\n }\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/complete_registration`,\r\n {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n age: Number(age),\r\n registration_id: registrationID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n };\r\n\r\n /**\r\n * Initiate the email setup process. Should be followed up with checkEmailVerification().\r\n * @method\r\n * @param {String} email - school email address to send verification code to\r\n * @param {String} token - user bearer token\r\n */\r\n static registerEmail = async (email, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v2/users/register_email`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n email: email,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.message) {\r\n throw new SidechatAPIError(json.message);\r\n }\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request email verification.\");\r\n }\r\n };\r\n\r\n /**\r\n * Check is the user's email is verified.\r\n * @method\r\n * @param {String} token - user bearer token\r\n */\r\n static checkEmailVerification = async (token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/users/check_email_verified`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.verified_email_updates_response) {\r\n return json.verified_email_updates_response;\r\n } else {\r\n throw new SidechatAPIError(json?.message || \"Email is not verified.\");\r\n }\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Email is not verified.\");\r\n }\r\n };\r\n\r\n /**\r\n * Set the device ID of the current user\r\n * @method\r\n * @param {String} deviceId - the device ID to set\r\n * @param {String} token - the user bearer token\r\n */\r\n static setDeviceID = async (deviceID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/register_device_token`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n build_type: \"release\",\r\n bundle_id: \"com.flowerave.sidechat\",\r\n device_token: deviceID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n await AsyncStorage.setItem(\"deviceID\", deviceID);\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n };\r\n\r\n /**\r\n * Get updated status for user and group\r\n * @method\r\n * @param {String} token - user bearer token\r\n * @param {String} [groupID] - ID of a specific group to retrieve info from\r\n */\r\n static getUserAndGroup = async (token, groupID = \"\") => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/updates?group_id=${groupID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n };\r\n\r\n /**\r\n * Fetches posts from the specified category in a group\r\n * @method\r\n * @param {String} groupID - group ID\r\n * @param {String} token - user bearer token\r\n * @param {\"hot\"|\"recent\"|\"top\"} category - category to filter posts\r\n * @param {SidechatCursorString} [cursor] - cursor string\r\n * @returns {{posts: SidechatPostOrComment[], cursor: SidechatCursorString}} List of posts and cursor\r\n */\r\n static getGroupPosts = async (groupID, token, category = \"hot\", cursor) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts?group_id=${groupID}&type=${category}${\r\n cursor ? \"&cursor=\" + cursor : \"\"\r\n }`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n };\r\n\r\n /**\r\n * Upvote or downvote, or unvote a post\r\n * @method\r\n * @param {String} postID - post ID to vote on\r\n * @param {String} token - user bearer token\r\n * @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote\r\n */\r\n static setVote = async (postID, token, action) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/posts/set_vote`, {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n post_id: postID,\r\n vote_status: action,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to change the vote on post.`);\r\n }\r\n };\r\n\r\n /**\r\n * Get all the commments on a post\r\n * @method\r\n * @param {String} postID - post ID to get comments for\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatPostOrComment[]} list of comments\r\n */\r\n static getPostComments = async (postID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts/comments/?post_id=${postID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n // Function to preprocess the comments and organize them into a nested structure\r\n function preprocessComments(apiComments) {\r\n // Map to store comments by their IDs for efficient lookup\r\n const commentMap = new Map();\r\n // List to store top-level comments\r\n const topLevelComments = [];\r\n\r\n // Iterate through the API comments\r\n apiComments.forEach((comment) => {\r\n // Store the comment in the map with its ID as the key\r\n commentMap.set(comment.id, comment);\r\n // Get the parent comment using the reply_post_id\r\n const parentComment = commentMap.get(comment.reply_post_id);\r\n // Check if the comment is a top-level comment\r\n if (\r\n !parentComment ||\r\n comment.reply_post_id === comment.parent_post_id\r\n ) {\r\n // If it's a top-level comment, push it to the topLevelComments array\r\n topLevelComments.push(comment);\r\n } else {\r\n // If it's a reply, add it to the parent comment's replies array\r\n if (!parentComment.replies) parentComment.replies = [];\r\n parentComment.replies.push(comment);\r\n }\r\n });\r\n\r\n // Flatten the nested structure and return a single list of comments\r\n return flattenComments(topLevelComments);\r\n }\r\n\r\n // Function to flatten nested comments into a single list\r\n function flattenComments(comments) {\r\n // Use reduce to flatten the nested comments array into a single list\r\n return comments.reduce((flatComments, comment) => {\r\n // Push the current comment to the flatComments array\r\n flatComments.push(comment);\r\n // If the current comment has replies, recursively flatten them and push to the flatComments array\r\n if (comment.replies)\r\n flatComments.push(...flattenComments(comment.replies));\r\n // Return the flatComments array\r\n return flatComments;\r\n }, []);\r\n }\r\n\r\n const sortedComments = preprocessComments(json.posts);\r\n return sortedComments;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get comments on post.`);\r\n }\r\n };\r\n\r\n /**\r\n * Gets groups to be displayed on the \"Explore Groups\" page\r\n * @method\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatGroup}\r\n */\r\n static getAvailableGroups = async (token) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/groups/explore`, {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n });\r\n const json = await res.json();\r\n return json.groups;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get groups from explore.`);\r\n }\r\n };\r\n}\r\n\r\nexport default SidechatAPIClient;\r\n"],"names":["SidechatAPIError","Error","constructor","message","super","this","name","SidechatAPIClient","defaultHeaders","Accept","loginViaSMS","async","res","fetch","method","headers","body","JSON","stringify","phone_number","phoneNumber","version","json","err","console","error","verifySMSCode","code","toUpperCase","setAge","age","registrationID","Number","registration_id","registerEmail","email","token","_extends","Authorization","checkEmailVerification","verified_email_updates_response","setDeviceID","deviceID","build_type","bundle_id","device_token","AsyncStorage","setItem","getUserAndGroup","groupID","getGroupPosts","category","cursor","setVote","postID","action","post_id","vote_status","getPostComments","preprocessComments","apiComments","commentMap","Map","topLevelComments","forEach","comment","set","id","parentComment","get","reply_post_id","parent_post_id","replies","push","flattenComments","comments","reduce","flatComments","posts","getAvailableGroups","groups"],"mappings":"oOAAA,MAAMA,UAAyBC,MAC7BC,WAAAA,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,kBACd,ECKF,MAAMC,GAAAA,EACGC,eAAi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AAO,6CAA6C,CACpEC,OAAQ,MACRC,QAAOsB,EAAA,CAAA,EACF7B,eAAc,CACjB8B,cAAgB,UAASF,QAI7B,aADmBxB,EAAIU,QACX0D,MACd,CAAE,MAAOzD,GAEP,MADAC,QAAQC,MAAMF,OACJvB,EAAkB,qCAC9B"}
@@ -1,2 +1,2 @@
1
- function e(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(e=function(){return!!r})()}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},r.apply(this,arguments)}function t(e){return t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},t(e)}function o(e,r){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},o(e,r)}function n(r){var i="function"==typeof Map?new Map:void 0;return n=function(r){if(null===r||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(r){return"function"==typeof e}}(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(r))return i.get(r);i.set(r,n)}function n(){return function(r,t,n){if(e())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,t);var s=new(r.bind.apply(r,i));return n&&o(s,n.prototype),s}(r,arguments,t(this).constructor)}return n.prototype=Object.create(r.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,r)},n(r)}var i=/*#__PURE__*/function(e){var r,t;function n(r){var t;return(t=e.call(this,r)||this).name="SidechatAPIError",t}return t=e,(r=n).prototype=Object.create(t.prototype),r.prototype.constructor=r,o(r,t),n}(/*#__PURE__*/n(Error));function s(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}var u={Accept:"application/json","Content-Type":"application/json"},c=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/login_register",{method:"POST",headers:u,body:JSON.stringify({phone_number:"+1"+e,version:3})})).then(function(e){return Promise.resolve(e.json())})},function(){throw console.error(error),new i("Failed to request SMS verification.")}))}catch(e){return Promise.reject(e)}},a=function(e,r){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/verify_phone_number",{method:"POST",headers:u,body:JSON.stringify({phone_number:"+1"+e,code:r.toUpperCase()})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},h=function(e,r){try{if(e<13)throw new i("You're too young to use Offsides.");return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/complete_registration",{method:"POST",headers:u,body:JSON.stringify({age:Number(e),registration_id:r})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},l=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v2/users/register_email",{method:"POST",headers:r({},u,{Authorization:"Bearer "+t}),body:JSON.stringify({email:e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.message)throw new i(e.message);return e})})},function(){throw console.error(error),new i("Failed to request email verification.")}))}catch(e){return Promise.reject(e)}},f=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/users/check_email_verified",{method:"GET",headers:r({},u,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.verified_email_updates_response)return e.verified_email_updates_response;throw new i((null==e?void 0:e.message)||"Email is not verified.")})})},function(){throw console.error(error),new i("Email is not verified.")}))}catch(e){return Promise.reject(e)}},p=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/register_device_token",{method:"POST",headers:r({},u,{Authorization:"Bearer "+t}),body:JSON.stringify({build_type:"release",bundle_id:"com.flowerave.sidechat",device_token:e})})).then(function(r){return Promise.resolve(r.json()).then(function(r){return Promise.resolve(AsyncStorage.setItem("deviceID",e)).then(function(){return r})})})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},d=function(e,t){void 0===t&&(t="");try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/updates?group_id="+t,{method:"GET",headers:r({},u,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},v=function(e,t,o,n){void 0===o&&(o="hot");try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts?group_id="+e+"&type="+o+(n?"&cursor="+n:""),{method:"GET",headers:r({},u,{Authorization:"Bearer "+t})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},m=function(e,t,o){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/set_vote",{method:"POST",headers:r({},u,{Authorization:"Bearer "+t}),body:JSON.stringify({post_id:e,vote_status:o})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to change the vote on post.")}))}catch(e){return Promise.reject(e)}},y=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/comments/?post_id="+e,{method:"GET",headers:r({},u,{Authorization:"Bearer "+t})})).then(function(e){function r(e){var r=new Map,o=[];return e.forEach(function(e){r.set(e.id,e);var t=r.get(e.reply_post_id);t&&e.reply_post_id!==e.parent_post_id?(t.replies||(t.replies=[]),t.replies.push(e)):o.push(e)}),t(o)}function t(e){return e.reduce(function(e,r){return e.push(r),r.replies&&e.push.apply(e,t(r.replies)),e},[])}return Promise.resolve(e.json()).then(function(e){return r(e.posts)})})},function(e){throw console.error(e),new i("Failed to get comments on post.")}))}catch(e){return Promise.reject(e)}},P=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/groups/explore",{method:"GET",headers:r({},u,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.groups})})},function(e){throw console.error(e),new i("Failed to get groups from explore.")}))}catch(e){return Promise.reject(e)}};export{f as checkEmailVerification,P as getAvailableGroups,v as getGroupPosts,y as getPostComments,d as getUserAndGroup,c as loginViaSMS,l as registerEmail,h as setAge,p as setDeviceID,m as setVote,a as verifySMSCode};
1
+ function e(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(e=function(){return!!r})()}function r(){return r=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},r.apply(this,arguments)}function t(e){return t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},t(e)}function o(e,r){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},o(e,r)}function n(r){var i="function"==typeof Map?new Map:void 0;return n=function(r){if(null===r||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(r){return"function"==typeof e}}(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(r))return i.get(r);i.set(r,n)}function n(){return function(r,t,n){if(e())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,t);var s=new(r.bind.apply(r,i));return n&&o(s,n.prototype),s}(r,arguments,t(this).constructor)}return n.prototype=Object.create(r.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,r)},n(r)}var i=/*#__PURE__*/function(e){var r,t;function n(r){var t;return(t=e.call(this,r)||this).name="SidechatAPIError",t}return t=e,(r=n).prototype=Object.create(t.prototype),r.prototype.constructor=r,o(r,t),n}(/*#__PURE__*/n(Error));function s(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}var u=function(){};u.defaultHeaders={Accept:"application/json","Content-Type":"application/json"},u.loginViaSMS=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/login_register",{method:"POST",headers:defaultHeaders,body:JSON.stringify({phone_number:"+1"+e,version:3})})).then(function(e){return Promise.resolve(e.json())})},function(){throw console.error(error),new i("Failed to request SMS verification.")}))}catch(e){return Promise.reject(e)}},u.verifySMSCode=function(e,r){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/verify_phone_number",{method:"POST",headers:defaultHeaders,body:JSON.stringify({phone_number:"+1"+e,code:r.toUpperCase()})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},u.setAge=function(e,r){try{if(e<13)throw new i("You're too young to use Offsides.");return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/complete_registration",{method:"POST",headers:defaultHeaders,body:JSON.stringify({age:Number(e),registration_id:r})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},u.registerEmail=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v2/users/register_email",{method:"POST",headers:r({},defaultHeaders,{Authorization:"Bearer "+t}),body:JSON.stringify({email:e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.message)throw new i(e.message);return e})})},function(){throw console.error(error),new i("Failed to request email verification.")}))}catch(e){return Promise.reject(e)}},u.checkEmailVerification=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/users/check_email_verified",{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.verified_email_updates_response)return e.verified_email_updates_response;throw new i((null==e?void 0:e.message)||"Email is not verified.")})})},function(){throw console.error(error),new i("Email is not verified.")}))}catch(e){return Promise.reject(e)}},u.setDeviceID=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/register_device_token",{method:"POST",headers:r({},defaultHeaders,{Authorization:"Bearer "+t}),body:JSON.stringify({build_type:"release",bundle_id:"com.flowerave.sidechat",device_token:e})})).then(function(r){return Promise.resolve(r.json()).then(function(r){return Promise.resolve(AsyncStorage.setItem("deviceID",e)).then(function(){return r})})})},function(e){throw console.error(e),new i("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},u.getUserAndGroup=function(e,t){void 0===t&&(t="");try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/updates?group_id="+t,{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},u.getGroupPosts=function(e,t,o,n){void 0===o&&(o="hot");try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts?group_id="+e+"&type="+o+(n?"&cursor="+n:""),{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+t})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},u.setVote=function(e,t,o){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/set_vote",{method:"POST",headers:r({},defaultHeaders,{Authorization:"Bearer "+t}),body:JSON.stringify({post_id:e,vote_status:o})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new i("Failed to change the vote on post.")}))}catch(e){return Promise.reject(e)}},u.getPostComments=function(e,t){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/comments/?post_id="+e,{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+t})})).then(function(e){function r(e){var r=new Map,o=[];return e.forEach(function(e){r.set(e.id,e);var t=r.get(e.reply_post_id);t&&e.reply_post_id!==e.parent_post_id?(t.replies||(t.replies=[]),t.replies.push(e)):o.push(e)}),t(o)}function t(e){return e.reduce(function(e,r){return e.push(r),r.replies&&e.push.apply(e,t(r.replies)),e},[])}return Promise.resolve(e.json()).then(function(e){return r(e.posts)})})},function(e){throw console.error(e),new i("Failed to get comments on post.")}))}catch(e){return Promise.reject(e)}},u.getAvailableGroups=function(e){try{return Promise.resolve(s(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/groups/explore",{method:"GET",headers:r({},defaultHeaders,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.groups})})},function(e){throw console.error(e),new i("Failed to get groups from explore.")}))}catch(e){return Promise.reject(e)}};export{u as SidechatAPIClient,i as SidechatAPIError};
2
2
  //# sourceMappingURL=sidechat.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sidechat.module.js","sources":["../classes/SidechatAPIError.js","../index.js"],"sourcesContent":["class SidechatAPIError extends Error {\r\n constructor(message) {\r\n super(message);\r\n this.name = \"SidechatAPIError\";\r\n }\r\n}\r\n\r\nexport default SidechatAPIError;\r\n","import \"./types/SidechatTypes.js\";\r\nimport SidechatAPIError from \"./classes/SidechatAPIError.js\";\r\nconst defaultHeaders = {\r\n Accept: \"application/json\",\r\n \"Content-Type\": \"application/json\",\r\n};\r\n\r\n/**\r\n * Initiate the login process with a phone number. Should be followed up with verifySMSCode().\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to\r\n */\r\nconst loginViaSMS = async (phoneNumber) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/login_register`, {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n version: 3,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request SMS verification.\");\r\n }\r\n};\r\n\r\n/**\r\n * Verify the code sent via SMS with loginViaSMS().\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to\r\n * @param {String} code - the verification code\r\n */\r\nconst verifySMSCode = async (phoneNumber, code) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/verify_phone_number`, {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n code: code.toUpperCase(),\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n};\r\n\r\n/**\r\n * Set the user's age\r\n * @param {Number} age - user's age in years\r\n * @param {String} registrationID - the registration ID generated by verifySMSCode()\r\n */\r\nconst setAge = async (age, registrationID) => {\r\n if (age < 13) {\r\n throw new SidechatAPIError(\"You're too young to use Offsides.\");\r\n }\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/complete_registration`,\r\n {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n age: Number(age),\r\n registration_id: registrationID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n};\r\n\r\n/**\r\n * Initiate the email setup process. Should be followed up with checkEmailVerification().\r\n * @param {String} email - school email address to send verification code to\r\n * @param {String} token - user bearer token\r\n */\r\nconst registerEmail = async (email, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v2/users/register_email`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n email: email,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.message) {\r\n throw new SidechatAPIError(json.message);\r\n }\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request email verification.\");\r\n }\r\n};\r\n\r\n/**\r\n * Check is the user's email is verified.\r\n * @param {String} token - user bearer token\r\n */\r\nconst checkEmailVerification = async (token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/users/check_email_verified`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.verified_email_updates_response) {\r\n return json.verified_email_updates_response;\r\n } else {\r\n throw new SidechatAPIError(json?.message || \"Email is not verified.\");\r\n }\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Email is not verified.\");\r\n }\r\n};\r\n\r\n/**\r\n * Set the device ID of the current user\r\n * @param {String} deviceId - the device ID to set\r\n * @param {String} token - the user bearer token\r\n */\r\nconst setDeviceID = async (deviceID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/register_device_token`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n build_type: \"release\",\r\n bundle_id: \"com.flowerave.sidechat\",\r\n device_token: deviceID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n await AsyncStorage.setItem(\"deviceID\", deviceID);\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n};\r\n\r\n/**\r\n * Get updated status for user and group\r\n * @param {String} token - user bearer token\r\n * @param {String} [groupID] - ID of a specific group to retrieve info from\r\n * @returns\r\n */\r\nconst getUserAndGroup = async (token, groupID = \"\") => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/updates?group_id=${groupID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n};\r\n\r\n/**\r\n * Fetches posts from the specified category in a group\r\n * @param {String} groupID - group ID\r\n * @param {String} token - user bearer token\r\n * @param {\"hot\"|\"recent\"|\"top\"} category - category to filter posts\r\n * @param {SidechatCursorString} [cursor] - cursor string\r\n * @returns {{posts: SidechatPostOrComment[], cursor: SidechatCursorString}} List of posts and cursor\r\n */\r\nconst getGroupPosts = async (groupID, token, category = \"hot\", cursor) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts?group_id=${groupID}&type=${category}${\r\n cursor ? \"&cursor=\" + cursor : \"\"\r\n }`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n};\r\n\r\n/**\r\n * Upvote or downvote, or unvote a post\r\n * @param {String} postID - post ID to vote on\r\n * @param {String} token - user bearer token\r\n * @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote\r\n * @returns\r\n */\r\nconst setVote = async (postID, token, action) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/posts/set_vote`, {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n post_id: postID,\r\n vote_status: action,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to change the vote on post.`);\r\n }\r\n};\r\n\r\n/**\r\n * Get all the commments on a post\r\n * @param {String} postID - post ID to get comments for\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatPostOrComment[]} list of comments\r\n */\r\nconst getPostComments = async (postID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts/comments/?post_id=${postID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n // Function to preprocess the comments and organize them into a nested structure\r\n function preprocessComments(apiComments) {\r\n // Map to store comments by their IDs for efficient lookup\r\n const commentMap = new Map();\r\n // List to store top-level comments\r\n const topLevelComments = [];\r\n\r\n // Iterate through the API comments\r\n apiComments.forEach((comment) => {\r\n // Store the comment in the map with its ID as the key\r\n commentMap.set(comment.id, comment);\r\n // Get the parent comment using the reply_post_id\r\n const parentComment = commentMap.get(comment.reply_post_id);\r\n // Check if the comment is a top-level comment\r\n if (\r\n !parentComment ||\r\n comment.reply_post_id === comment.parent_post_id\r\n ) {\r\n // If it's a top-level comment, push it to the topLevelComments array\r\n topLevelComments.push(comment);\r\n } else {\r\n // If it's a reply, add it to the parent comment's replies array\r\n if (!parentComment.replies) parentComment.replies = [];\r\n parentComment.replies.push(comment);\r\n }\r\n });\r\n\r\n // Flatten the nested structure and return a single list of comments\r\n return flattenComments(topLevelComments);\r\n }\r\n\r\n // Function to flatten nested comments into a single list\r\n function flattenComments(comments) {\r\n // Use reduce to flatten the nested comments array into a single list\r\n return comments.reduce((flatComments, comment) => {\r\n // Push the current comment to the flatComments array\r\n flatComments.push(comment);\r\n // If the current comment has replies, recursively flatten them and push to the flatComments array\r\n if (comment.replies)\r\n flatComments.push(...flattenComments(comment.replies));\r\n // Return the flatComments array\r\n return flatComments;\r\n }, []);\r\n }\r\n\r\n const sortedComments = preprocessComments(json.posts);\r\n return sortedComments;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get comments on post.`);\r\n }\r\n};\r\n\r\n/**\r\n * Gets groups to be displayed on the \"Explore Groups\" page\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatGroup}\r\n */\r\nconst getAvailableGroups = async (token) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/groups/explore`, {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n });\r\n const json = await res.json();\r\n return json.groups;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get groups from explore.`);\r\n }\r\n};\r\n\r\nexport {\r\n loginViaSMS,\r\n verifySMSCode,\r\n setAge,\r\n setDeviceID,\r\n registerEmail,\r\n checkEmailVerification,\r\n getUserAndGroup,\r\n getGroupPosts,\r\n setVote,\r\n getPostComments,\r\n getAvailableGroups,\r\n};\r\n"],"names":["SidechatAPIError","_Error","message","_this","call","name","_wrapNativeSuper","Error","_catch","body","recover","result","e","then","defaultHeaders","Accept","loginViaSMS","phoneNumber","Promise","resolve","fetch","method","headers","JSON","stringify","phone_number","version","res","json","console","error","reject","verifySMSCode","code","toUpperCase","err","setAge","age","registrationID","Number","registration_id","registerEmail","email","token","_extends","Authorization","checkEmailVerification","verified_email_updates_response","setDeviceID","deviceID","build_type","bundle_id","device_token","AsyncStorage","setItem","getUserAndGroup","groupID","getGroupPosts","category","cursor","setVote","postID","action","post_id","vote_status","getPostComments","preprocessComments","apiComments","commentMap","Map","topLevelComments","forEach","comment","set","id","parentComment","get","reply_post_id","parent_post_id","replies","push","flattenComments","comments","reduce","flatComments","apply","posts","getAvailableGroups","groups"],"mappings":"g0CAAMA,wBAAgBC,WACpB,SAAAD,EAAYE,GAASC,IAAAA,EAEY,OAD/BA,EAAAF,EAAAG,UAAMF,UACDG,KAAO,mBAAmBF,CACjC,CAAC,SAJmBF,KAAAD,yEAInBA,CAAA,eAAAM,EAJ4BC,QCkjBxB,SAASC,EAAOC,EAAMC,GAC5B,IACC,IAAIC,EAASF,GACd,CAAE,MAAMG,GACP,OAAOF,EAAQE,EAChB,CACA,OAAID,GAAUA,EAAOE,KACbF,EAAOE,UAAK,EAAQH,GAErBC,CACR,CA1jBA,IAAMG,EAAiB,CACrB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AC,QAAAX,aACtCU,OAAAA,QAAAC,QACgBC,MAAoD,6CAAA,CACpEC,OAAQ,MACRC,QAAOsB,EAAA,CAAA,EACF9B,EACH+B,CAAAA,wBAAyBF,OAE3B9B,KAAA,SANIc,GAAGT,OAAAA,QAAAC,QAOUQ,EAAIC,QAAMf,KAAA,SAAvBe,GACN,OAAOA,EAAK4D,MAAO,EACrB,EAAA,WAASrD,GAEP,MADAN,QAAQC,MAAMK,GACJ,IAAAnC,EAAqD,qCACjE,GACF,CAAC,MAAAY,GAAA,OAAAM,QAAAa,OAAAnB,EAAA,CAAA"}
1
+ {"version":3,"file":"sidechat.module.js","sources":["../src/classes/SidechatAPIError.js","../src/classes/SidechatAPIClient.js"],"sourcesContent":["class SidechatAPIError extends Error {\r\n constructor(message) {\r\n super(message);\r\n this.name = \"SidechatAPIError\";\r\n }\r\n}\r\n\r\nexport default SidechatAPIError;\r\n","import \"../types/SidechatTypes.js\";\r\nimport SidechatAPIError from \"../classes/SidechatAPIError.js\";\r\n\r\n/**\r\n * API client class for making requests to Sidechat's private API. As of now all methods are static.\r\n * @class\r\n * @since 2.0.0-alpha.0\r\n * @todo Add functionality for constructing a client with or without a token and having it keep track of requests/caching, etc\r\n */\r\nclass SidechatAPIClient {\r\n static defaultHeaders = {\r\n Accept: \"application/json\",\r\n \"Content-Type\": \"application/json\",\r\n };\r\n\r\n /**\r\n * Initiate the login process with a phone number. Should be followed up with verifySMSCode().\r\n * @method\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) to send verification code to\r\n */\r\n static loginViaSMS = async (phoneNumber) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/login_register`, {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n version: 3,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request SMS verification.\");\r\n }\r\n };\r\n\r\n /**\r\n * Verify the code sent via SMS with loginViaSMS().\r\n * @method\r\n * @param {Number} phoneNumber - US phone number (WITHOUT +1) that verification code was sent to\r\n * @param {String} code - the verification code\r\n */\r\n static verifySMSCode = async (phoneNumber, code) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/verify_phone_number`,\r\n {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n phone_number: `+1${phoneNumber}`,\r\n code: code.toUpperCase(),\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n };\r\n\r\n /**\r\n * Set the user's age\r\n * @method\r\n * @param {Number} age - user's age in years\r\n * @param {String} registrationID - the registration ID generated by verifySMSCode()\r\n */\r\n static setAge = async (age, registrationID) => {\r\n if (age < 13) {\r\n throw new SidechatAPIError(\"You're too young to use Offsides.\");\r\n }\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/complete_registration`,\r\n {\r\n method: \"POST\",\r\n headers: defaultHeaders,\r\n body: JSON.stringify({\r\n age: Number(age),\r\n registration_id: registrationID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n };\r\n\r\n /**\r\n * Initiate the email setup process. Should be followed up with checkEmailVerification().\r\n * @method\r\n * @param {String} email - school email address to send verification code to\r\n * @param {String} token - user bearer token\r\n */\r\n static registerEmail = async (email, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v2/users/register_email`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n email: email,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.message) {\r\n throw new SidechatAPIError(json.message);\r\n }\r\n return json;\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Failed to request email verification.\");\r\n }\r\n };\r\n\r\n /**\r\n * Check is the user's email is verified.\r\n * @method\r\n * @param {String} token - user bearer token\r\n */\r\n static checkEmailVerification = async (token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/users/check_email_verified`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n if (json.verified_email_updates_response) {\r\n return json.verified_email_updates_response;\r\n } else {\r\n throw new SidechatAPIError(json?.message || \"Email is not verified.\");\r\n }\r\n } catch (err) {\r\n console.error(error);\r\n throw new SidechatAPIError(\"Email is not verified.\");\r\n }\r\n };\r\n\r\n /**\r\n * Set the device ID of the current user\r\n * @method\r\n * @param {String} deviceId - the device ID to set\r\n * @param {String} token - the user bearer token\r\n */\r\n static setDeviceID = async (deviceID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/register_device_token`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n build_type: \"release\",\r\n bundle_id: \"com.flowerave.sidechat\",\r\n device_token: deviceID,\r\n }),\r\n }\r\n );\r\n const json = await res.json();\r\n await AsyncStorage.setItem(\"deviceID\", deviceID);\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(\"Failed verify this code.\");\r\n }\r\n };\r\n\r\n /**\r\n * Get updated status for user and group\r\n * @method\r\n * @param {String} token - user bearer token\r\n * @param {String} [groupID] - ID of a specific group to retrieve info from\r\n */\r\n static getUserAndGroup = async (token, groupID = \"\") => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/updates?group_id=${groupID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n };\r\n\r\n /**\r\n * Fetches posts from the specified category in a group\r\n * @method\r\n * @param {String} groupID - group ID\r\n * @param {String} token - user bearer token\r\n * @param {\"hot\"|\"recent\"|\"top\"} category - category to filter posts\r\n * @param {SidechatCursorString} [cursor] - cursor string\r\n * @returns {{posts: SidechatPostOrComment[], cursor: SidechatCursorString}} List of posts and cursor\r\n */\r\n static getGroupPosts = async (groupID, token, category = \"hot\", cursor) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts?group_id=${groupID}&type=${category}${\r\n cursor ? \"&cursor=\" + cursor : \"\"\r\n }`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get posts from group.`);\r\n }\r\n };\r\n\r\n /**\r\n * Upvote or downvote, or unvote a post\r\n * @method\r\n * @param {String} postID - post ID to vote on\r\n * @param {String} token - user bearer token\r\n * @param {SidechatVoteString} action - whether to upvote, downvote, or reset vote\r\n */\r\n static setVote = async (postID, token, action) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/posts/set_vote`, {\r\n method: \"POST\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n body: JSON.stringify({\r\n post_id: postID,\r\n vote_status: action,\r\n }),\r\n });\r\n const json = await res.json();\r\n return json;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to change the vote on post.`);\r\n }\r\n };\r\n\r\n /**\r\n * Get all the commments on a post\r\n * @method\r\n * @param {String} postID - post ID to get comments for\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatPostOrComment[]} list of comments\r\n */\r\n static getPostComments = async (postID, token) => {\r\n try {\r\n const res = await fetch(\r\n `https://api.sidechat.lol/v1/posts/comments/?post_id=${postID}`,\r\n {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n }\r\n );\r\n const json = await res.json();\r\n // Function to preprocess the comments and organize them into a nested structure\r\n function preprocessComments(apiComments) {\r\n // Map to store comments by their IDs for efficient lookup\r\n const commentMap = new Map();\r\n // List to store top-level comments\r\n const topLevelComments = [];\r\n\r\n // Iterate through the API comments\r\n apiComments.forEach((comment) => {\r\n // Store the comment in the map with its ID as the key\r\n commentMap.set(comment.id, comment);\r\n // Get the parent comment using the reply_post_id\r\n const parentComment = commentMap.get(comment.reply_post_id);\r\n // Check if the comment is a top-level comment\r\n if (\r\n !parentComment ||\r\n comment.reply_post_id === comment.parent_post_id\r\n ) {\r\n // If it's a top-level comment, push it to the topLevelComments array\r\n topLevelComments.push(comment);\r\n } else {\r\n // If it's a reply, add it to the parent comment's replies array\r\n if (!parentComment.replies) parentComment.replies = [];\r\n parentComment.replies.push(comment);\r\n }\r\n });\r\n\r\n // Flatten the nested structure and return a single list of comments\r\n return flattenComments(topLevelComments);\r\n }\r\n\r\n // Function to flatten nested comments into a single list\r\n function flattenComments(comments) {\r\n // Use reduce to flatten the nested comments array into a single list\r\n return comments.reduce((flatComments, comment) => {\r\n // Push the current comment to the flatComments array\r\n flatComments.push(comment);\r\n // If the current comment has replies, recursively flatten them and push to the flatComments array\r\n if (comment.replies)\r\n flatComments.push(...flattenComments(comment.replies));\r\n // Return the flatComments array\r\n return flatComments;\r\n }, []);\r\n }\r\n\r\n const sortedComments = preprocessComments(json.posts);\r\n return sortedComments;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get comments on post.`);\r\n }\r\n };\r\n\r\n /**\r\n * Gets groups to be displayed on the \"Explore Groups\" page\r\n * @method\r\n * @param {String} token - user bearer token\r\n * @returns {SidechatGroup}\r\n */\r\n static getAvailableGroups = async (token) => {\r\n try {\r\n const res = await fetch(`https://api.sidechat.lol/v1/groups/explore`, {\r\n method: \"GET\",\r\n headers: {\r\n ...defaultHeaders,\r\n Authorization: `Bearer ${token}`,\r\n },\r\n });\r\n const json = await res.json();\r\n return json.groups;\r\n } catch (err) {\r\n console.error(err);\r\n throw new SidechatAPIError(`Failed to get groups from explore.`);\r\n }\r\n };\r\n}\r\n\r\nexport default SidechatAPIClient;\r\n"],"names":["SidechatAPIError","_Error","message","_this","call","name","_wrapNativeSuper","Error","_catch","body","recover","result","e","then","SidechatAPIClient","defaultHeaders","Accept","loginViaSMS","phoneNumber","Promise","resolve","fetch","method","headers","JSON","stringify","phone_number","version","res","json","console","error","reject","verifySMSCode","code","toUpperCase","err","setAge","age","registrationID","Number","registration_id","registerEmail","email","token","_extends","Authorization","checkEmailVerification","verified_email_updates_response","setDeviceID","deviceID","build_type","bundle_id","device_token","AsyncStorage","setItem","getUserAndGroup","groupID","getGroupPosts","category","cursor","setVote","postID","action","post_id","vote_status","getPostComments","preprocessComments","apiComments","commentMap","Map","topLevelComments","forEach","comment","set","id","parentComment","get","reply_post_id","parent_post_id","replies","push","flattenComments","comments","reduce","flatComments","apply","posts","getAvailableGroups","groups"],"mappings":"4zCAAM,IAAAA,wBAAgBC,WACpB,SAAAD,EAAYE,GAASC,IAAAA,EAEY,OAD/BA,EAAAF,EAAAG,UAAMF,UACDG,KAAO,mBAAmBF,CACjC,CAAC,SAJmBF,KAAAD,yEAInBA,CAAA,eAAAM,EAJ4BC,QCkjBxB,SAASC,EAAOC,EAAMC,GAC5B,IACC,IAAIC,EAASF,GACd,CAAE,MAAMG,GACP,OAAOF,EAAQE,EAChB,CACA,OAAID,GAAUA,EAAOE,KACbF,EAAOE,UAAK,EAAQH,GAErBC,CACR,CAnjBM,IAAAG,EAAiB,aAAjBA,EACGC,eAAiB,CACtBC,OAAQ,mBACR,eAAgB,oBAHdF,EAWGG,YAAW,SAAUC,GAAW,WAAK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WAASnD,GAEP,MADAN,QAAQC,MAAMK,GACJ,IAAApC,EAAgB,kCAC5B,GACF,CAAC,MAAAY,UAAAO,QAAAa,OAAApB,EA/UGE,CAAAA,EAAAA,EAuVG0E,mBAAkB,SAAU5C,GAAU,IAAA,OAAAzB,QAAAC,QAAAZ,aACvCW,OAAAA,QAAAC,QACgBC,MAAK,6CAA+C,CACpEC,OAAQ,MACRC,QAAOsB,EAAA,CAAA,EACF9B,eAAc,CACjB+B,cAAyBF,UAAAA,OAE3B/B,KAAA,SANIe,GAAG,OAAAT,QAAAC,QAOUQ,EAAIC,QAAMhB,cAAvBgB,GACN,OAAOA,EAAK4D,MAAO,EAAA,EACrB,EAAC,SAAQrD,GAEP,MADAN,QAAQC,MAAMK,OACJpC,uCACZ,GACF,CAAC,MAAAY,GAAAO,OAAAA,QAAAa,OAAApB,EAGH,CAAA"}
@@ -1,2 +1,2 @@
1
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e||self).sidechatJs={})}(this,function(e){function r(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(r=function(){return!!e})()}function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},t.apply(this,arguments)}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function n(e,r){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},n(e,r)}function i(e){var t="function"==typeof Map?new Map:void 0;return i=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(r){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return function(e,t,o){if(r())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,t);var s=new(e.bind.apply(e,i));return o&&n(s,o.prototype),s}(e,arguments,o(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),n(i,e)},i(e)}var s=/*#__PURE__*/function(e){var r,t;function o(r){var t;return(t=e.call(this,r)||this).name="SidechatAPIError",t}return t=e,(r=o).prototype=Object.create(t.prototype),r.prototype.constructor=r,n(r,t),o}(/*#__PURE__*/i(Error));function u(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}var c={Accept:"application/json","Content-Type":"application/json"};e.checkEmailVerification=function(e){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/users/check_email_verified",{method:"GET",headers:t({},c,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.verified_email_updates_response)return e.verified_email_updates_response;throw new s((null==e?void 0:e.message)||"Email is not verified.")})})},function(){throw console.error(error),new s("Email is not verified.")}))}catch(e){return Promise.reject(e)}},e.getAvailableGroups=function(e){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/groups/explore",{method:"GET",headers:t({},c,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.groups})})},function(e){throw console.error(e),new s("Failed to get groups from explore.")}))}catch(e){return Promise.reject(e)}},e.getGroupPosts=function(e,r,o,n){void 0===o&&(o="hot");try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts?group_id="+e+"&type="+o+(n?"&cursor="+n:""),{method:"GET",headers:t({},c,{Authorization:"Bearer "+r})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},e.getPostComments=function(e,r){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/comments/?post_id="+e,{method:"GET",headers:t({},c,{Authorization:"Bearer "+r})})).then(function(e){function r(e){var r=new Map,o=[];return e.forEach(function(e){r.set(e.id,e);var t=r.get(e.reply_post_id);t&&e.reply_post_id!==e.parent_post_id?(t.replies||(t.replies=[]),t.replies.push(e)):o.push(e)}),t(o)}function t(e){return e.reduce(function(e,r){return e.push(r),r.replies&&e.push.apply(e,t(r.replies)),e},[])}return Promise.resolve(e.json()).then(function(e){return r(e.posts)})})},function(e){throw console.error(e),new s("Failed to get comments on post.")}))}catch(e){return Promise.reject(e)}},e.getUserAndGroup=function(e,r){void 0===r&&(r="");try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/updates?group_id="+r,{method:"GET",headers:t({},c,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},e.loginViaSMS=function(e){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/login_register",{method:"POST",headers:c,body:JSON.stringify({phone_number:"+1"+e,version:3})})).then(function(e){return Promise.resolve(e.json())})},function(){throw console.error(error),new s("Failed to request SMS verification.")}))}catch(e){return Promise.reject(e)}},e.registerEmail=function(e,r){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v2/users/register_email",{method:"POST",headers:t({},c,{Authorization:"Bearer "+r}),body:JSON.stringify({email:e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.message)throw new s(e.message);return e})})},function(){throw console.error(error),new s("Failed to request email verification.")}))}catch(e){return Promise.reject(e)}},e.setAge=function(e,r){try{if(e<13)throw new s("You're too young to use Offsides.");return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/complete_registration",{method:"POST",headers:c,body:JSON.stringify({age:Number(e),registration_id:r})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},e.setDeviceID=function(e,r){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/register_device_token",{method:"POST",headers:t({},c,{Authorization:"Bearer "+r}),body:JSON.stringify({build_type:"release",bundle_id:"com.flowerave.sidechat",device_token:e})})).then(function(r){return Promise.resolve(r.json()).then(function(r){return Promise.resolve(AsyncStorage.setItem("deviceID",e)).then(function(){return r})})})},function(e){throw console.error(e),new s("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},e.setVote=function(e,r,o){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/set_vote",{method:"POST",headers:t({},c,{Authorization:"Bearer "+r}),body:JSON.stringify({post_id:e,vote_status:o})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed to change the vote on post.")}))}catch(e){return Promise.reject(e)}},e.verifySMSCode=function(e,r){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/verify_phone_number",{method:"POST",headers:c,body:JSON.stringify({phone_number:"+1"+e,code:r.toUpperCase()})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed verify this code.")}))}catch(e){return Promise.reject(e)}}});
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e||self).sidechatJs={})}(this,function(e){function r(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(r=function(){return!!e})()}function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},t.apply(this,arguments)}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function n(e,r){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},n(e,r)}function i(e){var t="function"==typeof Map?new Map:void 0;return i=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(r){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return function(e,t,o){if(r())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,t);var s=new(e.bind.apply(e,i));return o&&n(s,o.prototype),s}(e,arguments,o(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),n(i,e)},i(e)}var s=/*#__PURE__*/function(e){var r,t;function o(r){var t;return(t=e.call(this,r)||this).name="SidechatAPIError",t}return t=e,(r=o).prototype=Object.create(t.prototype),r.prototype.constructor=r,n(r,t),o}(/*#__PURE__*/i(Error));function u(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}var c=function(){};c.defaultHeaders={Accept:"application/json","Content-Type":"application/json"},c.loginViaSMS=function(e){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/login_register",{method:"POST",headers:defaultHeaders,body:JSON.stringify({phone_number:"+1"+e,version:3})})).then(function(e){return Promise.resolve(e.json())})},function(){throw console.error(error),new s("Failed to request SMS verification.")}))}catch(e){return Promise.reject(e)}},c.verifySMSCode=function(e,r){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/verify_phone_number",{method:"POST",headers:defaultHeaders,body:JSON.stringify({phone_number:"+1"+e,code:r.toUpperCase()})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},c.setAge=function(e,r){try{if(e<13)throw new s("You're too young to use Offsides.");return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/complete_registration",{method:"POST",headers:defaultHeaders,body:JSON.stringify({age:Number(e),registration_id:r})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},c.registerEmail=function(e,r){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v2/users/register_email",{method:"POST",headers:t({},defaultHeaders,{Authorization:"Bearer "+r}),body:JSON.stringify({email:e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.message)throw new s(e.message);return e})})},function(){throw console.error(error),new s("Failed to request email verification.")}))}catch(e){return Promise.reject(e)}},c.checkEmailVerification=function(e){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/users/check_email_verified",{method:"GET",headers:t({},defaultHeaders,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){if(e.verified_email_updates_response)return e.verified_email_updates_response;throw new s((null==e?void 0:e.message)||"Email is not verified.")})})},function(){throw console.error(error),new s("Email is not verified.")}))}catch(e){return Promise.reject(e)}},c.setDeviceID=function(e,r){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/register_device_token",{method:"POST",headers:t({},defaultHeaders,{Authorization:"Bearer "+r}),body:JSON.stringify({build_type:"release",bundle_id:"com.flowerave.sidechat",device_token:e})})).then(function(r){return Promise.resolve(r.json()).then(function(r){return Promise.resolve(AsyncStorage.setItem("deviceID",e)).then(function(){return r})})})},function(e){throw console.error(e),new s("Failed verify this code.")}))}catch(e){return Promise.reject(e)}},c.getUserAndGroup=function(e,r){void 0===r&&(r="");try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/updates?group_id="+r,{method:"GET",headers:t({},defaultHeaders,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},c.getGroupPosts=function(e,r,o,n){void 0===o&&(o="hot");try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts?group_id="+e+"&type="+o+(n?"&cursor="+n:""),{method:"GET",headers:t({},defaultHeaders,{Authorization:"Bearer "+r})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed to get posts from group.")}))}catch(e){return Promise.reject(e)}},c.setVote=function(e,r,o){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/set_vote",{method:"POST",headers:t({},defaultHeaders,{Authorization:"Bearer "+r}),body:JSON.stringify({post_id:e,vote_status:o})})).then(function(e){return Promise.resolve(e.json())})},function(e){throw console.error(e),new s("Failed to change the vote on post.")}))}catch(e){return Promise.reject(e)}},c.getPostComments=function(e,r){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/posts/comments/?post_id="+e,{method:"GET",headers:t({},defaultHeaders,{Authorization:"Bearer "+r})})).then(function(e){function r(e){var r=new Map,o=[];return e.forEach(function(e){r.set(e.id,e);var t=r.get(e.reply_post_id);t&&e.reply_post_id!==e.parent_post_id?(t.replies||(t.replies=[]),t.replies.push(e)):o.push(e)}),t(o)}function t(e){return e.reduce(function(e,r){return e.push(r),r.replies&&e.push.apply(e,t(r.replies)),e},[])}return Promise.resolve(e.json()).then(function(e){return r(e.posts)})})},function(e){throw console.error(e),new s("Failed to get comments on post.")}))}catch(e){return Promise.reject(e)}},c.getAvailableGroups=function(e){try{return Promise.resolve(u(function(){return Promise.resolve(fetch("https://api.sidechat.lol/v1/groups/explore",{method:"GET",headers:t({},defaultHeaders,{Authorization:"Bearer "+e})})).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.groups})})},function(e){throw console.error(e),new s("Failed to get groups from explore.")}))}catch(e){return Promise.reject(e)}},e.SidechatAPIClient=c,e.SidechatAPIError=s});
2
2
  //# sourceMappingURL=sidechat.umd.js.map