Skip to content

Commit

Permalink
chore: cleanup codes
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Dec 23, 2024
1 parent 72a271a commit 12b06fa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
2 changes: 2 additions & 0 deletions packages/backend/server/src/core/auth/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class AuthController {
}

@Public()
@UseNamedGuard('version')
@Post('/preflight')
async preflight(
@Body() params?: { email: string }
Expand Down Expand Up @@ -236,6 +237,7 @@ export class AuthController {
}

@Public()
@UseNamedGuard('version')
@Post('/magic-link')
async magicLinkSignIn(
@Req() req: Request,
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/server/src/core/version/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export class VersionGuardProvider

const version = req.headers['x-affine-version'];

return await this.version.checkVersion(version);
return this.version.checkVersion(version);
}
}
3 changes: 3 additions & 0 deletions packages/backend/server/src/plugins/oauth/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
OauthAccountAlreadyConnected,
OauthStateExpired,
UnknownOauthProvider,
UseNamedGuard,
} from '../../base';
import { AuthService, Public } from '../../core/auth';
import { UserService } from '../../core/user';
Expand All @@ -35,6 +36,7 @@ export class OAuthController {
) {}

@Public()
@UseNamedGuard('version')
@Post('/preflight')
@HttpCode(HttpStatus.OK)
async preflight(
Expand Down Expand Up @@ -64,6 +66,7 @@ export class OAuthController {
}

@Public()
@UseNamedGuard('version')
@Post('/callback')
@HttpCode(HttpStatus.OK)
async callback(
Expand Down
28 changes: 14 additions & 14 deletions packages/backend/server/tests/version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ test('should be able to prevent requests if version outdated', async t => {
await runtime.set('version/allowedVersion', 'unknownVersion');
await t.notThrowsAsync(
fetchWithVersion(app.getHttpServer(), undefined, HttpStatus.OK),
'should not check version if invalid minVersion provided'
'should not check version if invalid allowedVersion provided'
);
await t.notThrowsAsync(
fetchWithVersion(app.getHttpServer(), '0.0.1', HttpStatus.OK),
'should not check version if invalid minVersion provided'
'should not check version if invalid allowedVersion provided'
);

await runtime.set('version/allowedVersion', '0.0.1');
Expand All @@ -121,7 +121,7 @@ test('should be able to prevent requests if version outdated', async t => {
{
message: 'Unsupported client version: 0.0.0, please upgrade to 0.0.1.',
},
'should reject version if valid minVersion provided'
'should reject version if valid allowedVersion provided'
);

await runtime.set(
Expand All @@ -130,15 +130,15 @@ test('should be able to prevent requests if version outdated', async t => {
);
await t.notThrowsAsync(
fetchWithVersion(app.getHttpServer(), '0.17.5', HttpStatus.OK),
'should pass version if version satisfies minVersion'
'should pass version if version satisfies allowedVersion'
);
await t.throwsAsync(
fetchWithVersion(app.getHttpServer(), '0.17.4', HttpStatus.FORBIDDEN),
{
message:
'Unsupported client version: 0.17.4, please upgrade to 0.18.0.',
},
'should reject version if valid minVersion provided'
'should reject version if valid allowedVersion provided'
);
await t.throwsAsync(
fetchWithVersion(
Expand All @@ -150,19 +150,19 @@ test('should be able to prevent requests if version outdated', async t => {
message:
'Unsupported client version: 0.17.6-nightly-f0d99f4, please upgrade to 0.18.0.',
},
'should reject version if valid minVersion provided'
'should reject version if valid allowedVersion provided'
);
await t.notThrowsAsync(
fetchWithVersion(
app.getHttpServer(),
'0.18.0-nightly-cc9b38c',
HttpStatus.OK
),
'should pass version if version satisfies minVersion'
'should pass version if version satisfies allowedVersion'
);
await t.notThrowsAsync(
fetchWithVersion(app.getHttpServer(), '0.18.1', HttpStatus.OK),
'should pass version if version satisfies minVersion'
'should pass version if version satisfies allowedVersion'
);
}

Expand All @@ -174,18 +174,18 @@ test('should be able to prevent requests if version outdated', async t => {

await t.notThrowsAsync(
fetchWithVersion(app.getHttpServer(), '0.0.1', HttpStatus.OK),
'should pass version if version satisfies minVersion'
'should pass version if version satisfies allowedVersion'
);
await t.notThrowsAsync(
fetchWithVersion(app.getHttpServer(), '0.1.2', HttpStatus.OK),
'should pass version if version satisfies maxVersion'
'should pass version if version satisfies allowedVersion'
);
await t.throwsAsync(
fetchWithVersion(app.getHttpServer(), '0.1.3', HttpStatus.FORBIDDEN),
{
message: 'Unsupported client version: 0.1.3, please upgrade to 0.3.0.',
},
'should reject version if valid maxVersion provided'
'should reject version if valid allowedVersion provided'
);

await t.notThrowsAsync(
Expand All @@ -194,15 +194,15 @@ test('should be able to prevent requests if version outdated', async t => {
'0.2.0-nightly-cc9b38c',
HttpStatus.OK
),
'should pass version if version satisfies maxVersion'
'should pass version if version satisfies allowedVersion'
);

await t.throwsAsync(
fetchWithVersion(app.getHttpServer(), '0.2.0', HttpStatus.FORBIDDEN),
{
message: 'Unsupported client version: 0.2.0, please upgrade to 0.3.0.',
},
'should reject version if valid maxVersion provided'
'should reject version if valid allowedVersion provided'
);

await t.throwsAsync(
Expand All @@ -211,7 +211,7 @@ test('should be able to prevent requests if version outdated', async t => {
message:
'Unsupported client version: 0.3.1, please downgrade to 0.3.0.',
},
'should reject version if valid maxVersion provided'
'should reject version if valid allowedVersion provided'
);
}
});
11 changes: 10 additions & 1 deletion packages/frontend/graphql/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
export type Maybe<T> = T | null;
export type InputMaybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
Expand Down Expand Up @@ -285,6 +285,7 @@ export type ErrorDataUnion =
| SubscriptionNotExistsDataType
| SubscriptionPlanNotFoundDataType
| UnknownOauthProviderDataType
| UnsupportedClientVersionDataType
| UnsupportedSubscriptionPlanDataType
| VersionRejectedDataType
| WrongSignInCredentialsDataType;
Expand Down Expand Up @@ -361,6 +362,7 @@ export enum ErrorNames {
TOO_MANY_REQUEST = 'TOO_MANY_REQUEST',
UNKNOWN_OAUTH_PROVIDER = 'UNKNOWN_OAUTH_PROVIDER',
UNSPLASH_IS_NOT_CONFIGURED = 'UNSPLASH_IS_NOT_CONFIGURED',
UNSUPPORTED_CLIENT_VERSION = 'UNSUPPORTED_CLIENT_VERSION',
UNSUPPORTED_SUBSCRIPTION_PLAN = 'UNSUPPORTED_SUBSCRIPTION_PLAN',
USER_AVATAR_NOT_FOUND = 'USER_AVATAR_NOT_FOUND',
USER_NOT_FOUND = 'USER_NOT_FOUND',
Expand Down Expand Up @@ -1208,6 +1210,13 @@ export interface UnknownOauthProviderDataType {
name: Scalars['String']['output'];
}

export interface UnsupportedClientVersionDataType {
__typename?: 'UnsupportedClientVersionDataType';
action: Scalars['String']['output'];
clientVersion: Scalars['String']['output'];
recommendedVersion: Scalars['String']['output'];
}

export interface UnsupportedSubscriptionPlanDataType {
__typename?: 'UnsupportedSubscriptionPlanDataType';
plan: Scalars['String']['output'];
Expand Down

0 comments on commit 12b06fa

Please sign in to comment.