* feat: made some progress on a function which can be overridden to allow users to inject custom headers into a rest request
* made the changes suggested in PR. Renamed inject headers to createBaseHeaders, which adds the user agent into the headers.
* add OAuth2 routes
* Add oauth2 methods to rest
* Add rest manager methods, Add token params
* Add authorization headers
* Add auth to editUserApplicationRoleConnection
* fix logging header always displaying bot as auth
* Add OAuth2Scope enum
* Start testing ratelimit handling
* Fix now scopes are separated by a space
* move webhook object to DiscordAccessTokenResponse
* convert payload to snake_case
* fix some typings
* more types fixes
* add support for upserting commands with tokens
* handle correctly ratelimit and concurrently
* add guild to DiscordAccessTokenResponse
* Add oauth2 create link function
* Fix removeTokenPrefix to support Bearer tokens
* update jsdoc comment for removeTokenPrefix
* fix removeTokenPrefix unit tests
* fix see link on getMember and getCurrentMember
* add bot helpers and fix some types
* Use objects to pass the bearer tokens
* fix Deno issue with Buffer.from
* Merge 'upstream/main' into feat/oauth2 to fix merge conflict
* Fix debug queue logging
* keep only 1 route for current user
* add Bearer prefixed url to the rest of the logs
---------
Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
* refactor(rest)!: refactor `sendRequest`
- Removed `url` in favour of `route`. This change will effectively remove a bunch of unnecessary checks from dd. Also this changes how rest proxies have to pass the route to the `makeRequest` function. But since it will just require you to pass `req.route + req.query` it is an improvement compared to `rest.baseUrl + req.route + req.query`.
- Introduced `HttpResponseCodes` an internal enum to remove magic numbers.
- Improved the rate limted response handling. Made it simpler.
- Removed unnecessary `JSON.stringify(await result.json())` since `await result.text()` does effectively the same.
- Changed the anti memor leak `response.json()` to `response.arrayBuffer()` since latter does not do any additional processing.
* .
* forgot to fix that
Currently the route definitions make `createRestManager` massive. Moving them to their own creator function makes it a bit easier to handle.
Also `sessionInfo` has been removed since it's just an alias to `gatewayBot`. Instead `gatewayBot` should be used.
It has been removed since the routes are mainly used internally in the lib. Almost no one should need to touch them outside, but if they do they should know how routes are called.
* refactor(rest): remove falsy token check
This is in favour for interaction only bots, which still need rest but cannot provide a valid bot token.
If you want to use rest for your normal bot it should be your own responsibility to pass a valid token.
Further more `applicationId` is now a required property since we cannot extract the id from the token anymore.
* forgot to commit that
* fix error
* make appid optional again
* app id throw error if undefined
* fix test
Currently we use a double negation in the code which makes it harder to understand what it actually does.
Therefore the check has been changed to be understood easier.
* refactor(rest): interaction handling
Currently some interaction handling uses `sendRequest` directly.
This adds the `runThroughQueue` option, which prevents the request to be handled by a queue effectively giving the same effect as using `sendRequest` directly.
This prevents code repetition and supports future endpoints which might not have a rate limit too.
Further more all interaction related endpoints have now been set to not send the bots authorization header.
* fix invalid file
* fix eslint
* fix: followups have a rate limit
* fix awaiting
* refactor!(rest): rest proxy attachment sending
Currently attachments get encoded as base64 before being send to the proxy. This is not really necessary, instead we can just send `FormData` to the proxy.
* fix lint
* fix(rest, types)!: support auditlog reason
Improved the consistency by separating the audit log reason to an optional function parameter.
Also added support for 100% documented reason endpoints.
* missing stuff
* fix this
* fix e3e
* fix(bot,rest,types)!: attachment sending
* apply code suggestions
* forgot to add that
* this should not be there i guess
* maybe spell it right
* actually revert the attachments rename
* Change how method gets passed
* more stuff
* improve function name
* refactor(rest): simplify `manager.simplifyUrl`
The changes improve readability and performance by a small margin.
* refactor(rest)!: improve `RestManager.createRequest`
- AuditLog Reasons: options.body.reason => options.reason
- options.body can now be FormData
* forgot those
* suggestions
---------
Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>