feat: initial commit

This commit is contained in:
Mohamed Marrouchi
2024-09-10 10:50:11 +01:00
commit 30e5766487
879 changed files with 122820 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { SocketEventMetadataStorage } from '../storage/socket-event-metadata.storage';
export const SocketGet = (path: string): MethodDecorator => {
return (
target: object,
propertyKey: string | symbol,
descriptor: PropertyDescriptor,
) => {
SocketEventMetadataStorage.addEventMetadata(target, propertyKey, {
socketMethod: 'get',
path,
method: descriptor.value,
});
};
};
export const SocketPost = (path: string): MethodDecorator => {
return (
target: object,
propertyKey: string | symbol,
descriptor: PropertyDescriptor,
) => {
SocketEventMetadataStorage.addEventMetadata(target, propertyKey, {
socketMethod: 'post',
path,
method: descriptor.value,
});
};
};
export const SocketPut = (path: string): MethodDecorator => {
return (
target: object,
propertyKey: string | symbol,
descriptor: PropertyDescriptor,
) => {
SocketEventMetadataStorage.addEventMetadata(target, propertyKey, {
socketMethod: 'put',
path,
method: descriptor.value,
});
};
};
export const SocketPatch = (path: string): MethodDecorator => {
return (
target: object,
propertyKey: string | symbol,
descriptor: PropertyDescriptor,
) => {
SocketEventMetadataStorage.addEventMetadata(target, propertyKey, {
socketMethod: 'patch',
path,
method: descriptor.value,
});
};
};
export const SocketDelete = (path: string): MethodDecorator => {
return (
target: object,
propertyKey: string | symbol,
descriptor: PropertyDescriptor,
) => {
SocketEventMetadataStorage.addEventMetadata(target, propertyKey, {
socketMethod: 'delete',
path,
method: descriptor.value,
});
};
};
export const SocketOptions = (path: string): MethodDecorator => {
return (
target: object,
propertyKey: string | symbol,
descriptor: PropertyDescriptor,
) => {
SocketEventMetadataStorage.addEventMetadata(target, propertyKey, {
socketMethod: 'options',
path,
method: descriptor.value,
});
};
};
export const SocketHead = (path: string): MethodDecorator => {
return (
target: object,
propertyKey: string | symbol,
descriptor: PropertyDescriptor,
) => {
SocketEventMetadataStorage.addEventMetadata(target, propertyKey, {
socketMethod: 'head',
path,
method: descriptor.value,
});
};
};

View File

@@ -0,0 +1,17 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
export const SocketReq = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const client = ctx.switchToWs().getClient<any>();
return client.request; // Assuming `request` is attached to the client object
},
);

View File

@@ -0,0 +1,17 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
export const SocketRes = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const client = ctx.switchToWs().getClient<any>();
return client.response; // Assuming `response` is attached to the client object
},
);

View File

@@ -0,0 +1,32 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
import {
Catch,
ArgumentsHost,
ExceptionFilter,
NotFoundException,
} from '@nestjs/common';
import { SocketResponse } from '../utils/socket-response';
@Catch()
export class WebSocketExceptionsFilter implements ExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
const ctx = host.switchToWs();
const client = ctx.getClient<any>();
const response = new SocketResponse(client);
if (exception instanceof NotFoundException) {
response.status(404).json({ error: 'Not Found' });
} else {
response.status(500).json({ error: 'Internal Server Error' });
}
}
}