Skip to content

Commit

Permalink
fix(rest/oauth2): correct string literal types containing bot scope (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Renegade334 committed Sep 22, 2024
1 parent 5d95d97 commit 2ae2324
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 32 deletions.
16 changes: 8 additions & 8 deletions deno/rest/v10/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*/
Expand Down
16 changes: 8 additions & 8 deletions deno/rest/v9/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*/
Expand Down
16 changes: 8 additions & 8 deletions rest/v10/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*/
Expand Down
16 changes: 8 additions & 8 deletions rest/v9/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*/
Expand Down
21 changes: 21 additions & 0 deletions tests/v10/oauth2.test-d.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions tests/v9/oauth2.test-d.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 2ae2324

Please sign in to comment.