Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/quiet-moles-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': minor
'@rocket.chat/meteor': minor
---

Add OpenAPI support for the Rocket.Chat e2e.setUserPublicAndPrivateKeys endpoints by migrating to a modern chained route definition syntax and utilizing shared AJV schemas for validation to enhance API documentation and ensure type safety through response validation.
114 changes: 58 additions & 56 deletions apps/meteor/app/api/server/v1/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
validateUnauthorizedErrorResponse,
validateBadRequestErrorResponse,
validateForbiddenErrorResponse,
ise2eSetUserPublicAndPrivateKeysParamsPOST,
} from '@rocket.chat/rest-typings';
import ExpiryMap from 'expiry-map';

Expand Down Expand Up @@ -53,6 +52,12 @@ type E2EResetRoomKeyProps = {
e2eKeyId: string;
};

type e2eSetUserPublicAndPrivateKeysParamsPOST = {
public_key: string;
private_key: string;
force?: boolean;
};

const E2eSetRoomKeyIdSchema = {
type: 'object',
properties: {
Expand Down Expand Up @@ -156,6 +161,23 @@ const E2EResetRoomKeySchema = {
additionalProperties: false,
};

const e2eSetUserPublicAndPrivateKeysParamsPOSTSchema = {
type: 'object',
properties: {
public_key: {
type: 'string',
},
private_key: {
type: 'string',
},
force: {
type: 'boolean',
},
},
additionalProperties: false,
required: ['public_key', 'private_key'],
};

const isE2eSetRoomKeyIdProps = ajv.compile<E2eSetRoomKeyIdProps>(E2eSetRoomKeyIdSchema);

const ise2eGetUsersOfRoomWithoutKeyParamsGET = ajv.compile<e2eGetUsersOfRoomWithoutKeyParamsGET>(
Expand All @@ -170,6 +192,10 @@ const isE2EProvideUsersGroupKeyProps = ajv.compile<E2EProvideUsersGroupKeyProps>

const isE2EResetRoomKeyProps = ajv.compile<E2EResetRoomKeyProps>(E2EResetRoomKeySchema);

const ise2eSetUserPublicAndPrivateKeysParamsPOST = ajv.compile<e2eSetUserPublicAndPrivateKeysParamsPOST>(
e2eSetUserPublicAndPrivateKeysParamsPOSTSchema,
);

const e2eEndpoints = API.v1
.post(
'e2e.setRoomKeyID',
Expand Down Expand Up @@ -293,6 +319,37 @@ const e2eEndpoints = API.v1
return API.v1.success();
},
)
.post(
'e2e.setUserPublicAndPrivateKeys',
{
authRequired: true,
body: ise2eSetUserPublicAndPrivateKeysParamsPOST,
response: {
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
200: ajv.compile<void>({
type: 'object',
properties: {
success: { type: 'boolean', enum: [true] },
},
required: ['success'],
}),
},
},

async function action() {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { public_key, private_key, force } = this.bodyParams;

await setUserPublicAndPrivateKeysMethod(this.userId, {
public_key,
private_key,
force,
});

return API.v1.success();
},
)
.post(
'e2e.acceptSuggestedGroupKey',
{
Expand Down Expand Up @@ -469,61 +526,6 @@ const e2eEndpoints = API.v1
},
);

/**
* @openapi
* /api/v1/e2e.setUserPublicAndPrivateKeys:
* post:
* description: Sets the end-to-end encryption keys for the authenticated user
* security:
* - autenticated: {}
* requestBody:
* description: A tuple containing the public and the private keys
* content:
* application/json:
* schema:
* type: object
* properties:
* public_key:
* type: string
* private_key:
* type: string
* force:
* type: boolean
* responses:
* 200:
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ApiSuccessV1'
* default:
* description: Unexpected error
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ApiFailureV1'
*/
API.v1.addRoute(
'e2e.setUserPublicAndPrivateKeys',
{
authRequired: true,
validateParams: ise2eSetUserPublicAndPrivateKeysParamsPOST,
},
{
async post() {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { public_key, private_key, force } = this.bodyParams;

await setUserPublicAndPrivateKeysMethod(this.userId, {
public_key,
private_key,
force,
});

return API.v1.success();
},
},
);

type E2eEndpoints = ExtractRoutesFromAPI<typeof e2eEndpoints>;

declare module '@rocket.chat/rest-typings' {
Expand Down
4 changes: 0 additions & 4 deletions packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { CommandsEndpoints } from './v1/commands';
import type { CustomUserStatusEndpoints } from './v1/customUserStatus';
import type { DirectoryEndpoint } from './v1/directory';
import type { ImEndpoints, DmEndpoints } from './v1/dm';
import type { E2eEndpoints } from './v1/e2e';
import type { EmailInboxEndpoints } from './v1/email-inbox';
import type { EmojiCustomEndpoints } from './v1/emojiCustom';
import type { FederationEndpoints } from './v1/federation';
Expand Down Expand Up @@ -78,7 +77,6 @@ export interface Endpoints
IntegrationHooksEndpoints,
VideoConferenceEndpoints,
InvitesEndpoints,
E2eEndpoints,
AssetsEndpoints,
EmailInboxEndpoints,
MailerEndpoints,
Expand Down Expand Up @@ -243,8 +241,6 @@ export * from './v1/server-events';

export * from './v1/autotranslate/AutotranslateGetSupportedLanguagesParamsGET';
export * from './v1/autotranslate/AutotranslateSaveSettingsParamsPOST';
export * from './v1/e2e/e2eSetUserPublicAndPrivateKeysParamsPOST';
export * from './v1/e2e';
export * from './v1/import';
export * from './v1/email-inbox';
export * from './v1/calendar';
Expand Down
29 changes: 0 additions & 29 deletions packages/rest-typings/src/v1/e2e.ts

This file was deleted.

This file was deleted.

Loading