A progressive Node.js framework for building efficient and scalable server-side applications.
+ + + +## Description + +[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. + +## Installation + +```bash +$ pnpm install +``` + +## Running the app + +```bash +# development +$ pnpm run start + +# watch mode +$ pnpm run start:dev + +# production mode +$ pnpm run start:prod +``` + +## Test + +```bash +# unit tests +$ pnpm run test + +# e2e tests +$ pnpm run test:e2e + +# test coverage +$ pnpm run test:cov +``` + +## Support + +Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). + +## Stay in touch + +- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) +- Website - [https://nestjs.com](https://nestjs.com/) +- Twitter - [@nestframework](https://twitter.com/nestframework) + +## License + +Nest is [MIT licensed](LICENSE). diff --git a/examples/nestjs-example/nest-cli.json b/examples/nestjs-example/nest-cli.json new file mode 100644 index 0000000000..f9aa683b1a --- /dev/null +++ b/examples/nestjs-example/nest-cli.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src", + "compilerOptions": { + "deleteOutDir": true + } +} diff --git a/examples/nestjs-example/package.json b/examples/nestjs-example/package.json new file mode 100644 index 0000000000..78769c86ea --- /dev/null +++ b/examples/nestjs-example/package.json @@ -0,0 +1,72 @@ +{ + "name": "nestjs-example", + "version": "0.0.1", + "description": "", + "author": "", + "private": true, + "license": "UNLICENSED", + "scripts": { + "build": "nest build", + "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "start": "nest start", + "start:dev": "nest start --watch", + "start:debug": "nest start --debug --watch", + "start:prod": "node dist/main", + "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "test": "jest", + "test:watch": "jest --watch", + "test:cov": "jest --coverage", + "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", + "test:e2e": "jest --config ./test/jest-e2e.json" + }, + "dependencies": { + "@nestjs/common": "^10.0.0", + "@nestjs/core": "^10.0.0", + "@nestjs/config": "^3.0.1", + "@nestjs/platform-express": "^10.0.0", + "reflect-metadata": "^0.1.13", + "@trigger.dev/sdk": "workspace:*", + "@trigger.dev/nestjs": "workspace:*", + "rxjs": "^7.8.1" + }, + "devDependencies": { + "@nestjs/cli": "^10.0.0", + "@nestjs/schematics": "^10.0.0", + "@nestjs/testing": "^10.0.0", + "@types/express": "^4.17.17", + "@types/jest": "^29.5.2", + "@types/node": "^20.3.1", + "@types/supertest": "^2.0.12", + "@typescript-eslint/eslint-plugin": "^6.0.0", + "@typescript-eslint/parser": "^6.0.0", + "eslint": "^8.42.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-prettier": "^5.0.0", + "jest": "^29.5.0", + "prettier": "^3.0.0", + "source-map-support": "^0.5.21", + "supertest": "^6.3.3", + "ts-jest": "^29.1.0", + "ts-loader": "^9.4.3", + "ts-node": "^10.9.1", + "tsconfig-paths": "^4.2.0", + "typescript": "^5.1.3" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "json", + "ts" + ], + "rootDir": "src", + "testRegex": ".*\\.spec\\.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "collectCoverageFrom": [ + "**/*.(t|j)s" + ], + "coverageDirectory": "../coverage", + "testEnvironment": "node" + } +} diff --git a/examples/nestjs-example/src/app.controller.ts b/examples/nestjs-example/src/app.controller.ts new file mode 100644 index 0000000000..e6383b5309 --- /dev/null +++ b/examples/nestjs-example/src/app.controller.ts @@ -0,0 +1,31 @@ +import { Controller, Get } from '@nestjs/common'; +import { InjectTriggerDevClient } from '@trigger.dev/nestjs'; +import { eventTrigger, TriggerClient } from '@trigger.dev/sdk'; + +@Controller() +export class AppController { + constructor( + @InjectTriggerDevClient() private readonly client: TriggerClient, + ) { + this.client.defineJob({ + id: 'test-job', + name: 'Test Job One', + version: '0.0.1', + trigger: eventTrigger({ + name: 'test.event', + }), + run: async (payload, io, ctx) => { + await io.logger.info('Hello world!', { payload }); + + return { + message: 'Hello world!', + }; + }, + }); + } + + @Get() + getHello(): string { + return `Running Trigger.dev with client-id ${ this.client.id }`; + } +} diff --git a/examples/nestjs-example/src/app.module.ts b/examples/nestjs-example/src/app.module.ts new file mode 100644 index 0000000000..ad5755575b --- /dev/null +++ b/examples/nestjs-example/src/app.module.ts @@ -0,0 +1,24 @@ +import { Module } from '@nestjs/common'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +import { TriggerDevModule } from '@trigger.dev/nestjs'; +import { AppController } from './app.controller'; + +@Module({ + imports: [ + ConfigModule.forRoot({ + isGlobal: true, + }), + TriggerDevModule.registerAsync({ + inject: [ConfigService], + useFactory: (config: ConfigService) => ({ + id: 'my-nest-app', + apiKey: config.getOrThrow('TRIGGER_API_KEY'), + apiUrl: config.getOrThrow('TRIGGER_API_URL'), + verbose: false, + ioLogLocalEnabled: true, + }), + }), + ], + controllers: [AppController], +}) +export class AppModule {} diff --git a/examples/nestjs-example/src/main.ts b/examples/nestjs-example/src/main.ts new file mode 100644 index 0000000000..13cad38cff --- /dev/null +++ b/examples/nestjs-example/src/main.ts @@ -0,0 +1,8 @@ +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; + +async function bootstrap() { + const app = await NestFactory.create(AppModule); + await app.listen(3000); +} +bootstrap(); diff --git a/examples/nestjs-example/test/app.e2e-spec.ts b/examples/nestjs-example/test/app.e2e-spec.ts new file mode 100644 index 0000000000..50cda62332 --- /dev/null +++ b/examples/nestjs-example/test/app.e2e-spec.ts @@ -0,0 +1,24 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import * as request from 'supertest'; +import { AppModule } from './../src/app.module'; + +describe('AppController (e2e)', () => { + let app: INestApplication; + + beforeEach(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = moduleFixture.createNestApplication(); + await app.init(); + }); + + it('/ (GET)', () => { + return request(app.getHttpServer()) + .get('/') + .expect(200) + .expect('Hello World!'); + }); +}); diff --git a/examples/nestjs-example/test/jest-e2e.json b/examples/nestjs-example/test/jest-e2e.json new file mode 100644 index 0000000000..e9d912f3e3 --- /dev/null +++ b/examples/nestjs-example/test/jest-e2e.json @@ -0,0 +1,9 @@ +{ + "moduleFileExtensions": ["js", "json", "ts"], + "rootDir": ".", + "testEnvironment": "node", + "testRegex": ".e2e-spec.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + } +} diff --git a/examples/nestjs-example/tsconfig.build.json b/examples/nestjs-example/tsconfig.build.json new file mode 100644 index 0000000000..64f86c6bd2 --- /dev/null +++ b/examples/nestjs-example/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] +} diff --git a/examples/nestjs-example/tsconfig.json b/examples/nestjs-example/tsconfig.json new file mode 100644 index 0000000000..95f5641cf7 --- /dev/null +++ b/examples/nestjs-example/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2021", + "sourceMap": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "skipLibCheck": true, + "strictNullChecks": false, + "noImplicitAny": false, + "strictBindCallApply": false, + "forceConsistentCasingInFileNames": false, + "noFallthroughCasesInSwitch": false + } +} diff --git a/packages/nestjs/LICENSE b/packages/nestjs/LICENSE new file mode 100644 index 0000000000..e51e7b10aa --- /dev/null +++ b/packages/nestjs/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Trigger.dev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/nestjs/README.md b/packages/nestjs/README.md new file mode 100644 index 0000000000..f0400f90f8 --- /dev/null +++ b/packages/nestjs/README.md @@ -0,0 +1,7 @@ +# NestJS and Trigger.dev + +Trigger.dev has full support for the NestJS framework. + +For information about the using Trigger.dev in your NestJS app, check out these useful docs links: + +- [Quick start guide for getting setup with Trigger.dev in a NestJS project](https://trigger.dev/docs/documentation/quickstarts/nestjs) diff --git a/packages/nestjs/package.json b/packages/nestjs/package.json new file mode 100644 index 0000000000..741a5ee819 --- /dev/null +++ b/packages/nestjs/package.json @@ -0,0 +1,47 @@ +{ + "name": "@trigger.dev/nestjs", + "version": "1.0.0", + "description": "Official NestJS adapter for Trigger.dev", + "license": "MIT", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "publishConfig": { + "access": "public" + }, + "files": [ + "dist" + ], + "exports": { + ".": { + "import": "./dist/index.js", + "require": "./dist/index.js" + }, + "./package.json": "./package.json" + }, + "devDependencies": { + "@trigger.dev/sdk": "workspace:^2.1.0", + "@trigger.dev/tsconfig": "workspace:*", + "@types/debug": "^4.1.7", + "@types/express": "^4.17.13", + "rimraf": "^3.0.2", + "tsup": "^6.5.0", + "tsx": "^3.12.1" + }, + "scripts": { + "clean": "rimraf dist", + "build": "npm run clean && npm run build:tsup", + "build:tsup": "tsup" + }, + "peerDependencies": { + "@trigger.dev/sdk": "workspace:^2.1.0", + "@nestjs/common": ">=10.0.0" + }, + "dependencies": { + "@remix-run/web-fetch": "^4.3.5", + "debug": "^4.3.4", + "@nestjs/common": "^10.2.4" + }, + "engines": { + "node": ">=16.8.0" + } +} diff --git a/packages/nestjs/src/index.ts b/packages/nestjs/src/index.ts new file mode 100644 index 0000000000..eca1726ce4 --- /dev/null +++ b/packages/nestjs/src/index.ts @@ -0,0 +1,213 @@ +import { Body, ConfigurableModuleBuilder, Controller, Delete, DynamicModule, Get, Head, Headers, HttpCode, Inject, InjectionToken, InternalServerErrorException, Module, NotFoundException, Options, Post, Put, Res } from '@nestjs/common'; +import { Patch, Search } from '@nestjs/common/decorators/http/request-mapping.decorator'; +import { Headers as StandardHeaders, Request as StandardRequest } from '@remix-run/web-fetch'; +import { TriggerClient, TriggerClientOptions } from '@trigger.dev/sdk'; + +const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE } = new ConfigurableModuleBuilder