Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<p align="center"><a href="https://tryintent.com" target="_blank"><img src="https://intent-assets.s3.ap-south-1.amazonaws.com/intent-banner.png" width="400"></a></p>

[![](https://img.shields.io/badge/site-tryintent.com-98d422?logo=data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6AQMAAACyIsh+AAAACXBIWXMAAAdiAAAHYgE4epnbAAAABlBMVEWW1haU1hO0Wf1AAAAAAnRSTlP5Al3j9uAAAASYaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8P3hwYWNrZXQgYmVnaW49J++7vycgaWQ9J1c1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCc/Pgo8eDp4bXBtZXRhIHhtbG5zOng9J2Fkb2JlOm5zOm1ldGEvJz4KPHJkZjpSREYgeG1sbnM6cmRmPSdodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjJz4KCiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0nJwogIHhtbG5zOkF0dHJpYj0naHR0cDovL25zLmF0dHJpYnV0aW9uLmNvbS9hZHMvMS4wLyc+CiAgPEF0dHJpYjpBZHM+CiAgIDxyZGY6U2VxPgogICAgPHJkZjpsaSByZGY6cGFyc2VUeXBlPSdSZXNvdXJjZSc+CiAgICAgPEF0dHJpYjpDcmVhdGVkPjIwMjUtMDEtMDU8L0F0dHJpYjpDcmVhdGVkPgogICAgIDxBdHRyaWI6RXh0SWQ+Y2FiYjgwNjUtOTRlMi00MWIwLWI5Y2MtYWUzMzE0N2I3YTMzPC9BdHRyaWI6RXh0SWQ+CiAgICAgPEF0dHJpYjpGYklkPjUyNTI2NTkxNDE3OTU4MDw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uG5IXM0bQAlSieij8F0JXopT06MWq2PDjIaUfVYVc/RIhsBjuRw61LlKhq3gOdsjWMLqsD7p7VlEmn6i4cbtCtBVbTXFig3ABS+8N/TakWMGF8retXW+wF/MasWyRTLsKUdRv7st4Avpbk9L+upq1tFnaCBoh0Hy7SvTZlc6KkmNnHaQQkJ30PVmqz6Q5ws6zkgm+K/5P3vGcVoGkfMm1lOvhog/umhYGk+BXTb2tamKvueT4hrrZLWrRMMrVdEtpLWmSxjVhNCpEvzrbXmxvJq2kGD91cgPHY9puuUdWahhSL2agEkqalTdzWiMTSNMW455X0d/V993Krk7ZrzOlzVRfb1p72fBYXWnHgpq49sGDWygvc94sEegyAjaSNTfetRiQBZ8IfY5EkWu20l1mSFT57oea04mov9eRWGW3FokvrgSO56TYK70CwAsnLCLb7SDS7+w9WdlMuTEPhTrngh9KfcmEZiof1EOvFw7sqhnkoP/J9phWGgQTKst5IAk0qp4YiKjXtvz3KsFbIXX8iBX8Ukz/K0XkkFT9J4tvPRPWPsvxHYb868eMfFz7+PKGEngcgdwZGP7JMb3+mOZr339+zvsAX+BHwHzCG3z9YaHJQAAAAAElFTkSuQmCC)](https://tryintent.com) [![](https://img.shields.io/badge/docs-98d422?)](https://tryintent.com/docs) <a target="_blank" href="https://discord.gg/5ambDUN7Ge"><img src="https://dcbadge.limes.pink/api/server/5ambDUN7Ge?style=flat" alt="discord community" /></a>

## Introduction

Intent is a web application framework built on top of NestJS. It _intends_ to provide declarative APIs to develop and ship sophisticated solutions. While NestJS provides great syntax and structure to your application, it lacks many things that are needed to develop a good solution.
Expand All @@ -22,6 +24,11 @@ Intent provides necessary feature-integrations out of the box.
- [Localization](https://tryintent.com/docs/localization)
- [Console Commands](https://tryintent.com/docs/console)

## Contributors
<a href="https://github.com/intentjs/intent/graphs/contributors">
<img src="https://contrib.rocks/image?repo=intentjs/intent" />
</a>

## Contact Us

If you would like to support our work or just a few words of feedback, we are all ears at hi@tryintent.com.
Expand Down
3 changes: 3 additions & 0 deletions integrations/sample-app/app/boot/sp/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { IntentApplicationContext, ServiceProvider } from '@intentjs/core';
import { OrderPlacedListener } from 'app/events/listeners/sample-listener';
import { IntentController } from 'app/http/controllers/icon';
import { QueueJobs } from 'app/jobs/job';
import { UserDbRepository } from 'app/repositories/userDbRepository';
Expand Down Expand Up @@ -27,6 +28,8 @@ export class AppServiceProvider extends ServiceProvider {
this.bindWithClass('USER_DB_REPO', UserDbRepository);

this.bind(QueueJobs);

this.bind(OrderPlacedListener);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions integrations/sample-app/app/events/events/sample-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { EmitsEvent, Event } from '@intentjs/core';

@Event('order_placed')
export class OrderPlacedEvent extends EmitsEvent {
constructor(public order: Record<string, any>) {
super();
}
}
10 changes: 10 additions & 0 deletions integrations/sample-app/app/events/listeners/sample-listener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Injectable, ListensTo } from '@intentjs/core';

@Injectable()
export class OrderPlacedListener {
@ListensTo('order_placed')
async handle(data: Record<string, any>): Promise<void> {
console.log('data ==> ', data);
// write your code here...
}
}
10 changes: 7 additions & 3 deletions integrations/sample-app/app/http/controllers/app.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { Controller, Get, Req } from '@intentjs/core';
import { OrderPlacedEvent } from 'app/events/events/sample-event';
import { UserService } from 'app/services';

@Controller()
export class UserController {
constructor(private readonly service: UserService) {}

@Get()
@Get('/')
async getHello(@Req() req: Request) {
return { hello: 'Intent' };
}

@Get('hello')
@Get('hello/')
async getHello2(@Req() req: Request) {
return { hello: 'Intent' };
const order = { id: 123, product: 'A book' };
const event = new OrderPlacedEvent(order);
event.emit();
return { hello: 'Intent2' };
}
}
12 changes: 12 additions & 0 deletions packages/core/lib/exceptions/base-exception-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HttpException } from './http-exception';
import { ValidationFailed } from './validation-failed';
import { HttpStatus } from '../rest/http-server/status-codes';
import { ExecutionContext } from '../rest/http-server/contexts/execution-context';
import { RouteNotFoundException } from './route-not-found-exception';

export abstract class IntentExceptionFilter {
doNotReport(): Array<Type<HttpException>> {
Expand All @@ -28,9 +29,20 @@ export abstract class IntentExceptionFilter {

async handleHttp(context: ExecutionContext, exception: any): Promise<any> {
const res = context.switchToHttp().getResponse();
const req = context.switchToHttp().getRequest();

const debugMode = ConfigService.get('app.debug');

if (exception instanceof RouteNotFoundException) {
if (req.expectsJson()) {
return res.status(HttpStatus.NOT_FOUND).json({
message: exception.message,
status: exception.getStatus(),
// stack: debugMode && exception.stack,
});
}
}

if (exception instanceof ValidationFailed) {
return res.status(HttpStatus.UNPROCESSABLE_ENTITY).json({
message: 'validation failed',
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/exceptions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './invalid-value-type';
export * from './http-exception';
export * from './forbidden-exception';
export * from './file-not-found-exception';
export * from './route-not-found-exception';
8 changes: 8 additions & 0 deletions packages/core/lib/exceptions/route-not-found-exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { HttpStatus } from '../rest/http-server/status-codes';
import { HttpException } from './http-exception';

export class RouteNotFoundException extends HttpException {
constructor(response: string | Record<string, any>) {
super(response, HttpStatus.NOT_FOUND);
}
}
13 changes: 11 additions & 2 deletions packages/core/lib/rest/foundation/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { HttpExecutionContext } from '../http-server/contexts/http-execution-con
import { ExecutionContext } from '../http-server/contexts/execution-context';
import { Response } from '../http-server/response';
import { RouteExplorer } from '../http-server/route-explorer';
import { RouteNotFoundException } from '../../exceptions/route-not-found-exception';

const signals = ['SIGTERM', 'SIGINT', 'SIGUSR2'];

Expand Down Expand Up @@ -98,12 +99,20 @@ export class IntentHttpServer {

await this.container.boot(app);
await this.kernel.boot(server);

server.set_not_found_handler((hReq: any, hRes: HyperResponse) => {
const httpContext = new HttpExecutionContext(hReq, hRes);
const context = new ExecutionContext(httpContext, null, null);
const routeNotFoundError = new RouteNotFoundException(
`[${hReq.method}] ${hReq.url} is not a valid route.`,
);
errorHandler.catch(context, routeNotFoundError);
});

server.set_error_handler((hReq: any, hRes: HyperResponse, error: Error) => {
const res = new Response();
const httpContext = new HttpExecutionContext(hReq, hRes);
const context = new ExecutionContext(httpContext, null, null);
errorHandler.catch(context, error);
res.reply(hReq, hRes);
});

this.configureErrorReporter(config.get('app.sentry'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ class ExpressRequest {
return this.get(name);
}

accepts() {
let instance = accepts(this);
return instance.types.apply(instance, arguments);
}

acceptsCharsets() {
charsets = flattened(charsets, arguments);

Expand Down
2 changes: 1 addition & 1 deletion packages/hyper-express/src/components/http/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ class Request {
}

expectsJson() {
return this.accepts().includes('application/json');
return this.accepts().includes('application/json') || this.accepts().includes('*/*');
}

setUser(user) {
Expand Down
3 changes: 2 additions & 1 deletion packages/hyper-express/types/components/http/Response.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Response<Locals = DefaultResponseLocals> extends Writable {
value: string | null,
expiry?: number,
options?: CookieOptions,
sign_cookie?: boolean
sign_cookie?: boolean,
): Response;

/**
Expand Down Expand Up @@ -264,6 +264,7 @@ export class Response<Locals = DefaultResponseLocals> extends Writable {
sendStatus(status_code: number): Response;
set(field: string | object, value?: string | Array<string>): Response | void;
vary(name: string): Response;
notFound(): Response;

/* ExpressJS Properties */
get headersSent(): boolean;
Expand Down
Loading