diff --git a/src/app.ts b/src/app.ts index cddf5ce..24ed5cd 100644 --- a/src/app.ts +++ b/src/app.ts @@ -12,7 +12,7 @@ const swaggerUI = require('swagger-ui-express'); var cors = require('cors'); require('dotenv').config() -const swaggerOptions = { +const swaggerDefinition = { definition: { openapi: '3.0.0', info: { @@ -22,10 +22,19 @@ const swaggerOptions = { servers: ['http://localhost:4005'] }, }, - apis: ['./src/routers/community.router.ts', './src/routers/skillWallet.router.ts'], }; - -const swagger = swaggerJSDoc(swaggerOptions); +const optionsV1 = { + swaggerDefinition, + apis: ['./src/routers/public.router.ts'] +}; +const optionsV2 = { + swaggerDefinition, + apis: ['./src/routers/private.router.ts'] +}; +const swaggerSpecV1 = swaggerJSDoc(optionsV1); +const swaggerSpecV2 = swaggerJSDoc(optionsV2); +const swaggerHtmlV1 = swaggerUI.generateHTML(swaggerSpecV1, optionsV1) +const swaggerHtmlV2 = swaggerUI.generateHTML(swaggerSpecV2, optionsV2) @injectable() export class App { @@ -68,6 +77,9 @@ export class App { private _initRoutes() { this._app.use("/api/skillWallet", this.skillWalletRouter.router); this._app.use("/api/community", this.communityRouter.router); - this._app.use("/api/docs", swaggerUI.serve, swaggerUI.setup(swagger)); + this._app.use('/api/docs', swaggerUI.serveFiles(swaggerSpecV1, optionsV1)); + this._app.get('/api/docs', (req, res) => { req; res.send(swaggerHtmlV1) }); + this._app.use('/api/docs-private', swaggerUI.serveFiles(swaggerSpecV2, optionsV2)); + this._app.get('/api/docs-private', (req, res) => { req; res.send(swaggerHtmlV2) }); } } \ No newline at end of file diff --git a/src/routers/private.router.ts b/src/routers/private.router.ts new file mode 100644 index 0000000..151e9ea --- /dev/null +++ b/src/routers/private.router.ts @@ -0,0 +1,399 @@ +import { injectable } from "inversify"; +import { Router } from "express"; +import { CommunityController, SkillWalletController } from "../controllers"; +@injectable() +export class PublicRouter { + private readonly _router: Router; + + constructor(private skillWalletController: SkillWalletController, private communityController: CommunityController) { + this._router = Router({ strict: true }); + this.init(); + } + + private init(): void { + // Activation & Validation + /** + * @swagger + * /api/skillWallet/{skillWalletId}/activate: + * post: + * name: SkillWallet + * description: Activates SkillWallet. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: body + * name: payload + * schema: + * type: object + * required: + * - signature + * properties: + * signature: + * type: string + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.post("/:skillWalletId/activate", this.skillWalletController.activateSkillWallet); + /** + * @swagger + * /api/skillWallet/{skillWalletId}/pubKey: + * post: + * description: Adds public key to SkillWallet. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: body + * name: payload + * schema: + * type: object + * required: + * - pubKey + * properties: + * pubKey: + * type: string + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.post("/:skillWalletId/pubKey", this.skillWalletController.addPubKeyToSkillWallet); + /** + * @swagger + * /api/skillWallet/{skillWalletId}/validate: + * post: + * description: Requests SkillWallet validation. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: body + * name: payload + * schema: + * type: object + * required: + * - signature + * - action + * properties: + * signature: + * type: string + * action: + * type: string + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.post("/:skillWalletId/validate", this.skillWalletController.validate); + + // GET + + /** + * @swagger + * /api/skillWallet/{skillWalletId}/interactions: + * get: + * description: Gets interaction NFTs. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/:skillWalletId/interactions", this.skillWalletController.getInteractions); + /** + * @swagger + * /api/skillWallet/{skillWalletId}/events: + * get: + * description: Gets SkillWallet events. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/:skillWalletId/events", this.skillWalletController.getEvents); + /** + * @swagger + * /api/skillWallet/{skillWalletId}/tasks: + * get: + * description: Gets SkillWallet tasks. + * parameters: + * - in: query + * name: activitiesAddress + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/:skillWalletId/tasks", this.skillWalletController.getTasks); + /** + * @swagger + * /api/skillWallet/{skillWalletId}/tasks/{taskId}: + * get: + * description: Gets task by id. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: path + * name: taskId + * schema: + * type: string + * required: true + * - in: query + * name: activitiesAddress + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/:skillWalletId/tasks/:taskId", this.skillWalletController.getTaskById); + /** + * @swagger + * /api/skillWallet/{skillWalletId}/badges: + * get: + * description: Gets SkillWallet badges. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/:skillWalletId/badges", this.skillWalletController.getBadges); + /** + * @swagger + * /api/skillWallet/{skillWalletId}/community/{communityAddress}/membershipID: + * get: + * description: Gets membership details. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: path + * name: communityAddress + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/:skillWalletId/community/:communityAddress/membershipID", this.skillWalletController.getMembershipID); + + // Nonces + /** + * @swagger + * /api/skillWallet/{skillWalletId}/nonces: + * get: + * description: Gets nonces for validation. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: query + * name: action + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/:skillWalletId/nonces", this.skillWalletController.getNonceForValidation); + /** + * @swagger + * /api/skillWallet/{skillWalletId}/nonces: + * delete: + * description: Invalidates nonce. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: query + * name: nonce + * schema: + * type: string + * required: true + * - in: query + * name: action + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.delete("/:skillWalletId/nonces", this.skillWalletController.deleteNonce); + /** + * @swagger + * /api/skillWallet/{skillWalletId}/nonces: + * post: + * description: Generates nonce. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: query + * name: action + * schema: + * type: number + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.post('/:skillWalletId/nonces', this.skillWalletController.generateNonce); + + // Config + + /** + * @swagger + * /api/skillWallet/access: + * post: + * description: Authenticates Partner App. + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.post("/access", this.skillWalletController.authenticatePartnersApp); + + /** + * @swagger + * /api/community/{communityAddress}/key: + * get: + * description: Gets Partner Agreement by community. + * parameters: + * - in: path + * name: communityAddress + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/:communityAddress/key", this.communityController.getPAByCommunity); + + // POST + + /** + * @swagger + * /api/community/{communityAddress}/coreTeamMembers: + * post: + * description: Inserts core team member. + * parameters: + * - in: path + * name: communityAddress + * schema: + * type: string + * required: true + * - in: body + * name: payload + * schema: + * type: object + * required: + * - memberAddress + * - memberName + * properties: + * memberAddress: + * type: string + * memberName: + * type: string + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.post('/:communityAddress/coreTeamMembers', this.communityController.insertCoreTeamMemberName); + /** + * @swagger + * /api/community/key: + * post: + * description: Posts Partner Agreement. + * parameters: + * - in: body + * name: payload + * schema: + * type: object + * required: + * - partnersAgreementAddress + * - communityAddress + * properties: + * partnersAgreementAddress: + * type: string + * communityAddress: + * type: string + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.post("/key", this.communityController.postPartnerAgreement) + } + + public get router(): Router { + return this._router; + } +} diff --git a/src/routers/public.router.ts b/src/routers/public.router.ts new file mode 100644 index 0000000..3f21871 --- /dev/null +++ b/src/routers/public.router.ts @@ -0,0 +1,132 @@ +import { injectable } from "inversify"; +import { Router } from "express"; +import { CommunityController, SkillWalletController } from "../controllers"; +@injectable() +export class PublicRouter { + private readonly _router: Router; + + constructor(private skillWalletController: SkillWalletController, private communityController: CommunityController) { + this._router = Router({ strict: true }); + this.init(); + } + + private init(): void { + + /** + * @swagger + * /api/skillWallet: + * get: + * description: Gets SkillWallet. + * parameters: + * - in: query + * name: tokenId + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get('/', this.skillWalletController.get); + + /** + * @swagger + * /api/skillWallet/{skillWalletId}/isActive: + * get: + * description: Checks wether SkillWallet is active. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/:skillWalletId/isActive", this.skillWalletController.isActive); + + /** + * @swagger + * /api/skillWallet/config: + * get: + * description: Gets SkillWallet config. + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/config", this.skillWalletController.getConfig); + + /** + * @swagger + * /api/community/{communityAddress}/skillwallet: + * get: + * description: Gets SkillWallets per community. + * parameters: + * - in: path + * name: communityAddress + * schema: + * type: string + * required: true + * - in: query + * name: coreTeamMembers + * schema: + * type: boolean + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get('/:communityAddress/skillwallet', this.communityController.get); + + /** + * @swagger + * /api/community/{communityAddress}/coreTeamMembers: + * get: + * description: Gets core team members' names. + * parameters: + * - in: path + * name: communityAddress + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get('/:communityAddress/coreTeamMembers', this.communityController.getCoreTeamMemberNames); + + /** + * @swagger + * /api/community/key/{key}: + * get: + * description: Gets community by Partner Agreement key. + * parameters: + * - in: path + * name: key + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ + this._router.get("/key/:key", this.communityController.getCommunityByPartnerAgreementKey); + } + + public get router(): Router { + return this._router; + } +} diff --git a/src/routers/skillWallet.router.ts b/src/routers/skillWallet.router.ts index 90bdd3e..6d3d9da 100644 --- a/src/routers/skillWallet.router.ts +++ b/src/routers/skillWallet.router.ts @@ -12,77 +12,77 @@ export class SkillWalletRouter { private init(): void { // Activation & Validation - // /** - // * @swagger - // * /api/skillWallet/{skillWalletId}/activate: - // * post: - // * description: Activates SkillWallet. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * requestBody: - // * content: - // * application/json: - // * schema: - // * type: - // * object - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/{skillWalletId}/activate: + * post: + * description: Activates SkillWallet. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * requestBody: + * content: + * application/json: + * schema: + * type: + * object + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.post("/:skillWalletId/activate", this.skillWalletController.activateSkillWallet); - // /** - // * @swagger - // * /api/skillWallet/{skillWalletId}/pubKey: - // * post: - // * description: Adds public key to SkillWallet. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * requestBody: - // * content: - // * application/json: - // * schema: - // * type: - // * object - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/{skillWalletId}/pubKey: + * post: + * description: Adds public key to SkillWallet. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * requestBody: + * content: + * application/json: + * schema: + * type: + * object + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.post("/:skillWalletId/pubKey", this.skillWalletController.addPubKeyToSkillWallet); - // /** - // * @swagger - // * /api/skillWallet/{skillWalletId}/validate: - // * post: - // * description: Requests SkillWallet validation. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * requestBody: - // * content: - // * application/json: - // * schema: - // * type: - // * object - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/{skillWalletId}/validate: + * post: + * description: Requests SkillWallet validation. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * requestBody: + * content: + * application/json: + * schema: + * type: + * object + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.post("/:skillWalletId/validate", this.skillWalletController.validate); /** * @swagger @@ -95,11 +95,11 @@ export class SkillWalletRouter { * schema: * type: string * required: true - * responses: - * 200: - * description: Success - * 500: - * description: Something went wrong, please try again later. + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. */ this._router.get("/:skillWalletId/isActive", this.skillWalletController.isActive); @@ -115,48 +115,48 @@ export class SkillWalletRouter { * schema: * type: string * required: true - * responses: - * 200: - * description: Success - * 500: - * description: Something went wrong, please try again later. + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. */ this._router.get('/', this.skillWalletController.get); - // /** - // * @swagger - // * /api/skillWallet/{skillWalletId}/interactions: - // * get: - // * description: Gets interaction NFTs. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/{skillWalletId}/interactions: + * get: + * description: Gets interaction NFTs. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.get("/:skillWalletId/interactions", this.skillWalletController.getInteractions); - // /** - // * @swagger - // * /api/skillWallet/{skillWalletId}/events: - // * get: - // * description: Gets SkillWallet events. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/{skillWalletId}/events: + * get: + * description: Gets SkillWallet events. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.get("/:skillWalletId/events", this.skillWalletController.getEvents); /** * @swagger @@ -169,11 +169,11 @@ export class SkillWalletRouter { * schema: * type: string * required: true - * responses: - * 200: - * description: Success - * 500: - * description: Something went wrong, please try again later. + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. */ this._router.get("/:skillWalletId/tasks", this.skillWalletController.getTasks); /** @@ -192,129 +192,129 @@ export class SkillWalletRouter { * schema: * type: string * required: true - * responses: - * 200: - * description: Success - * 500: - * description: Something went wrong, please try again later. + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. */ this._router.get("/:skillWalletId/tasks/:taskId", this.skillWalletController.getTaskById); - // /** - // * @swagger - // * /api/skillWallet/{skillWalletId}/badges: - // * get: - // * description: Gets SkillWallet badges. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/{skillWalletId}/badges: + * get: + * description: Gets SkillWallet badges. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.get("/:skillWalletId/badges", this.skillWalletController.getBadges); - // /** - // * @swagger - // * /api/skillWallet/{skillWalletId}/community/{communityAddress}/membershipID: - // * get: - // * description: Gets membership details. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * - in: path - // * name: communityAddress - // * schema: - // * type: string - // * required: true - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/{skillWalletId}/community/{communityAddress}/membershipID: + * get: + * description: Gets membership details. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: path + * name: communityAddress + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.get("/:skillWalletId/community/:communityAddress/membershipID", this.skillWalletController.getMembershipID); // Nonces - // /** - // * @swagger - // * /api/skillWallet/{skillWalletId}/nonces: - // * get: - // * description: Gets nonces for validation. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * - in: query - // * name: action - // * schema: - // * type: string - // * required: true - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/{skillWalletId}/nonces: + * get: + * description: Gets nonces for validation. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: query + * name: action + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.get("/:skillWalletId/nonces", this.skillWalletController.getNonceForValidation); - // /** - // * @swagger - // * /api/skillWallet/{skillWalletId}/nonces: - // * delete: - // * description: Invalidates nonce. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * - in: query - // * name: nonce - // * schema: - // * type: string - // * required: true - // * - in: query - // * name: action - // * schema: - // * type: string - // * required: true - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/{skillWalletId}/nonces: + * delete: + * description: Invalidates nonce. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: query + * name: nonce + * schema: + * type: string + * required: true + * - in: query + * name: action + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.delete("/:skillWalletId/nonces", this.skillWalletController.deleteNonce); - // /** - // * @swagger - // * /api/skillWallet/nonces: - // * post: - // * description: Generates nonce. - // * parameters: - // * - in: path - // * name: skillWalletId - // * schema: - // * type: string - // * required: true - // * - in: query - // * name: action - // * schema: - // * type: string - // * required: true - // * responses: - // * 200: - // * description: Success - // * 500: - // * description: Something went wrong, please try again later. - // */ + /** + * @swagger + * /api/skillWallet/nonces: + * post: + * description: Generates nonce. + * parameters: + * - in: path + * name: skillWalletId + * schema: + * type: string + * required: true + * - in: query + * name: action + * schema: + * type: string + * required: true + * responses: + * 200: + * description: Success + * 500: + * description: Something went wrong, please try again later. + */ this._router.post('/:skillWalletId/nonces', this.skillWalletController.generateNonce); // Config