unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
72 lines • 3.05 kB
JavaScript
import Controller from './controller.js';
import { NONE } from '../types/permissions.js';
import { createRequestSchema } from '../openapi/util/create-request-schema.js';
import { createResponseSchema } from '../openapi/util/create-response-schema.js';
import { serializeDates } from '../types/serialize-dates.js';
import { emptyResponse, getStandardResponses, } from '../openapi/util/standard-responses.js';
import { userSchema } from '../openapi/spec/user-schema.js';
export class PublicInviteController extends Controller {
constructor(config, { publicSignupTokenService, openApiService, }) {
super(config);
this.publicSignupTokenService = publicSignupTokenService;
this.openApiService = openApiService;
this.route({
method: 'get',
path: '/:token/validate',
handler: this.validate,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Public signup tokens'],
operationId: 'validatePublicSignupToken',
summary: `Validate signup token`,
description: `Check whether the provided public sign-up token exists, has not expired and is enabled`,
responses: {
200: emptyResponse,
...getStandardResponses(400),
},
}),
],
});
this.route({
method: 'post',
path: '/:token/signup',
handler: this.addTokenUser,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Public signup tokens'],
operationId: 'addPublicSignupTokenUser',
summary: 'Add a user via a signup token',
description: 'Create a user with the viewer root role and link them to the provided signup token',
requestBody: createRequestSchema('createInvitedUserSchema'),
responses: {
200: createResponseSchema('userSchema'),
...getStandardResponses(400, 409),
},
}),
],
});
}
async validate(req, res) {
const { token } = req.params;
const valid = await this.publicSignupTokenService.validate(token);
if (valid) {
res.status(200).end();
}
else {
res.status(400).end();
}
}
async addTokenUser(req, res) {
const { token } = req.params;
const valid = await this.publicSignupTokenService.validate(token);
if (!valid) {
res.status(400).end();
return;
}
const { isAPI, ...user } = await this.publicSignupTokenService.addTokenUser(token, req.body, req.audit);
this.openApiService.respondWithValidation(201, res, userSchema.$id, serializeDates(user));
}
}
//# sourceMappingURL=public-invite.js.map