|
| 1 | +import type { IOAuthApps } from '@rocket.chat/core-typings'; |
1 | 2 | import { OAuthApps } from '@rocket.chat/models'; |
2 | | -import { isUpdateOAuthAppParams, isOauthAppsGetParams, isOauthAppsAddParams, isDeleteOAuthAppParams } from '@rocket.chat/rest-typings'; |
| 3 | +import { ajv, isUpdateOAuthAppParams, isOauthAppsGetParams, isDeleteOAuthAppParams } from '@rocket.chat/rest-typings'; |
3 | 4 |
|
4 | 5 | import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; |
5 | 6 | import { apiDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; |
6 | 7 | import { addOAuthApp } from '../../../oauth2-server-config/server/admin/functions/addOAuthApp'; |
7 | 8 | import { deleteOAuthApp } from '../../../oauth2-server-config/server/admin/methods/deleteOAuthApp'; |
8 | 9 | import { updateOAuthApp } from '../../../oauth2-server-config/server/admin/methods/updateOAuthApp'; |
| 10 | +import type { ExtractRoutesFromAPI } from '../ApiClass'; |
9 | 11 | import { API } from '../api'; |
10 | 12 |
|
11 | 13 | API.v1.addRoute( |
@@ -83,18 +85,106 @@ API.v1.addRoute( |
83 | 85 | }, |
84 | 86 | ); |
85 | 87 |
|
86 | | -API.v1.addRoute( |
| 88 | +export type OauthAppsAddParams = { |
| 89 | + name: string; |
| 90 | + active: boolean; |
| 91 | + redirectUri: string; |
| 92 | +}; |
| 93 | + |
| 94 | +const OauthAppsAddParamsSchema = { |
| 95 | + type: 'object', |
| 96 | + properties: { |
| 97 | + name: { |
| 98 | + type: 'string', |
| 99 | + }, |
| 100 | + active: { |
| 101 | + type: 'boolean', |
| 102 | + }, |
| 103 | + redirectUri: { |
| 104 | + type: 'string', |
| 105 | + }, |
| 106 | + }, |
| 107 | + required: ['name', 'active', 'redirectUri'], |
| 108 | + additionalProperties: false, |
| 109 | +}; |
| 110 | + |
| 111 | +const isOauthAppsAddParams = ajv.compile<OauthAppsAddParams>(OauthAppsAddParamsSchema); |
| 112 | + |
| 113 | +const oauthAppsCreateEndpoints = API.v1.post( |
87 | 114 | 'oauth-apps.create', |
88 | 115 | { |
89 | 116 | authRequired: true, |
90 | | - validateParams: isOauthAppsAddParams, |
| 117 | + body: isOauthAppsAddParams, |
91 | 118 | permissionsRequired: ['manage-oauth-apps'], |
| 119 | + response: { |
| 120 | + 400: ajv.compile<{ |
| 121 | + error?: string; |
| 122 | + errorType?: string; |
| 123 | + stack?: string; |
| 124 | + details?: object; |
| 125 | + }>({ |
| 126 | + type: 'object', |
| 127 | + properties: { |
| 128 | + success: { type: 'boolean', enum: [false] }, |
| 129 | + stack: { type: 'string' }, |
| 130 | + error: { type: 'string' }, |
| 131 | + errorType: { type: 'string' }, |
| 132 | + details: { type: 'object' }, |
| 133 | + }, |
| 134 | + required: ['success'], |
| 135 | + additionalProperties: false, |
| 136 | + }), |
| 137 | + 401: ajv.compile({ |
| 138 | + type: 'object', |
| 139 | + properties: { |
| 140 | + success: { type: 'boolean', enum: [false] }, |
| 141 | + status: { type: 'string' }, |
| 142 | + message: { type: 'string' }, |
| 143 | + error: { type: 'string' }, |
| 144 | + errorType: { type: 'string' }, |
| 145 | + }, |
| 146 | + required: ['success'], |
| 147 | + additionalProperties: false, |
| 148 | + }), |
| 149 | + 403: ajv.compile({ |
| 150 | + type: 'object', |
| 151 | + properties: { |
| 152 | + success: { type: 'boolean', enum: [false] }, |
| 153 | + status: { type: 'string' }, |
| 154 | + message: { type: 'string' }, |
| 155 | + error: { type: 'string' }, |
| 156 | + errorType: { type: 'string' }, |
| 157 | + }, |
| 158 | + required: ['success'], |
| 159 | + additionalProperties: false, |
| 160 | + }), |
| 161 | + 200: ajv.compile<{ application: IOAuthApps }>({ |
| 162 | + type: 'object', |
| 163 | + properties: { |
| 164 | + application: { $ref: '#/components/schemas/IOAuthApps' }, |
| 165 | + success: { |
| 166 | + type: 'boolean', |
| 167 | + enum: [true], |
| 168 | + }, |
| 169 | + }, |
| 170 | + required: ['application', 'success'], |
| 171 | + additionalProperties: false, |
| 172 | + }), |
| 173 | + }, |
92 | 174 | }, |
93 | | - { |
94 | | - async post() { |
95 | | - const application = await addOAuthApp(this.bodyParams, this.userId); |
96 | 175 |
|
97 | | - return API.v1.success({ application }); |
98 | | - }, |
| 176 | + async function action() { |
| 177 | + const application = await addOAuthApp(this.bodyParams, this.userId); |
| 178 | + |
| 179 | + return API.v1.success({ application }); |
99 | 180 | }, |
100 | 181 | ); |
| 182 | + |
| 183 | +type OauthAppsCreateEndpoints = ExtractRoutesFromAPI<typeof oauthAppsCreateEndpoints>; |
| 184 | + |
| 185 | +export type OAuthAppsEndpoints = OauthAppsCreateEndpoints; |
| 186 | + |
| 187 | +declare module '@rocket.chat/rest-typings' { |
| 188 | + // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface |
| 189 | + interface Endpoints extends OauthAppsCreateEndpoints {} |
| 190 | +} |
0 commit comments