fix(rest/oauth2): correct string literal types containing bot scope (#1101)

This commit is contained in:
René
2024-09-22 14:01:27 +01:00
committed by GitHub
parent 5d95d970cf
commit 2ae232477a
6 changed files with 73 additions and 32 deletions

View File

@@ -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
*/

View File

@@ -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
*/

View File

@@ -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
*/

View File

@@ -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
*/

View File

@@ -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<RESTOAuth2BotAuthorizationQuery['scope']>(validBotScope);
expectNotAssignable<RESTOAuth2BotAuthorizationQuery['scope']>(invalidBotScope);
expectAssignable<RESTOAuth2AdvancedBotAuthorizationQuery['scope']>(validBotScope);
expectNotAssignable<RESTOAuth2AdvancedBotAuthorizationQuery['scope']>(invalidBotScope);

20
tests/v9/oauth2.test-d.ts Normal file
View File

@@ -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<RESTOAuth2BotAuthorizationQuery['scope']>(validBotScope);
expectNotAssignable<RESTOAuth2BotAuthorizationQuery['scope']>(invalidBotScope);
expectAssignable<RESTOAuth2AdvancedBotAuthorizationQuery['scope']>(validBotScope);
expectNotAssignable<RESTOAuth2AdvancedBotAuthorizationQuery['scope']>(invalidBotScope);