Commit Graph

52 Commits

Author SHA1 Message Date
Skillz4Killz
59631f2fac format 2023-10-28 13:25:09 +00:00
Fleny
895b482a02 Add option for the header of auth on rest proxy (#3153) 2023-10-18 22:21:22 +00:00
Fleny
f98bb9bf75 fix(rest)!: Update OAuth2 to use the Basic authentication (#3150)
* update exchangeToken and revokeToken to use header

* update helpers file for the new signature
2023-10-15 04:32:04 +00:00
8au
f3a568c4db feat: rest header injection (#3122)
* 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.
2023-09-19 20:14:32 +00:00
Awesome Stickz
f34c0c3bc0 fix: bug with rest manager passing a timestamp instead of milliseconds in setTimeout (#3125) 2023-09-19 17:09:48 +00:00
Fleny
a7d645ec4b feat: Implement OAuth2 endpoints (#3114)
* 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>
2023-09-19 16:23:22 +00:00
Fleny
a087a52d6f Fix(rest) Fix error when serializing payload with a BigInt (#3117)
* Fix error when serializing payload with bigint

* add comment for reason of changeToDiscordFormat
2023-09-08 14:48:47 +00:00
Fleny
1e8edb99c6 bug(rest) Invert unauthorized check (#3104) 2023-08-24 17:21:17 +00:00
Skillz
db8c464081 fix: docs update Closes #3054 2023-08-20 11:16:17 -05:00
Awesome Stickz
0aeadbb275 fix(rest): bug with trying to pass string values in calculateBits() if object is already in Discord format in changeToDiscordFormat() (#3099) 2023-08-05 18:32:10 +00:00
Yaikava
ec5e800bcd 🐛 - fix: snakelize json when files are used (#3062) 2023-07-23 20:59:59 +00:00
NeKz
fe00a6f3e3 fix(rest): add missing files for editMessage (#3087)
* fix(rest): add missing files for editMessage

* fix(rest): extend attachment test with editMessage

* fix(types):  remove null from files type
2023-07-23 20:56:22 +00:00
Skillz4Killz
c9c510b0cd Merge branch 'main' of https://github.com/discordeno/discordeno 2023-06-06 16:28:56 +00:00
Skillz4Killz
73c9788065 feat(rest): easily enable or disable snake case 2023-06-06 16:28:50 +00:00
Skillz
5edfbb7efb fix: localization snake case bug 2023-05-08 13:21:51 -05:00
Skillz4Killz
1d232ac34a fix: interaction.edit type 2023-05-05 23:27:40 +00:00
Skillz4Killz
e54f51a7af fix: hack in helpers again (#3008)
* fix: hack in helpers again

* fix: remaining type errors

* fix: weird linter issue
2023-04-19 12:57:36 -05:00
Skillz4Killz
06f3c93790 fix: handle completed request marking behavior bug 2023-04-17 18:45:57 +00:00
Skillz4Killz
b496f4c1ac fix: being in a loop is not a good sign 2023-04-17 16:09:18 +00:00
Skillz4Killz
250f524885 fix: some improvements to invalid bucket 2023-04-17 16:00:01 +00:00
Yaikava
e9c011eef5 fix(rest): oauth2Application route (#3002) 2023-04-15 14:52:23 +02:00
ITOH
8ee3b59d90 fix(rest): only calculate bits if not undefined (#3000) 2023-04-14 18:52:41 +00:00
Jonathan Ho
dda4d75de1 fix(rest,utils): reverse "refactor: use node-fetch" 6a6a334 (#2995) 2023-04-13 22:05:18 +00:00
ITOH
927ee42ce0 fix(rest): set the correct auth header when using proxy (#2969) 2023-04-04 22:24:20 +00:00
ITOH
8c9c3d53bf refactor(rest)!: make invalid bucket lazy (#2967)
* refactor(rest): make invalid bucket lazy
Instead of using timeouts we should aim to use a lazy bucket system.

* that might be better

* fix tests
2023-04-04 03:34:34 +00:00
ITOH
e3549a8675 fix(rest): does not need to set the absolute url (#2966) 2023-04-03 20:00:30 +00:00
ITOH
895db84d34 refactor(rest): add header constants (#2962)
* refactor(rest): add header constants

* spelling error

* export
2023-04-03 19:01:14 +00:00
ITOH
7f9459b435 feat(rest): add isProxied (#2957)
Adds the `isProxied` property to rest.
This effectively removes the `startWith('https://discord.com/api')` check.
2023-04-03 15:51:47 +00:00
ITOH
50282f9190 refactor(rest)!: improve sendRequest (#2956)
* 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
2023-04-03 15:23:01 +00:00
ITOH
fd357aeace refactor(rest)!: move routes to their own creator function (#2950)
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.
2023-04-02 21:04:33 +00:00
ITOH
7c031df875 refactor(rest)!: remove falsy token check (#2949)
* 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
2023-04-02 21:39:08 +02:00
ITOH
5e1e56146e fix: eslint no async error (#2947)
* fix: eslint no async error

* just ignore
2023-04-02 19:47:29 +02:00
ITOH
7c51f731cb refactor(rest): improve unauthorized readability (#2946)
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.
2023-04-02 16:54:36 +00:00
ITOH
7b5d99e5dd refactor(rest): interaction handling (#2944)
* 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
2023-04-02 16:27:48 +00:00
ITOH
1cb1b09460 refactor!(rest): rest proxy attachment sending (#2924)
* 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
2023-04-02 15:43:08 +00:00
ITOH
17a52fec1b fix(rest, types)!: support auditlog reason (#2940)
* 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
2023-04-02 15:38:06 +00:00
ITOH
6359972e38 docs(rest): webhook names cannot contain 'discord' (#2936)
Closes: https://github.com/discordeno/discordeno/issues/2928
2023-04-01 19:18:59 +00:00
ITOH
05fc3fbeba style: format (#2925) 2023-04-01 02:46:46 +02:00
ITOH
f5abd83cc5 fix(bot,rest,types)!: attachment sending (#2917)
* 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
2023-03-31 20:50:53 +00:00
ITOH
d757773e95 perf(rest): remove regex check from RestManager.simplifyUrl (#2910)
Co-authored-by: Jonathan Ho <heiheiho000@gmail.com>
2023-03-30 10:05:01 -05:00
ITOH
fdf0d53f9e refactor(rest)!: improve RestManager.createRequest (#2906)
* 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>
2023-03-30 09:54:02 -05:00
ITOH
7fae8c0315 refactor(rest): simplify manager.simplifyUrl (#2905)
* refactor(rest): simplify `manager.simplifyUrl`
The changes improve readability and performance by a small margin.

* fix tests
2023-03-29 22:35:17 +02:00
ITOH
a715140df6 feat(client,rest,types): add GetAuditLog.after (#2898)
* feat(client,rest,types): add `GetAuditLog.after`

closes: https://github.com/discordeno/discordeno/issues/2860

* Apply suggestions from code review

---------

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
2023-03-29 10:46:21 -05:00
Skillz
8bb91fa6f7 fix: apply the camelized types for docs improvements 2023-03-16 12:15:51 -05:00
Skillz4Killz
103310a8f4 fix: add authorization prop to rest for proxy 2023-03-16 12:50:16 +00:00
Jonathan Ho
6a6a3348c0 refactor: use node-fetch (#2832)
* refactor: use node-fetch

* test: fix import map
2023-03-14 19:08:30 -05:00
Skillz4Killz
4bb34c9087 fix: more props that need permission transforming (#2804) 2023-02-27 22:08:38 -06:00
Skillz
0a44962422 fix: more docs & remove logs for unit tests 2023-02-27 14:57:47 -06:00
Skillz
199af86c4e fix: deploy to npm 2023-02-27 14:39:17 -06:00
Skillz4Killz
3bbb03b8e3 cleanup cleanup cleanup on isle dd (#2792)
* cleanup cleanup cleanup on isle dd

* fix: rest manager import in test
2023-02-25 20:11:15 -06:00