From 2ae232477a1362eb0bd5c4aeee4a97bfbca7b2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= <9092381+Renegade334@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:01:27 +0100 Subject: [PATCH] fix(rest/oauth2): correct string literal types containing bot scope (#1101) --- deno/rest/v10/oauth2.ts | 16 ++++++++-------- deno/rest/v9/oauth2.ts | 16 ++++++++-------- rest/v10/oauth2.ts | 16 ++++++++-------- rest/v9/oauth2.ts | 16 ++++++++-------- tests/v10/oauth2.test-d.ts | 21 +++++++++++++++++++++ tests/v9/oauth2.test-d.ts | 20 ++++++++++++++++++++ 6 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 tests/v10/oauth2.test-d.ts create mode 100644 tests/v9/oauth2.test-d.ts diff --git a/deno/rest/v10/oauth2.ts b/deno/rest/v10/oauth2.ts index 67b18765..09f28158 100644 --- a/deno/rest/v10/oauth2.ts +++ b/deno/rest/v10/oauth2.ts @@ -134,10 +134,10 @@ export interface RESTOAuth2BotAuthorizationQuery { * Needs to include bot for the bot flow */ scope: - | OAuth2Scopes.Bot - | `${OAuth2Scopes.Bot}${' ' | '%20'}${string}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}${string}${' ' | '%20'}`; + | `${OAuth2Scopes.Bot} ${string}` + | `${OAuth2Scopes.Bot}` + | `${string} ${OAuth2Scopes.Bot} ${string}` + | `${string} ${OAuth2Scopes.Bot}`; /** * The permissions you're requesting * @@ -163,10 +163,10 @@ export interface RESTOAuth2AdvancedBotAuthorizationQuery { * This assumes you include the `bot` scope alongside others (like `identify` for example) */ scope: - | OAuth2Scopes.Bot - | `${OAuth2Scopes.Bot}${' ' | '%20'}${string}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}${string}${' ' | '%20'}`; + | `${OAuth2Scopes.Bot} ${string}` + | `${OAuth2Scopes.Bot}` + | `${string} ${OAuth2Scopes.Bot} ${string}` + | `${string} ${OAuth2Scopes.Bot}`; /** * The required permissions bitfield, stringified */ diff --git a/deno/rest/v9/oauth2.ts b/deno/rest/v9/oauth2.ts index b5d9fe77..297001c0 100644 --- a/deno/rest/v9/oauth2.ts +++ b/deno/rest/v9/oauth2.ts @@ -134,10 +134,10 @@ export interface RESTOAuth2BotAuthorizationQuery { * Needs to include bot for the bot flow */ scope: - | OAuth2Scopes.Bot - | `${OAuth2Scopes.Bot}${' ' | '%20'}${string}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}${string}${' ' | '%20'}`; + | `${OAuth2Scopes.Bot} ${string}` + | `${OAuth2Scopes.Bot}` + | `${string} ${OAuth2Scopes.Bot} ${string}` + | `${string} ${OAuth2Scopes.Bot}`; /** * The permissions you're requesting * @@ -163,10 +163,10 @@ export interface RESTOAuth2AdvancedBotAuthorizationQuery { * This assumes you include the `bot` scope alongside others (like `identify` for example) */ scope: - | OAuth2Scopes.Bot - | `${OAuth2Scopes.Bot}${' ' | '%20'}${string}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}${string}${' ' | '%20'}`; + | `${OAuth2Scopes.Bot} ${string}` + | `${OAuth2Scopes.Bot}` + | `${string} ${OAuth2Scopes.Bot} ${string}` + | `${string} ${OAuth2Scopes.Bot}`; /** * The required permissions bitfield, stringified */ diff --git a/rest/v10/oauth2.ts b/rest/v10/oauth2.ts index 2552cead..c18993a7 100644 --- a/rest/v10/oauth2.ts +++ b/rest/v10/oauth2.ts @@ -134,10 +134,10 @@ export interface RESTOAuth2BotAuthorizationQuery { * Needs to include bot for the bot flow */ scope: - | OAuth2Scopes.Bot - | `${OAuth2Scopes.Bot}${' ' | '%20'}${string}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}${string}${' ' | '%20'}`; + | `${OAuth2Scopes.Bot} ${string}` + | `${OAuth2Scopes.Bot}` + | `${string} ${OAuth2Scopes.Bot} ${string}` + | `${string} ${OAuth2Scopes.Bot}`; /** * The permissions you're requesting * @@ -163,10 +163,10 @@ export interface RESTOAuth2AdvancedBotAuthorizationQuery { * This assumes you include the `bot` scope alongside others (like `identify` for example) */ scope: - | OAuth2Scopes.Bot - | `${OAuth2Scopes.Bot}${' ' | '%20'}${string}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}${string}${' ' | '%20'}`; + | `${OAuth2Scopes.Bot} ${string}` + | `${OAuth2Scopes.Bot}` + | `${string} ${OAuth2Scopes.Bot} ${string}` + | `${string} ${OAuth2Scopes.Bot}`; /** * The required permissions bitfield, stringified */ diff --git a/rest/v9/oauth2.ts b/rest/v9/oauth2.ts index 059cf7e6..6178b61a 100644 --- a/rest/v9/oauth2.ts +++ b/rest/v9/oauth2.ts @@ -134,10 +134,10 @@ export interface RESTOAuth2BotAuthorizationQuery { * Needs to include bot for the bot flow */ scope: - | OAuth2Scopes.Bot - | `${OAuth2Scopes.Bot}${' ' | '%20'}${string}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}${string}${' ' | '%20'}`; + | `${OAuth2Scopes.Bot} ${string}` + | `${OAuth2Scopes.Bot}` + | `${string} ${OAuth2Scopes.Bot} ${string}` + | `${string} ${OAuth2Scopes.Bot}`; /** * The permissions you're requesting * @@ -163,10 +163,10 @@ export interface RESTOAuth2AdvancedBotAuthorizationQuery { * This assumes you include the `bot` scope alongside others (like `identify` for example) */ scope: - | OAuth2Scopes.Bot - | `${OAuth2Scopes.Bot}${' ' | '%20'}${string}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}` - | `${string}${' ' | '%20'}${OAuth2Scopes.Bot}${string}${' ' | '%20'}`; + | `${OAuth2Scopes.Bot} ${string}` + | `${OAuth2Scopes.Bot}` + | `${string} ${OAuth2Scopes.Bot} ${string}` + | `${string} ${OAuth2Scopes.Bot}`; /** * The required permissions bitfield, stringified */ diff --git a/tests/v10/oauth2.test-d.ts b/tests/v10/oauth2.test-d.ts new file mode 100644 index 00000000..7ee7128e --- /dev/null +++ b/tests/v10/oauth2.test-d.ts @@ -0,0 +1,21 @@ +import { expectAssignable, expectNotAssignable } from 'tsd'; +import type { OAuth2Scopes, RESTOAuth2BotAuthorizationQuery, RESTOAuth2AdvancedBotAuthorizationQuery } from '../../v10'; + +declare const validBotScope: + | OAuth2Scopes.Bot + | 'bot' + | 'bot identify' + | 'applications.commands bot' + | 'applications.commands bot identify'; +declare const invalidBotScope: + | OAuth2Scopes.ApplicationsCommands + | 'applications.commands' + | 'applications.commands identify' + | 'bot%20identify' + | ''; + +expectAssignable(validBotScope); +expectNotAssignable(invalidBotScope); + +expectAssignable(validBotScope); +expectNotAssignable(invalidBotScope); diff --git a/tests/v9/oauth2.test-d.ts b/tests/v9/oauth2.test-d.ts new file mode 100644 index 00000000..28553853 --- /dev/null +++ b/tests/v9/oauth2.test-d.ts @@ -0,0 +1,20 @@ +import { expectAssignable, expectNotAssignable } from 'tsd'; +import type { OAuth2Scopes, RESTOAuth2BotAuthorizationQuery, RESTOAuth2AdvancedBotAuthorizationQuery } from '../../v9'; + +declare const validBotScope: + | OAuth2Scopes.Bot + | 'bot' + | 'bot identify' + | 'applications.commands bot' + | 'applications.commands bot identify'; +declare const invalidBotScope: + | OAuth2Scopes.ApplicationsCommands + | 'applications.commands' + | 'applications.commands identify' + | ''; + +expectAssignable(validBotScope); +expectNotAssignable(invalidBotScope); + +expectAssignable(validBotScope); +expectNotAssignable(invalidBotScope);