diff --git a/apps/meteor/app/api/server/api.ts b/apps/meteor/app/api/server/api.ts index b603274ab85..2898624f191 100644 --- a/apps/meteor/app/api/server/api.ts +++ b/apps/meteor/app/api/server/api.ts @@ -88,7 +88,7 @@ interface IAPIDefaultFieldsToExclude { inviteToken: number; } -type RateLimiterOptions = { +export type RateLimiterOptions = { numRequestsAllowed?: number; intervalTimeInMS?: number; }; @@ -320,6 +320,16 @@ export class APIClass< }; } + public unavailableResult(msg?: T): InternalError { + return { + statusCode: 503, + body: { + success: false, + error: msg || 'Service unavailable', + }, + }; + } + public unauthorized(msg?: T): UnauthorizedResult { return { statusCode: 401, @@ -421,7 +431,7 @@ export class APIClass< }: { routes: string[]; rateLimiterOptions: RateLimiterOptions | boolean; - endpoints: string[]; + endpoints: Record | string[]; }): void { if (typeof rateLimiterOptions !== 'object') { throw new Meteor.Error('"rateLimiterOptions" must be an object'); diff --git a/apps/meteor/app/api/server/definition.ts b/apps/meteor/app/api/server/definition.ts index d2da73d500d..25ae81f08ed 100644 --- a/apps/meteor/app/api/server/definition.ts +++ b/apps/meteor/app/api/server/definition.ts @@ -55,10 +55,10 @@ export type ForbiddenResult = { }; }; -export type InternalError = { +export type InternalError = { statusCode: StatusCode; body: { - error: T | 'Internal server error'; + error: T | D; success: false; }; }; @@ -311,7 +311,8 @@ type Results = { headers?: Record; }; -export type TypedAction = ( - this: TypedThis, - request: Request, -) => PromiseOrValue>; +export type TypedAction< + TOptions extends TypedOptions, + TPath extends string = '', + TThis extends TypedThis = TypedThis, +> = (this: TThis, request: Request) => PromiseOrValue>;