Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

🚧 snoowrap v2.0 (work in progress) #338

Merged
merged 35 commits into from
Nov 2, 2022
Merged

Conversation

iMrDJAi
Copy link

@iMrDJAi iMrDJAi commented Aug 2, 2021

This pull request will mainly address the following changes:

Since most of them are considered as breaking changes, they should be released as the next major version of snoowrap "v2.0". (#300)

Other changes supposed to be made before v2.0:

What I've done so far:

  • I've fully replaced request by axios, added support of some old request properties for a maximum backward compatibility.
  • I've fully removed bluebird promises from request_handler.js and used async/await instead.
  • Other minor changes I've mentioned in the commits messages.

What's missing?

  • Updating snoowrap.js and objects/* to match the new axios API and to replace bluebird promises. (still working on it)
  • Completing the task list at the top. ⬆⬆

I need help, I can't handle all of these alone. cc @SpyTec.

I'm a windows user '-'
- ➕ Added axios, form-data.
- ➕ Added live-server to simplify running tests on browser.
- 🔨 Updated request_handler.js:
  - 🔥 Removed bluebird Promises to use async/await instead.
  - 💥 Replaced request with axios.
  - 👽️ Updated requests options to match the axios API.
- 🚚 Renamed xhr.js to axios.js.
- 🔨 Updated axios.js:
  - 🎨 Added request interceptor to modify requests options.
  - 👽️ Added support to some old request options for a maximum backward compatibility.
- 🚨 Removed ESLint promise/no-native rule. (some rules are overkill, consider removing some of them to use a newer JavaScript syntax).
- 📝 Updated docs.
- 🔨 Updated axios.js:
  - 🎨 Improved requests options validation.
  - ✨Added a way to debug requests/responses internally.
- 🔨 Updated request_handler.js:
  - 🐛Fixed a bug with errors handling  in `snoowrap#oauthRequest`.
- ✨Added `npm run browser` to simplify testing and debugging on browser console.
🚨 Removed `"use strict";` on `browser/index.js` since it causes linter issues.
🩹 Added an additional check for the debug function since it may not always be available on `_r`.
- 🔨 Updated `snoowrap#getAuthUrl`:
  - ✨The default scope now is set to `['*']` which gives you all permissions.
  - ✨Added support for the `compact` mode which represents the mobile version of the authorization URL.
- 🐛 Fixed a bug with `snoowrap#fromAuthCode` and `snoowrap#fromApplicationOnlyAuth` when they don't set the values of `requester.tokenExpiration` and `requester.scope` after a successful authentication which causes the access token to refresh again for no reason '-' .
- 🐛 Fixed the broken `snoowrap#markAsVisited` method  (I havn't test it yet bcs I don't have reddit premium).
- 🐛 Fixed a bug with `snoowrap#getRandomSubmission` when the reddit server returns the subreddit itself instead of a random submission.
- 🩹 Now the `scope` value is getting removed from the requester object when calling `snoowrap#revokeAccessToken` or `snoowrap#revokeRefreshToken`.
- 👽️ Updated all methods to match the new `axios` API.
- ➖ Removed `promiseWrap` and `proxies`.
- 🎨 More clean code.
- 💡 More clean comments.
- 📝 Updated docs.
@iMrDJAi
Copy link
Author

iMrDJAi commented Aug 9, 2021

Finally! a new commit! 🎉

Most of the work is done, the axios migration is done, bluebird promises, promise-chains's promiseWrap functions, and proxies has been completely removed, some bugs are fixed and much more. See the full changes log in the latest commit message.

It still has some pending work btw, docs/readme update, more features and bug fixes, more testing, final touches...

Attention needed:

  • _newObject ignores most of the snoowrap#createModmailDiscussion response, no practical way to parse the returned content yet.
  • Missing method in snoowrap.js at line 1185 That wasn't a method.
  • snoowrap#composeMessage returns an empty object {} which is uncommon?
  • Some methods (Comment#lock, Submission#hide...) claim to return the updated version of the content (submission, comment...) even though they don't.
  • url.parse used in Listing.js at line 3 is deprecated Replaced with the native URL class. Listing#_setUri() requires absolute URLs now.
  • PrivateMessage.js: TODO: Get rid of the repeated code here, most of these methods are exactly the same with the exception of the URIs.
  • Still unsure about VoteableContent#_mutateAndExpandReplies, someone should double check it.
  • Many unnecessary lodash functions (_.map(), _.forEach()...) that have native equivalents are used. @SpyTec Is that what you meant by "Remove underscore function calls maps"?

@iMrDJAi
Copy link
Author

iMrDJAi commented Aug 10, 2021

Here are other things came up to my head last night:

  • Unit tests have to be rewritten, they fail with latest snoowrap version, it's even worse with the upcoming 2.0 version since it contains lot of breaking changes.
  • The .sh scripts aren't compatible with Windows. Well, they worked with me since I have Ubuntu sub-system, but it shouldn't be hard to write Windows compatible versions.
  • The curly ESLint rule is overkill, probably we should allow inline if statements at the least, the code would be much cleaner with that.
  • Dependencies should be updated, some of them have security vulnerabilities. Also, I'm wondering why snoowrap depends on a specific commit of uglify-js instead of using a published version on the npm registry. What's so special about it?

The code is pending review and testing, @not-an-aardvark @SpyTec you should take a look. Also more discussion is needed, things must be clarified.

- ✨Added image/video/videogif submissions support! `snoowrap#submitImage`, `snoowrap#submitVideo` and `snoowrap#_uploadMedia`. (Thx PRAW 😂)
- 🐛 Fixed an issue with `FormData` on `axios.js` when running snoowrap on node.
- 📝 Updated docs.
@iMrDJAi
Copy link
Author

iMrDJAi commented Aug 12, 2021

The first image ever to be uploaded on reddit using snoowrap
The first video ever to be uploaded on reddit using snoowrap

I'm making history! 🤩

@tnm0113
Copy link

tnm0113 commented Aug 15, 2021

when v2.0 will be released ? so excited for this, and very good work iMrDJAi

Copy link
Owner

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for all your work on this! I haven't finished going through all the changes closely yet, but from skimming it briefly I left a couple comments. I still have some more reviewing to do.

Re:

Many unnecessary lodash functions (_.map(), _.forEach()...) that have native equivalents are used. @SpyTec Is that what you meant by "Remove underscore function calls maps"?

I'm guessing that was referring to this, which is a very old backwards-compatibility measure that creates snake_case aliases like get_subreddit for all methods like getSubreddit.

browser/index.js Outdated Show resolved Hide resolved
src/README.md Show resolved Hide resolved
@iMrDJAi
Copy link
Author

iMrDJAi commented Aug 17, 2021

I'm guessing that was referring to this, which is a very old backwards-compatibility measure that creates snake_case aliases like get_subreddit for all methods like getSubreddit.

@not-an-aardvark I got that! snake_case names should be definitely removed. This requires some extra work since some methods still support snake_case params.

Update: snake_case aliases are removed. However, I decided to follow a new polity:

  • All raw API params will be passed as is, regardless of whether they are snake_case or not. As a result, I removed camelCase aliases. This will clear confusion and keep things unified.
  • All other custom properties/methods/params will remain in camelCase form.

@iMrDJAi
Copy link
Author

iMrDJAi commented Aug 17, 2021

when v2.0 will be released ? so excited for this, and very good work iMrDJAi

@tnm0113 Still working on it, stay tuned!

- ✨ Added `snoowrap#submitGallery`.
- ✨ Added `snoowrap#submitPoll`.
- ✨ Added inline media support for `snoowrap#submitSelfpost`.
- ✨ Added `snoowrap#_convertToFancypants`. Used to convert `markdown` to `rtjson` format for the `fancy pants` editor. Necessary to embed inline media in selfposts.
- 🔨 Improved validation for `snoowrap#submitVideo` .
- ✨ Created `MediaFile.ts`. It contains classes that represent uploaded media can be used inline or with other `snoowrap#submitXXXX` functions.
- 🔨 Updated `snoowrap#_uploadMedia` to return instances of `MediaFile`.
- 🚧 Missing docs..
@iMrDJAi
Copy link
Author

iMrDJAi commented Aug 18, 2021

The first poll ever to be submitted on reddit using snoowrap! 🎉
The first gallery ever to be submitted on reddit using snoowrap! 🎉
The first self post with inline media ever to be submitted on reddit using snoowrap! 🎉

I have to write docs for the new methods. 🚧🚧

- 📝 Updated docs.
- 🚧 Missing docs for `src/objects/MediaFile.ts`.
@iMrDJAi
Copy link
Author

iMrDJAi commented Aug 26, 2021

After several attempts couldn't figure out how to include src/objects/MediaFile.ts in the documentation. I'll skip this for now. JSDoc is broken with TypeScript, it needs to be replaced by TypeDoc. Or maybe we should use the Discord's docs website? In this case, I registered the organization https://github.com/snoowrap to host the docs repositories there.

@iMrDJAi
Copy link
Author

iMrDJAi commented Sep 26, 2021

First, I apologize for being late. I been busy working on some side projects last month.
Anyway, this commit addresses these issues:

Missing docs for the new updates. Work in progress...

- 📝 Updated docs.
- 🐛 Bug fixes and logic improvements.
🔨 Added shortcuts of the new `submit` methods to the subreddit object
@pgamerx
Copy link

pgamerx commented Dec 20, 2021

Any updates?

@jamesrswift
Copy link

Typescript declaration for comments is incorrect (e.g. Snoowrap.Comment lacks a lock() method)

@iMrDJAi
Copy link
Author

iMrDJAi commented Jan 7, 2022

Yeah, while my changes are working, a lot of things are still missing/incomplete: the typescript migration, fixing docs, removing snake_case names, an allowlist for axios options, dealing with unit tests, and much more...
@not-an-aardvark You should probably merge this to a development branch so more people can help and contribute. However, I'll see what I can do about that mess.

@jamesrswift
Copy link

If there's anything I can do to help, I'd like to :) get in touch if I can!

@SuperchupuDev
Copy link

SuperchupuDev commented May 7, 2022

Absolutely agree with the above comment, await ships in a greater version of Android Webview (55) than fetch (42) and it's already in v2.0, in fact every major browser shipped fetch earlier than await, I don't really think using native fetch() would drop compatibility outside of Node
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#browser_compatibility

image

@iMrDJAi
Copy link
Author

iMrDJAi commented May 7, 2022

is it upgradable at least?

@SuperchupuDev It's not if com.android.webview, however com.google.android.webview is upgradable. BTW, currently I'm using an Android 5.1 device, it's shame that the manufacturers aren't producing small-sized smartphones anymore. :")

@luc122c @SuperchupuDev I'm not against using new features. In fact that won't usally affact older environments since the code gets transpiled at the end (e.g. async/await to native promises).
The features that should be avoided are the ones that may not work on the lagecy environments even after transpiling the code (e.g. the new regex syntax). Or those that may cause a bundle size increasment (e.g. polyfills).
Axios on browser is based on the XMLHttpRequest API which is widly suppored, also it has a powerful API and it's way easier to build wrappers than Fetch, this is why I decided to stick to it.
Also, dropping node <8 versions is a stupid idea, not everyone is going to upgrade. Regardless of the fact that the available binaries of node for the mobile platforms (nodejs-mobile) are still in v12.

@iMrDJAi
Copy link
Author

iMrDJAi commented May 7, 2022

I'm busy with work latly. Are there any TypeScript developers who are intersted to help finishing the megration? The more the better! (cc @JamesxX).

@not-an-aardvark @SpyTec and the other contributors, I think it's the time for you to act, we need to speed it up, I need help.

@iMrDJAi
Copy link
Author

iMrDJAi commented Jun 2, 2022

Closing due to the inactivity of maintainers. Feel free to reach me out if you're interested to open it again.

@iMrDJAi iMrDJAi closed this Jun 2, 2022
@Venefilyn
Copy link
Collaborator

Hobby coding has been on the back burner over the past year on my end due to both professional and personal reasons. There's two big drawbacks to snoowrap that causes such slow development, both maintainers are relatively inactive to the project, and lack of community engagement.

I can't at this time make any commitments in the near future, neither to this project or any of the others I'm a maintainer of. I hope we can find some people willing to continue the work

What I think would be best is to merge to a new branch for v2 development, document what has been done and what is missing in the tracking issue, and split the tasks into smaller things. Once it is believed there is a working prototype I can at least release pre-release versions of v2 in npm.

Outstanding for this PR would be to have it reviewed. But, I can't commit to doing it myself in the coming weeks

@iMrDJAi
Copy link
Author

iMrDJAi commented Jun 25, 2022

Hobby coding has been on the back burner over the past year on my end due to both professional and personal reasons.

Unfortunately, this is the case for me too. I found myself unable to continue working on it without help, I was slow and I couldn't achieve progress in a reasonable amount of time.

document what has been done and what is missing in the tracking issue, and split the tasks into smaller things

I'll take a look on my work again and document everything, then I'll open a new pull request instead to keep it clean.

@amosbastian
Copy link

Hey, is there any way I can help with this?

@DedaDev
Copy link

DedaDev commented Oct 28, 2022

I'll take a look on my work again and document everything, then I'll open a new pull request instead to keep it clean.

@iMrDJAi how its going with this?

What I think would be best is to merge to a new branch for v2 development, document what has been done and what is missing in the tracking issue, and split the tasks into smaller things. Once it is believed there is a working prototype I can at least release pre-release versions of v2 in npm.

@SpyTec please do it, make v2 branch, @iMrDJAi should re-direct this PR to that branch, and let the others contribute, so we can move on with this.

@iMrDJAi
Copy link
Author

iMrDJAi commented Oct 28, 2022

@DedaDev To be honest I didn't have enough time to get back to this project in the last few months, unfortunately I made 0 progress since then. I still have interest but.. not time.

@SpyTec please do it, make v2 branch, @iMrDJAi should re-direct this PR to that branch, and let the others contribute, so we can move on with this.

I can't agree more, I think merging this to a v2 branch would speed it up, this will allow more developers to contribute.

@iMrDJAi iMrDJAi reopened this Oct 28, 2022
@Venefilyn Venefilyn changed the base branch from master to v2.0 October 28, 2022 14:43
@Venefilyn
Copy link
Collaborator

v2.0 created and PR changed to point to it. If people want to take a look at this PR and give their review feel free, then I can merge sometime next week - just to give everyone more time to note down what's missing overall

@SuperchupuDev
Copy link

SuperchupuDev commented Oct 28, 2022

Now that Node v18 is LTS I think this would be a good time to switch to the built-in fetch API, Node v14 is reaching EOL soon and v12 already did a while ago (iirc the Fetch API also got backported to v16), why supporting old versions that aren't officially supported anymore? If someone really needs support for legacy environments they can just keep using v1 🤷‍♀️

@iMrDJAi
Copy link
Author

iMrDJAi commented Oct 28, 2022

@SuperchupuDev I dislike these EOL policies tbh, in reality they just don't work, following them blindly would bring nothing but unnecessary limitations. You only drop support for legacy environments if your project cannot be kept functional on these environments anymore. Learn how to make your code platform independent.

@iMrDJAi
Copy link
Author

iMrDJAi commented Oct 28, 2022

v2.0 created and PR changed to point to it. If people want to take a look at this PR and give their review feel free, then I can merge sometime next week - just to give everyone more time to note down what's missing overall

Here is a hint: most likely there are remaining files that need to be ported to TypeScript, also there are still some lodash function calls that need to get replaced by native solutions.

@@ -19,18 +19,18 @@ rules:
indent: [error, 2, {FunctionDeclaration: {body: 1, parameters: 1}, FunctionExpression: {body: 1, parameters: 1}, CallExpression: {arguments: 1}, SwitchCase: 1, MemberExpression: 1}]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
indent: [error, 2, {FunctionDeclaration: {body: 1, parameters: 1}, FunctionExpression: {body: 1, parameters: 1}, CallExpression: {arguments: 1}, SwitchCase: 1, MemberExpression: 1}]
"@typescript-eslint/indent": [error, 2, {FunctionDeclaration: {body: 1, parameters: 1}, FunctionExpression: {body: 1, parameters: 1}, CallExpression: {arguments: 1}, SwitchCase: 1, MemberExpression: 1}]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DedaDev I believe we should disable all formatting rules and install prettier instead.

* instantiate it directly.
* <style> #RedditContent {display: none} </style>
*/
class RedditContent<T extends RedditContent = RedditContent<any>> {
Copy link

@DedaDev DedaDev Oct 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure what you are doing here, making generics for the class in which T extends the Class itself?
and you are not even using that T in the body

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It helps constrain the generic when extending other classes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DedaDev We pass sub classes as generic types to RedditContent<> to ensure that methods like fetch() and refresh() return the correct typing. RedditContent<any> is the default in case you do new RedditContent().

export {default as requiredArg} from './requiredArg'
export {default as URL} from './URL'
export {default as URLSearchParams} from './URLSearchParams'
export {default as WebSocket} from './WebSocket'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe named export would suit better here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DedaDev Idk.. Yeah, this file isn't necessary.

semi: [error, always]
semi-spacing: error
# semi: [error, never]
# semi-spacing: error
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why commented?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DedaDev To temporarily suspense linter error till I remove all semicolons.

username: string
password: string
two_factor_code?: number | string
access_token?: string
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move types to separate files?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DedaDev Well, there are too many files in the project already, not sure if creating more is a good idea.

@DedaDev
Copy link

DedaDev commented Oct 29, 2022

There is the way too many things to be fixed, I think you took a huge bite @iMrDJAi
Subreddit.ts is 1560 lines long, I don't want to even look at it.

Let's start small,
I would suggest fixing the current code first, so fixing all tests, and updating the API-s.
Then replacing the request-promise with Axios.
Then we can think of typescript and all the fancy stuff.
Add me on discord to coordinate around this, Deda#6991

@Venefilyn Venefilyn merged commit ddc933c into not-an-aardvark:v2.0 Nov 2, 2022
@Venefilyn
Copy link
Collaborator

Lots of things to do still, we know that. I merged the branch, anything else can be brought up in #300 or subsequent PRs.

While this PR took a long time, since we have a lot of participants interested please take a look at Issue #370 about the future of snoowrap. The project has no velocity and something needs to change

@DedaDev
Copy link

DedaDev commented Nov 2, 2022

Nooo, revert the merge please @SpyTec . That PR has 200+ errors, tests are broken, no one would be able to continue that work,
we need smaller tasks. I like @iMrDJA enthusiasm, he wanted to fix everything, but as I said, he took a huge bite that he cannot swallow, that usually leads to unfinished job. We need smaller cycles like with scrum (Agile).

And lets make a rule that only PRs that are passing all tests can be merged. (husky would be a good implementation)

@Venefilyn
Copy link
Collaborator

Nooo, revert the merge please @SpyTec . That PR has 200+ errors, tests are broken, no one would be able to continue that work,
we need smaller tasks. I like @iMrDJA enthusiasm, he wanted to fix everything, but as I said, he took a huge bite that he cannot swallow, that usually leads to unfinished job. We need smaller cycles like with scrum (Agile).

Several times the PR has been asking for contributions from other people. When I set out the v2.0 tracking issue I didn't expect one giant PR either, but if someone already did a lot of code I will let them continue. With hobby projects with little activity you have to take some liberties in how things are handled

And lets make a rule that only PRs that are passing all tests can be merged. (husky would be a good implementation)

We do not put broken code to main branch, all tests have to pass already. This was merged into a separate branch to make collaboration easier

@SuperchupuDev
Copy link

just wondering, what is the minimum node version planned to be supported in 2.0? looks like the ci is failing because it's using node 8.15 which breaks since esbuild uses } catch { which was added in node 10. i would suggest supporting v12+ but i'm not the one to decide that

@DedaDev
Copy link

DedaDev commented Nov 2, 2022

@SpyTec he said that he doesn't have time to work on it, #338 (comment)
and everyone is going to be super lost when they open up the code as I was.

@FoxxMD
Copy link

FoxxMD commented Nov 2, 2022

@DedaDev I think you're missing the point...this PR and the branch 2.0 consist solely of DJA's commits, based off the latest master branch. There is no other "2.0" that was merged into DJA's PR. It's just their work.

You can work from that if you want. Or you can start from the master branch. Or you can branch off some earlier commit in the 2.0 branch. If you want to PR another "next" branch based off of only a few commits and go step by step you can do that too.

The point is this work is now available in this repo for others to discuss and PR off of, instead of having to restrict everything to this one PR discussion or having to move the discussion to DJA's fork.

@iMrDJAi
Copy link
Author

iMrDJAi commented Nov 2, 2022

@DedaDev to be clear, Subreddit.js and other files from v1 were already big, also the code base was legacy and much complex than the one on this PR (replacing bluebird promises helped), so at least now we have modern code to fix. I stated before that the tests are totally broken with v2 and they need to be written from scratch so don't worry about the results.

I don't disagree with what you said, the PR was too huge the way I lost track of what I was doing, also I wasn't able to find enough time to continue, that's on me. I don't promise anything but I'll give it a shot again. I may reach you out on Discord this weekend.

Merging this doesn't mean anything but allowing more developers to contribute, it will never be released if it remains in this state.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.