apps/api/README.md
A RESTful API for accessing the Novu platform, built using NestJS.
See the docs for Run in Local Machine to get setup. Then run:
# Run the API in watch mode
$ npm run start:api
# unit tests
$ npm run test
See the docs for Running on Local Machine - API Tests.
@Get, @Post, @Put, @Delete decorators to define the HTTP method.@Param, @Query, @Body decorators to define the parameters.@RequireAuthentication() decorator to define the guards as well as make it accessible to novu web app.getEntityName, createEntityName, updateEntityName, deleteEntityName.list prefix for the method name and don't forget to add pagination functionality.
@SdkUsePagination decorator to alert the sdk of a paginated endpoint (will improve DX with an async iterator) the pagination parameters.@SdkGroupName - Use this decorator to group the endpoints in the SDK, use . separator to create a subresource (Ex' 'Subscribers.Notifications' getSubscriberNotifications), the original resource is defined as an openApi Tag .@SdkMethodName in case of a unique operation, use this decorator to define the method name in the SDK.The Novu API utilizes the @nestjs/swagger package to generate up-to-date OpenAPI specifications.
A web interface to browse the published endpoints is available during local development at localhost:3000/openapi. An OpenAPI specification can be retrieved at api.novu.co/openapi.yaml.
To maintain consistency and quality of OpenAPI documentation, Novu uses Spectral to validate the OpenAPI specification and enforce style. The OpenAPI specification is run through a Github action on pull request, and call also be run locally after starting the API with:
$ npm run lint:openapi
The command will return warnings and errors that must be fixed before the Github action will pass. These fixes are created by making changes through the @nestjs/swagger decorators.
Database migrations are included for features that have a hard dependency on specific data being available on database entities. These migrations are run by both Novu Cloud and Novu Self-Hosted users to support new feature releases.
The npm run migration script is available in the package.json to ensure script changes are DRY and consistent. This script is included in user-facing communications such as our documentation and release notes, and the script naming therefore MUST remain stable.
The path to the migration to run is passed as a positional argument to the script. For example, to run the Add Integration Identifier script, we would enter the following:
npm run migration -- ./migrations/integration-scheme-update/add-integration-identifier-migration.ts
These migrations live in the ./migrations directory, and follow the naming convention of:
./migrations/<CHANGE_DESCRIPTION>/<CHANGE_ACTION>.ts. Each <CHANGE_DESCRIPTION> may have 1 or more <CHANGE_ACTION>.ts scripts. For example:
.
└── migrations/
└── integration-scheme-update/
├── add-integration-identifier-migration.ts
└── add-primary-priority-migration.ts