Skip to content

Commit 742992b

Browse files
chore: Add OpenAPI support for the Rocket.Chat e2e.setUserPublicAndPrivateKeys
- 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
1 parent a4341ec commit 742992b

File tree

5 files changed

+64
-117
lines changed

5 files changed

+64
-117
lines changed

.changeset/quiet-moles-remain.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rocket.chat/rest-typings': minor
3+
'@rocket.chat/meteor': minor
4+
---
5+
6+
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.

apps/meteor/app/api/server/v1/e2e.ts

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
validateUnauthorizedErrorResponse,
66
validateBadRequestErrorResponse,
77
validateForbiddenErrorResponse,
8-
ise2eSetUserPublicAndPrivateKeysParamsPOST,
98
} from '@rocket.chat/rest-typings';
109
import ExpiryMap from 'expiry-map';
1110

@@ -53,6 +52,12 @@ type E2EResetRoomKeyProps = {
5352
e2eKeyId: string;
5453
};
5554

55+
type e2eSetUserPublicAndPrivateKeysParamsPOST = {
56+
public_key: string;
57+
private_key: string;
58+
force?: boolean;
59+
};
60+
5661
const E2eSetRoomKeyIdSchema = {
5762
type: 'object',
5863
properties: {
@@ -156,6 +161,23 @@ const E2EResetRoomKeySchema = {
156161
additionalProperties: false,
157162
};
158163

164+
const e2eSetUserPublicAndPrivateKeysParamsPOSTSchema = {
165+
type: 'object',
166+
properties: {
167+
public_key: {
168+
type: 'string',
169+
},
170+
private_key: {
171+
type: 'string',
172+
},
173+
force: {
174+
type: 'boolean',
175+
},
176+
},
177+
additionalProperties: false,
178+
required: ['public_key', 'private_key'],
179+
};
180+
159181
const isE2eSetRoomKeyIdProps = ajv.compile<E2eSetRoomKeyIdProps>(E2eSetRoomKeyIdSchema);
160182

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

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

195+
const ise2eSetUserPublicAndPrivateKeysParamsPOST = ajv.compile<e2eSetUserPublicAndPrivateKeysParamsPOST>(
196+
e2eSetUserPublicAndPrivateKeysParamsPOSTSchema,
197+
);
198+
173199
const e2eEndpoints = API.v1
174200
.post(
175201
'e2e.setRoomKeyID',
@@ -293,6 +319,37 @@ const e2eEndpoints = API.v1
293319
return API.v1.success();
294320
},
295321
)
322+
.post(
323+
'e2e.setUserPublicAndPrivateKeys',
324+
{
325+
authRequired: true,
326+
body: ise2eSetUserPublicAndPrivateKeysParamsPOST,
327+
response: {
328+
400: validateBadRequestErrorResponse,
329+
401: validateUnauthorizedErrorResponse,
330+
200: ajv.compile<void>({
331+
type: 'object',
332+
properties: {
333+
success: { type: 'boolean', enum: [true] },
334+
},
335+
required: ['success'],
336+
}),
337+
},
338+
},
339+
340+
async function action() {
341+
// eslint-disable-next-line @typescript-eslint/naming-convention
342+
const { public_key, private_key, force } = this.bodyParams;
343+
344+
await setUserPublicAndPrivateKeysMethod(this.userId, {
345+
public_key,
346+
private_key,
347+
force,
348+
});
349+
350+
return API.v1.success();
351+
},
352+
)
296353
.post(
297354
'e2e.acceptSuggestedGroupKey',
298355
{
@@ -469,61 +526,6 @@ const e2eEndpoints = API.v1
469526
},
470527
);
471528

472-
/**
473-
* @openapi
474-
* /api/v1/e2e.setUserPublicAndPrivateKeys:
475-
* post:
476-
* description: Sets the end-to-end encryption keys for the authenticated user
477-
* security:
478-
* - autenticated: {}
479-
* requestBody:
480-
* description: A tuple containing the public and the private keys
481-
* content:
482-
* application/json:
483-
* schema:
484-
* type: object
485-
* properties:
486-
* public_key:
487-
* type: string
488-
* private_key:
489-
* type: string
490-
* force:
491-
* type: boolean
492-
* responses:
493-
* 200:
494-
* content:
495-
* application/json:
496-
* schema:
497-
* $ref: '#/components/schemas/ApiSuccessV1'
498-
* default:
499-
* description: Unexpected error
500-
* content:
501-
* application/json:
502-
* schema:
503-
* $ref: '#/components/schemas/ApiFailureV1'
504-
*/
505-
API.v1.addRoute(
506-
'e2e.setUserPublicAndPrivateKeys',
507-
{
508-
authRequired: true,
509-
validateParams: ise2eSetUserPublicAndPrivateKeysParamsPOST,
510-
},
511-
{
512-
async post() {
513-
// eslint-disable-next-line @typescript-eslint/naming-convention
514-
const { public_key, private_key, force } = this.bodyParams;
515-
516-
await setUserPublicAndPrivateKeysMethod(this.userId, {
517-
public_key,
518-
private_key,
519-
force,
520-
});
521-
522-
return API.v1.success();
523-
},
524-
},
525-
);
526-
527529
type E2eEndpoints = ExtractRoutesFromAPI<typeof e2eEndpoints>;
528530

529531
declare module '@rocket.chat/rest-typings' {

packages/rest-typings/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type { CommandsEndpoints } from './v1/commands';
1515
import type { CustomUserStatusEndpoints } from './v1/customUserStatus';
1616
import type { DirectoryEndpoint } from './v1/directory';
1717
import type { ImEndpoints, DmEndpoints } from './v1/dm';
18-
import type { E2eEndpoints } from './v1/e2e';
1918
import type { EmailInboxEndpoints } from './v1/email-inbox';
2019
import type { EmojiCustomEndpoints } from './v1/emojiCustom';
2120
import type { FederationEndpoints } from './v1/federation';
@@ -78,7 +77,6 @@ export interface Endpoints
7877
IntegrationHooksEndpoints,
7978
VideoConferenceEndpoints,
8079
InvitesEndpoints,
81-
E2eEndpoints,
8280
AssetsEndpoints,
8381
EmailInboxEndpoints,
8482
MailerEndpoints,
@@ -243,8 +241,6 @@ export * from './v1/server-events';
243241

244242
export * from './v1/autotranslate/AutotranslateGetSupportedLanguagesParamsGET';
245243
export * from './v1/autotranslate/AutotranslateSaveSettingsParamsPOST';
246-
export * from './v1/e2e/e2eSetUserPublicAndPrivateKeysParamsPOST';
247-
export * from './v1/e2e';
248244
export * from './v1/import';
249245
export * from './v1/email-inbox';
250246
export * from './v1/calendar';

packages/rest-typings/src/v1/e2e.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/rest-typings/src/v1/e2e/e2eSetUserPublicAndPrivateKeysParamsPOST.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)