Skip to content

Commit bcfd7c3

Browse files
authored
Merge branch 'main' into fix/thread-channelnames
2 parents 0f93eb5 + b360b2e commit bcfd7c3

File tree

7 files changed

+190
-34
lines changed

7 files changed

+190
-34
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"RESTAPIMessageReference",
4242
"RESTAPIPartialCurrentUserGuild",
4343
"RESTAPIPoll",
44+
"RESTOAuth2TokenOptionalClientCredentials",
4445

4546
"RESTOAuth2AdvancedBotAuthorizationQuery",
4647
"RESTOAuth2AdvancedBotAuthorizationQueryResult",

deno/rest/v10/oauth2.ts

Lines changed: 14 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deno/rest/v9/oauth2.ts

Lines changed: 14 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest/v10/oauth2.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,20 @@ export interface RESTPostOAuth2AuthorizationQueryResult {
6262
export type RESTOAuth2AuthorizationQueryResult = RESTPostOAuth2AuthorizationQueryResult;
6363

6464
/**
65+
* @remarks
66+
* This endpoint requires either HTTP Basic authentication using `client_id:client_secret`,
67+
* or the `client_id` and `client_secret` must be provided in the form body.
6568
* @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-redirect-url-example}
6669
*/
67-
export interface RESTPostOAuth2AccessTokenURLEncodedData {
68-
client_id: Snowflake;
69-
client_secret: string;
70+
export type RESTPostOAuth2AccessTokenURLEncodedData = RESTOAuth2TokenOptionalClientCredentials & {
7071
grant_type: 'authorization_code';
7172
code: string;
7273
redirect_uri?: string;
73-
}
74+
};
75+
76+
export type RESTOAuth2TokenOptionalClientCredentials =
77+
| { client_id: Snowflake; client_secret: string }
78+
| { client_id?: never; client_secret?: never };
7479

7580
/**
7681
* @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-access-token-response}
@@ -84,14 +89,15 @@ export interface RESTPostOAuth2AccessTokenResult {
8489
}
8590

8691
/**
92+
* @remarks
93+
* This endpoint requires either HTTP Basic authentication using `client_id:client_secret`,
94+
* or the `client_id` and `client_secret` must be provided in the form body.
8795
* @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-refresh-token-exchange-example}
8896
*/
89-
export interface RESTPostOAuth2RefreshTokenURLEncodedData {
90-
client_id: Snowflake;
91-
client_secret: string;
97+
export type RESTPostOAuth2RefreshTokenURLEncodedData = RESTOAuth2TokenOptionalClientCredentials & {
9298
grant_type: 'refresh_token';
9399
refresh_token: string;
94-
}
100+
};
95101

96102
export type RESTPostOAuth2RefreshTokenResult = RESTPostOAuth2AccessTokenResult;
97103

rest/v9/oauth2.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,20 @@ export interface RESTPostOAuth2AuthorizationQueryResult {
6262
export type RESTOAuth2AuthorizationQueryResult = RESTPostOAuth2AuthorizationQueryResult;
6363

6464
/**
65+
* @remarks
66+
* This endpoint requires either HTTP Basic authentication using `client_id:client_secret`,
67+
* or the `client_id` and `client_secret` must be provided in the form body.
6568
* @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-redirect-url-example}
6669
*/
67-
export interface RESTPostOAuth2AccessTokenURLEncodedData {
68-
client_id: Snowflake;
69-
client_secret: string;
70+
export type RESTPostOAuth2AccessTokenURLEncodedData = RESTOAuth2TokenOptionalClientCredentials & {
7071
grant_type: 'authorization_code';
7172
code: string;
7273
redirect_uri?: string;
73-
}
74+
};
75+
76+
export type RESTOAuth2TokenOptionalClientCredentials =
77+
| { client_id: Snowflake; client_secret: string }
78+
| { client_id?: never; client_secret?: never };
7479

7580
/**
7681
* @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-access-token-response}
@@ -84,14 +89,15 @@ export interface RESTPostOAuth2AccessTokenResult {
8489
}
8590

8691
/**
92+
* @remarks
93+
* This endpoint requires either HTTP Basic authentication using `client_id:client_secret`,
94+
* or the `client_id` and `client_secret` must be provided in the form body.
8795
* @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-refresh-token-exchange-example}
8896
*/
89-
export interface RESTPostOAuth2RefreshTokenURLEncodedData {
90-
client_id: Snowflake;
91-
client_secret: string;
97+
export type RESTPostOAuth2RefreshTokenURLEncodedData = RESTOAuth2TokenOptionalClientCredentials & {
9298
grant_type: 'refresh_token';
9399
refresh_token: string;
94-
}
100+
};
95101

96102
export type RESTPostOAuth2RefreshTokenResult = RESTPostOAuth2AccessTokenResult;
97103

tests/v10/oauth2.ts

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import type { OAuth2Scopes, RESTOAuth2BotAuthorizationQuery, RESTOAuth2AdvancedBotAuthorizationQuery } from '../../v10';
1+
import type {
2+
OAuth2Scopes,
3+
RESTOAuth2BotAuthorizationQuery,
4+
RESTOAuth2AdvancedBotAuthorizationQuery,
5+
RESTPostOAuth2AccessTokenURLEncodedData,
6+
RESTPostOAuth2RefreshTokenURLEncodedData,
7+
} from '../../v10';
28
import { expectAssignable, expectNotAssignable } from '../__utils__/type-assertions';
39

410
declare const validBotScope:
@@ -22,3 +28,63 @@ expectNotAssignable<RESTOAuth2BotAuthorizationQuery['scope']>(invalidBotScope);
2228
expectAssignable<RESTOAuth2AdvancedBotAuthorizationQuery['scope']>(validBotScope);
2329
// @ts-expect-error - invalid scope
2430
expectNotAssignable<RESTOAuth2AdvancedBotAuthorizationQuery['scope']>(invalidBotScope);
31+
32+
{
33+
expectAssignable<RESTPostOAuth2AccessTokenURLEncodedData>({
34+
code: 'code',
35+
grant_type: 'authorization_code',
36+
redirect_uri: 'https://discord.com',
37+
});
38+
39+
expectAssignable<RESTPostOAuth2AccessTokenURLEncodedData>({
40+
client_id: '123456789',
41+
client_secret: 'very secret',
42+
code: 'code',
43+
grant_type: 'authorization_code',
44+
redirect_uri: 'https://discord.com',
45+
});
46+
47+
// @ts-expect-error - client_secret is missing
48+
expectNotAssignable<RESTPostOAuth2AccessTokenURLEncodedData>({
49+
client_id: '123456789',
50+
code: 'code',
51+
grant_type: 'authorization_code',
52+
redirect_uri: 'https://discord.com',
53+
});
54+
55+
// @ts-expect-error - client_id is missing
56+
expectNotAssignable<RESTPostOAuth2AccessTokenURLEncodedData>({
57+
client_secret: 'very secret',
58+
code: 'code',
59+
grant_type: 'authorization_code',
60+
redirect_uri: 'https://discord.com',
61+
});
62+
}
63+
64+
{
65+
expectAssignable<RESTPostOAuth2RefreshTokenURLEncodedData>({
66+
grant_type: 'refresh_token',
67+
refresh_token: 'a real token this is',
68+
});
69+
70+
expectAssignable<RESTPostOAuth2RefreshTokenURLEncodedData>({
71+
client_id: '123456789',
72+
client_secret: 'very secret',
73+
grant_type: 'refresh_token',
74+
refresh_token: 'a real token this is',
75+
});
76+
77+
// @ts-expect-error - client_secret is missing
78+
expectNotAssignable<RESTPostOAuth2RefreshTokenURLEncodedData>({
79+
client_id: '123456789',
80+
grant_type: 'refresh_token',
81+
refresh_token: 'a real token this is',
82+
});
83+
84+
// @ts-expect-error - client_id is missing
85+
expectNotAssignable<RESTPostOAuth2RefreshTokenURLEncodedData>({
86+
client_secret: 'very secret',
87+
grant_type: 'refresh_token',
88+
refresh_token: 'a real token this is',
89+
});
90+
}

tests/v9/oauth2.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import type { OAuth2Scopes, RESTOAuth2BotAuthorizationQuery, RESTOAuth2AdvancedBotAuthorizationQuery } from '../../v9';
1+
import type {
2+
OAuth2Scopes,
3+
RESTOAuth2BotAuthorizationQuery,
4+
RESTOAuth2AdvancedBotAuthorizationQuery,
5+
RESTPostOAuth2AccessTokenURLEncodedData,
6+
RESTPostOAuth2RefreshTokenURLEncodedData,
7+
} from '../../v9';
28
import { expectAssignable, expectNotAssignable } from '../__utils__/type-assertions';
39

410
declare const validBotScope:
@@ -20,3 +26,62 @@ expectNotAssignable<RESTOAuth2BotAuthorizationQuery['scope']>(invalidBotScope);
2026
expectAssignable<RESTOAuth2AdvancedBotAuthorizationQuery['scope']>(validBotScope);
2127
// @ts-expect-error - invalid scope
2228
expectNotAssignable<RESTOAuth2AdvancedBotAuthorizationQuery['scope']>(invalidBotScope);
29+
{
30+
expectAssignable<RESTPostOAuth2AccessTokenURLEncodedData>({
31+
code: 'code',
32+
grant_type: 'authorization_code',
33+
redirect_uri: 'https://discord.com',
34+
});
35+
36+
expectAssignable<RESTPostOAuth2AccessTokenURLEncodedData>({
37+
client_id: '123456789',
38+
client_secret: 'very secret',
39+
code: 'code',
40+
grant_type: 'authorization_code',
41+
redirect_uri: 'https://discord.com',
42+
});
43+
44+
// @ts-expect-error - client_secret is missing
45+
expectNotAssignable<RESTPostOAuth2AccessTokenURLEncodedData>({
46+
client_id: '123456789',
47+
code: 'code',
48+
grant_type: 'authorization_code',
49+
redirect_uri: 'https://discord.com',
50+
});
51+
52+
// @ts-expect-error - client_id is missing
53+
expectNotAssignable<RESTPostOAuth2AccessTokenURLEncodedData>({
54+
client_secret: 'very secret',
55+
code: 'code',
56+
grant_type: 'authorization_code',
57+
redirect_uri: 'https://discord.com',
58+
});
59+
}
60+
61+
{
62+
expectAssignable<RESTPostOAuth2RefreshTokenURLEncodedData>({
63+
grant_type: 'refresh_token',
64+
refresh_token: 'a real token this is',
65+
});
66+
67+
expectAssignable<RESTPostOAuth2RefreshTokenURLEncodedData>({
68+
client_id: '123456789',
69+
client_secret: 'very secret',
70+
grant_type: 'refresh_token',
71+
refresh_token: 'a real token this is',
72+
});
73+
74+
// @ts-expect-error - client_secret is missing
75+
expectNotAssignable<RESTPostOAuth2RefreshTokenURLEncodedData>({
76+
client_id: '123456789',
77+
grant_type: 'refresh_token',
78+
refresh_token: 'a real token this is',
79+
});
80+
81+
// @ts-expect-error - client_id is missing
82+
expectNotAssignable<RESTPostOAuth2RefreshTokenURLEncodedData>({
83+
client_secret: 'very secret',
84+
grant_type: 'refresh_token',
85+
refresh_token: 'a real token this is',
86+
});
87+
}

0 commit comments

Comments
 (0)