mm-share-lib 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -2
- package/src/auth/apple/apple.module.ts +10 -0
- package/src/auth/apple/apple.service.ts +28 -0
- package/src/auth/apple/dto/apple-login.dto.ts +16 -0
- package/src/auth/apple/dto/index.ts +1 -0
- package/src/auth/apple/index.ts +3 -0
- package/src/auth/config/apple.config.ts +18 -0
- package/src/auth/config/auth.config.ts +29 -0
- package/src/auth/config/facebook.config.ts +23 -0
- package/src/auth/config/file.config.ts +50 -0
- package/src/auth/config/google.config.ts +23 -0
- package/src/auth/config/index.ts +6 -0
- package/src/auth/config/twitter.config.ts +22 -0
- package/src/auth/facebook/dto/facebook-login.dto.ts +8 -0
- package/src/auth/facebook/dto/index.ts +1 -0
- package/src/auth/facebook/facebook.module.ts +11 -0
- package/src/auth/facebook/facebook.service.ts +51 -0
- package/src/auth/facebook/index.ts +4 -0
- package/src/auth/facebook/interface/facebook.interface.ts +6 -0
- package/src/auth/facebook/interface/index.ts +1 -0
- package/src/auth/google/dto/google-login.dto.ts +8 -0
- package/src/auth/google/dto/index.ts +1 -0
- package/src/auth/google/google.module.ts +10 -0
- package/src/auth/google/google.service.ts +51 -0
- package/src/auth/google/index.ts +3 -0
- package/src/auth/index.ts +5 -0
- package/src/auth/twitter/dto/index.ts +1 -0
- package/src/auth/twitter/dto/twitter-login.dto.ts +12 -0
- package/src/auth/twitter/index.ts +3 -0
- package/src/auth/twitter/twitter.module.ts +11 -0
- package/src/auth/twitter/twitter.service.ts +43 -0
- package/src/config/index.ts +1 -0
- package/src/config/type.config.ts +88 -0
- package/src/dto/pagination.dto.ts +14 -2
- package/src/exception/bad-request-error.exception.spec.ts +24 -0
- package/src/exception/bad-request-error.exception.ts +8 -0
- package/src/exception/base.exception.ts +36 -0
- package/src/exception/conflict-error.exception.spec.ts +23 -0
- package/src/exception/conflict-error.exception.ts +8 -0
- package/src/exception/forbidden-error.exception.spec.ts +23 -0
- package/src/exception/forbidden-error.exception.ts +8 -0
- package/src/exception/index.ts +7 -0
- package/src/exception/internal-server-error.exception.spec.ts +23 -0
- package/src/exception/internal-server-error.exception.ts +12 -0
- package/src/exception/not-found-error.exception.spec.ts +23 -0
- package/src/exception/not-found-error.exception.ts +8 -0
- package/src/exception/unauthorized-error.exception.spec.ts +23 -0
- package/src/exception/unauthorized-error.exception.ts +12 -0
- package/src/filter/http-exception.filter.ts +23 -0
- package/src/filter/index.ts +1 -0
- package/src/filter/rpc-exception.filter.ts +15 -0
- package/src/index.ts +3 -0
- package/src/interface/index.ts +1 -0
- package/src/interface/social.interface.ts +6 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/mailer/config/index.ts +1 -0
- package/src/lib/mailer/config/mailer.config.ts +62 -0
- package/src/lib/mailer/index.ts +2 -0
- package/src/lib/mailer/mailer.module.ts +8 -0
- package/src/lib/mailer/mailer.service.ts +53 -0
- package/src/lib/redis/index.ts +0 -0
- package/src/lib/search-engine/document/base.document.ts +2 -2
- package/src/lib/search-engine/interface/search-document.interface.ts +10 -2
- package/src/lib/search-engine/schema/generic.schema.ts +1 -1
- package/src/lib/search-engine/schema/index.ts +1 -1
- package/src/lib/search-engine/typesense/collection/index.ts +1 -0
- package/src/lib/search-engine/typesense/document/index.ts +1 -0
- package/src/lib/search-engine/typesense/index.ts +1 -0
- package/src/lib/search-engine/typesense/service/client.service.ts +5 -3
- package/src/lib/storage/index.ts +0 -0
- package/src/lib/typesense/client/index.ts +1 -0
- package/src/lib/typesense/collection/index.ts +1 -0
- package/src/lib/typesense/decorator/field.decorator.spec.ts +89 -0
- package/src/lib/typesense/decorator/field.decorator.ts +44 -0
- package/src/lib/typesense/decorator/index.ts +2 -0
- package/src/lib/typesense/decorator/schema.decorator.ts +23 -0
- package/src/lib/typesense/document/base.document.ts +3 -0
- package/src/lib/typesense/index.ts +6 -0
- package/src/lib/typesense/metadata/index.ts +4 -0
- package/src/lib/typesense/metadata/schema.metadata.ts +21 -0
- package/src/lib/typesense/metadata/typesense.metadata-accessor.ts +37 -0
- package/src/lib/typesense/metadata/typesense.metadata-explorer.spec.ts +56 -0
- package/src/lib/typesense/metadata/typesense.metadata-explorer.ts +41 -0
- package/src/lib/typesense/metadata/typesense.metadata-registry.ts +28 -0
- package/src/lib/typesense/module/index.ts +4 -0
- package/src/lib/typesense/module/interface.module.ts +34 -0
- package/src/lib/typesense/module/typesense.constant.ts +1 -0
- package/src/lib/typesense/module/typesense.module.spec.ts +94 -0
- package/src/lib/typesense/module/typesense.module.ts +87 -0
- package/src/lib/typesense/module/typesense.provider.ts +54 -0
- package/src/response/base-entity.response.ts +8 -0
- package/src/response/index.ts +1 -0
- package/src/response/login.response.ts +0 -0
- package/src/response/pagination.response.ts +23 -8
- package/src/setup/index.ts +1 -0
- package/src/setup/microservice.setup.ts +29 -0
- package/src/setup/swagger.setup.ts +0 -0
- package/src/util/app.utils.ts +18 -0
- package/src/util/index.ts +2 -0
- package/src/util/validate-config.ts +20 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/src/dto/base-filter.dto.d.ts +0 -4
- package/dist/src/dto/base-filter.dto.js +0 -11
- package/dist/src/dto/base-filter.dto.js.map +0 -1
- package/dist/src/dto/index.d.ts +0 -2
- package/dist/src/dto/index.js +0 -19
- package/dist/src/dto/index.js.map +0 -1
- package/dist/src/dto/pagination.dto.d.ts +0 -4
- package/dist/src/dto/pagination.dto.js +0 -11
- package/dist/src/dto/pagination.dto.js.map +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.js +0 -23
- package/dist/src/index.js.map +0 -1
- package/dist/src/lib/index.d.ts +0 -1
- package/dist/src/lib/index.js +0 -18
- package/dist/src/lib/index.js.map +0 -1
- package/dist/src/lib/search-engine/document/base.document.d.ts +0 -3
- package/dist/src/lib/search-engine/document/base.document.js +0 -7
- package/dist/src/lib/search-engine/document/base.document.js.map +0 -1
- package/dist/src/lib/search-engine/document/index.js +0 -18
- package/dist/src/lib/search-engine/document/index.js.map +0 -1
- package/dist/src/lib/search-engine/index.d.ts +0 -1
- package/dist/src/lib/search-engine/index.js +0 -18
- package/dist/src/lib/search-engine/index.js.map +0 -1
- package/dist/src/lib/search-engine/interface/index.d.ts +0 -2
- package/dist/src/lib/search-engine/interface/index.js +0 -19
- package/dist/src/lib/search-engine/interface/index.js.map +0 -1
- package/dist/src/lib/search-engine/interface/search-document.interface.d.ts +0 -4
- package/dist/src/lib/search-engine/interface/search-document.interface.js +0 -3
- package/dist/src/lib/search-engine/interface/search-document.interface.js.map +0 -1
- package/dist/src/lib/search-engine/interface/transform-service.interface.d.ts +0 -6
- package/dist/src/lib/search-engine/interface/transform-service.interface.js +0 -3
- package/dist/src/lib/search-engine/interface/transform-service.interface.js.map +0 -1
- package/dist/src/lib/search-engine/schema/generic.schema.d.ts +0 -2
- package/dist/src/lib/search-engine/schema/generic.schema.js +0 -7
- package/dist/src/lib/search-engine/schema/generic.schema.js.map +0 -1
- package/dist/src/lib/search-engine/schema/index.d.ts +0 -1
- package/dist/src/lib/search-engine/schema/index.js +0 -18
- package/dist/src/lib/search-engine/schema/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/index.d.ts +0 -3
- package/dist/src/lib/search-engine/typesense/index.js +0 -20
- package/dist/src/lib/search-engine/typesense/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/metadata/index.d.ts +0 -2
- package/dist/src/lib/search-engine/typesense/metadata/index.js +0 -19
- package/dist/src/lib/search-engine/typesense/metadata/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.d.ts +0 -12
- package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js +0 -3
- package/dist/src/lib/search-engine/typesense/metadata/schema.metadata.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.d.ts +0 -10
- package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js +0 -33
- package/dist/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/service/client.service.d.ts +0 -33
- package/dist/src/lib/search-engine/typesense/service/client.service.js +0 -197
- package/dist/src/lib/search-engine/typesense/service/client.service.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/service/index.d.ts +0 -1
- package/dist/src/lib/search-engine/typesense/service/index.js +0 -18
- package/dist/src/lib/search-engine/typesense/service/index.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense-module.interface.d.ts +0 -27
- package/dist/src/lib/search-engine/typesense/typesense-module.interface.js +0 -3
- package/dist/src/lib/search-engine/typesense/typesense-module.interface.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.constants.d.ts +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.constants.js +0 -5
- package/dist/src/lib/search-engine/typesense/typesense.constants.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.module.d.ts +0 -8
- package/dist/src/lib/search-engine/typesense/typesense.module.js +0 -68
- package/dist/src/lib/search-engine/typesense/typesense.module.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.module.test.d.ts +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.module.test.js +0 -89
- package/dist/src/lib/search-engine/typesense/typesense.module.test.js.map +0 -1
- package/dist/src/lib/search-engine/typesense/typesense.providers.d.ts +0 -4
- package/dist/src/lib/search-engine/typesense/typesense.providers.js +0 -40
- package/dist/src/lib/search-engine/typesense/typesense.providers.js.map +0 -1
- package/dist/src/response/index.d.ts +0 -1
- package/dist/src/response/index.js +0 -18
- package/dist/src/response/index.js.map +0 -1
- package/dist/src/response/pagination.response.d.ts +0 -17
- package/dist/src/response/pagination.response.js +0 -29
- package/dist/src/response/pagination.response.js.map +0 -1
- package/dist/src/util/date.util.d.ts +0 -2
- package/dist/src/util/date.util.js +0 -14
- package/dist/src/util/date.util.js.map +0 -1
- package/dist/src/util/generator.util.d.ts +0 -4
- package/dist/src/util/generator.util.js +0 -29
- package/dist/src/util/generator.util.js.map +0 -1
- package/dist/src/util/index.d.ts +0 -2
- package/dist/src/util/index.js +0 -19
- package/dist/src/util/index.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- /package/{dist/src/lib/search-engine/document/index.d.ts → src/lib/typesense/document/index.ts} +0 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
import { HttpStatus } from '@nestjs/common';
|
2
|
+
import { BadRequestException } from './bad-request-error.exception';
|
3
|
+
|
4
|
+
describe('BadRequestException', () => {
|
5
|
+
it('should set default message and status code if no parameters are provided', () => {
|
6
|
+
const error = new BadRequestException();
|
7
|
+
|
8
|
+
expect(error.message).toBe('BadRequestException');
|
9
|
+
expect(error.statusCode).toBe(HttpStatus.BAD_REQUEST);
|
10
|
+
expect(error.parameters).toBeUndefined();
|
11
|
+
});
|
12
|
+
|
13
|
+
it('should set custom message, status code, and parameters if provided', () => {
|
14
|
+
const customMessage = 'Custom message';
|
15
|
+
const customStatusCode = HttpStatus.BAD_REQUEST;
|
16
|
+
const customParameters = { key: 'value' };
|
17
|
+
const error = new BadRequestException(customMessage, customParameters);
|
18
|
+
|
19
|
+
expect(error.message).toBe(customMessage);
|
20
|
+
expect(error.statusCode).toBe(customStatusCode);
|
21
|
+
expect(error.parameters).toEqual(customParameters);
|
22
|
+
console.log(error);
|
23
|
+
});
|
24
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { HttpStatus } from '@nestjs/common';
|
2
|
+
import { BaseException, ParametersType } from './base.exception';
|
3
|
+
|
4
|
+
export class BadRequestException extends BaseException {
|
5
|
+
constructor(message?: string, parameters?: ParametersType) {
|
6
|
+
super(message ?? 'BadRequestException', HttpStatus.BAD_REQUEST, parameters);
|
7
|
+
}
|
8
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { HttpException, HttpStatus } from '@nestjs/common';
|
2
|
+
|
3
|
+
export type ErrorModel = {
|
4
|
+
error: {
|
5
|
+
code: string | number;
|
6
|
+
traceid: string;
|
7
|
+
message: string;
|
8
|
+
timestamp: string;
|
9
|
+
path: string;
|
10
|
+
};
|
11
|
+
};
|
12
|
+
|
13
|
+
export type ParametersType = { [key: string]: unknown };
|
14
|
+
|
15
|
+
export class BaseException extends HttpException {
|
16
|
+
traceid: string;
|
17
|
+
readonly context: string;
|
18
|
+
readonly statusCode: number;
|
19
|
+
readonly code?: string;
|
20
|
+
readonly parameters: ParametersType;
|
21
|
+
|
22
|
+
constructor(
|
23
|
+
message: string,
|
24
|
+
status: HttpStatus,
|
25
|
+
parameters?: ParametersType,
|
26
|
+
) {
|
27
|
+
super(message, status);
|
28
|
+
|
29
|
+
if (parameters) {
|
30
|
+
this.parameters = parameters;
|
31
|
+
}
|
32
|
+
|
33
|
+
this.statusCode = super.getStatus();
|
34
|
+
Error.captureStackTrace(this);
|
35
|
+
}
|
36
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { HttpStatus } from '@nestjs/common';
|
2
|
+
import { ConflictException } from './conflict-error.exception';
|
3
|
+
|
4
|
+
describe('ConflictException', () => {
|
5
|
+
it('should set default message and status code if no parameters are provided', () => {
|
6
|
+
const error = new ConflictException();
|
7
|
+
|
8
|
+
expect(error.message).toBe('ConflictException');
|
9
|
+
expect(error.statusCode).toBe(HttpStatus.CONFLICT);
|
10
|
+
expect(error.parameters).toBeUndefined();
|
11
|
+
});
|
12
|
+
|
13
|
+
it('should set custom message, status code, and parameters if provided', () => {
|
14
|
+
const customMessage = 'Custom message';
|
15
|
+
const customStatusCode = HttpStatus.CONFLICT;
|
16
|
+
const customParameters = { key: 'value' };
|
17
|
+
const error = new ConflictException(customMessage, customParameters);
|
18
|
+
|
19
|
+
expect(error.message).toBe(customMessage);
|
20
|
+
expect(error.statusCode).toBe(customStatusCode);
|
21
|
+
expect(error.parameters).toEqual(customParameters);
|
22
|
+
});
|
23
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { HttpStatus } from '@nestjs/common';
|
2
|
+
import { BaseException, ParametersType } from './base.exception';
|
3
|
+
|
4
|
+
export class ConflictException extends BaseException {
|
5
|
+
constructor(message?: string, parameters?: ParametersType) {
|
6
|
+
super(message ?? 'ConflictException', HttpStatus.CONFLICT, parameters);
|
7
|
+
}
|
8
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { ForbiddenException } from './forbidden-error.exception';
|
2
|
+
import { HttpStatus } from '@nestjs/common';
|
3
|
+
|
4
|
+
describe('ForbiddenException', () => {
|
5
|
+
it('should set default message and status code if no parameters are provided', () => {
|
6
|
+
const error = new ForbiddenException();
|
7
|
+
|
8
|
+
expect(error.message).toBe('BadRequestException');
|
9
|
+
expect(error.statusCode).toBe(HttpStatus.FORBIDDEN);
|
10
|
+
expect(error.parameters).toBeUndefined();
|
11
|
+
});
|
12
|
+
|
13
|
+
it('should set custom message, status code, and parameters if provided', () => {
|
14
|
+
const customMessage = 'Custom message';
|
15
|
+
const customStatusCode = HttpStatus.FORBIDDEN;
|
16
|
+
const customParameters = { key: 'value' };
|
17
|
+
const error = new ForbiddenException(customMessage, customParameters);
|
18
|
+
|
19
|
+
expect(error.message).toBe(customMessage);
|
20
|
+
expect(error.statusCode).toBe(customStatusCode);
|
21
|
+
expect(error.parameters).toEqual(customParameters);
|
22
|
+
});
|
23
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { HttpStatus } from '@nestjs/common';
|
2
|
+
import { BaseException, ParametersType } from './base.exception';
|
3
|
+
|
4
|
+
export class ForbiddenException extends BaseException {
|
5
|
+
constructor(message?: string, parameters?: ParametersType) {
|
6
|
+
super(message ?? 'BadRequestException', HttpStatus.FORBIDDEN, parameters);
|
7
|
+
}
|
8
|
+
}
|
package/src/exception/index.ts
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
export * from './base.exception';
|
2
|
+
export * from './conflict-error.exception';
|
3
|
+
export * from './not-found-error.exception';
|
4
|
+
export * from './forbidden-error.exception';
|
5
|
+
export * from './bad-request-error.exception';
|
6
|
+
export * from './unauthorized-error.exception';
|
7
|
+
export * from './internal-server-error.exception';
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { InternalServerException } from './internal-server-error.exception';
|
2
|
+
import { HttpStatus } from '@nestjs/common';
|
3
|
+
|
4
|
+
describe('InternalServerException', () => {
|
5
|
+
it('should set default message and status code if no parameters are provided', () => {
|
6
|
+
const error = new InternalServerException();
|
7
|
+
|
8
|
+
expect(error.message).toBe('InternalServerException');
|
9
|
+
expect(error.statusCode).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
|
10
|
+
expect(error.parameters).toBeUndefined();
|
11
|
+
});
|
12
|
+
|
13
|
+
it('should set custom message, status code, and parameters if provided', () => {
|
14
|
+
const customMessage = 'Custom message';
|
15
|
+
const customStatusCode = HttpStatus.INTERNAL_SERVER_ERROR;
|
16
|
+
const customParameters = { key: 'value' };
|
17
|
+
const error = new InternalServerException(customMessage, customParameters);
|
18
|
+
|
19
|
+
expect(error.message).toBe(customMessage);
|
20
|
+
expect(error.statusCode).toBe(customStatusCode);
|
21
|
+
expect(error.parameters).toEqual(customParameters);
|
22
|
+
});
|
23
|
+
});
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { HttpStatus } from '@nestjs/common';
|
2
|
+
import { BaseException, ParametersType } from './base.exception';
|
3
|
+
|
4
|
+
export class InternalServerException extends BaseException {
|
5
|
+
constructor(message?: string, parameters?: ParametersType) {
|
6
|
+
super(
|
7
|
+
message ?? 'InternalServerException',
|
8
|
+
HttpStatus.INTERNAL_SERVER_ERROR,
|
9
|
+
parameters,
|
10
|
+
);
|
11
|
+
}
|
12
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { NotFoundException } from './not-found-error.exception';
|
2
|
+
import { HttpStatus } from '@nestjs/common';
|
3
|
+
|
4
|
+
describe('NotFoundException', () => {
|
5
|
+
it('should set default message and status code if no parameters are provided', () => {
|
6
|
+
const error = new NotFoundException();
|
7
|
+
|
8
|
+
expect(error.message).toBe('NotFoundException');
|
9
|
+
expect(error.statusCode).toBe(HttpStatus.NOT_FOUND);
|
10
|
+
expect(error.parameters).toBeUndefined();
|
11
|
+
});
|
12
|
+
|
13
|
+
it('should set custom message, status code, and parameters if provided', () => {
|
14
|
+
const customMessage = 'Custom message';
|
15
|
+
const customStatusCode = HttpStatus.INTERNAL_SERVER_ERROR;
|
16
|
+
const customParameters = { key: 'value' };
|
17
|
+
const error = new NotFoundException(customMessage, customParameters);
|
18
|
+
|
19
|
+
expect(error.message).toBe(customMessage);
|
20
|
+
expect(error.statusCode).toBe(customStatusCode);
|
21
|
+
expect(error.parameters).toEqual(customParameters);
|
22
|
+
});
|
23
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { HttpStatus } from '@nestjs/common';
|
2
|
+
import { BaseException, ParametersType } from './base.exception';
|
3
|
+
|
4
|
+
export class NotFoundException extends BaseException {
|
5
|
+
constructor(message?: string, parameters?: ParametersType) {
|
6
|
+
super(message ?? 'NotFoundException', HttpStatus.NOT_FOUND, parameters);
|
7
|
+
}
|
8
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { UnauthorizedException } from './unauthorized-error.exception';
|
2
|
+
import { HttpStatus } from '@nestjs/common';
|
3
|
+
|
4
|
+
describe('UnauthorizedException', () => {
|
5
|
+
it('should set default message and status code if no parameters are provided', () => {
|
6
|
+
const error = new UnauthorizedException();
|
7
|
+
|
8
|
+
expect(error.message).toBe('UnauthorizedException');
|
9
|
+
expect(error.statusCode).toBe(HttpStatus.UNAUTHORIZED);
|
10
|
+
expect(error.parameters).toBeUndefined();
|
11
|
+
});
|
12
|
+
|
13
|
+
it('should set custom message, status code, and parameters if provided', () => {
|
14
|
+
const customMessage = 'Custom message';
|
15
|
+
const customStatusCode = HttpStatus.UNAUTHORIZED;
|
16
|
+
const customParameters = { key: 'value' };
|
17
|
+
const error = new UnauthorizedException(customMessage, customParameters);
|
18
|
+
|
19
|
+
expect(error.message).toBe(customMessage);
|
20
|
+
expect(error.statusCode).toBe(customStatusCode);
|
21
|
+
expect(error.parameters).toEqual(customParameters);
|
22
|
+
});
|
23
|
+
});
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { HttpStatus } from '@nestjs/common';
|
2
|
+
import { BaseException, ParametersType } from './base.exception';
|
3
|
+
|
4
|
+
export class UnauthorizedException extends BaseException {
|
5
|
+
constructor(message?: string, parameters?: ParametersType) {
|
6
|
+
super(
|
7
|
+
message ?? 'UnauthorizedException',
|
8
|
+
HttpStatus.UNAUTHORIZED,
|
9
|
+
parameters,
|
10
|
+
);
|
11
|
+
}
|
12
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import {
|
2
|
+
ExceptionFilter,
|
3
|
+
Catch,
|
4
|
+
ArgumentsHost,
|
5
|
+
HttpException,
|
6
|
+
} from '@nestjs/common';
|
7
|
+
import { Request, Response } from 'express';
|
8
|
+
|
9
|
+
@Catch(HttpException)
|
10
|
+
export class HttpExceptionFilter implements ExceptionFilter {
|
11
|
+
catch(exception: HttpException, host: ArgumentsHost) {
|
12
|
+
const ctx = host.switchToHttp();
|
13
|
+
const response = ctx.getResponse<Response>();
|
14
|
+
const request = ctx.getRequest<Request>();
|
15
|
+
const status = exception.getStatus();
|
16
|
+
|
17
|
+
response.status(status).json({
|
18
|
+
statusCode: status,
|
19
|
+
timestamp: new Date().toISOString(),
|
20
|
+
path: request.url,
|
21
|
+
});
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './http-exception.filter';
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Catch } from '@nestjs/common';
|
2
|
+
import { RpcException } from '@nestjs/microservices';
|
3
|
+
import type { RpcExceptionFilter as NestRpcExceptionFilter } from '@nestjs/common';
|
4
|
+
import { throwError } from 'rxjs';
|
5
|
+
import type { Observable } from 'rxjs';
|
6
|
+
|
7
|
+
@Catch(RpcException)
|
8
|
+
export class RpcExceptionFilter
|
9
|
+
implements NestRpcExceptionFilter<RpcException>
|
10
|
+
{
|
11
|
+
catch(exception: RpcException): Observable<any> {
|
12
|
+
// TODO: handle grpc error here instead of throwing it inside each service
|
13
|
+
return throwError(() => exception.getError());
|
14
|
+
}
|
15
|
+
}
|
package/src/index.ts
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './social.interface';
|
package/src/lib/index.ts
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './mailer.config';
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { registerAs } from '@nestjs/config';
|
2
|
+
import {
|
3
|
+
IsString,
|
4
|
+
IsInt,
|
5
|
+
Min,
|
6
|
+
Max,
|
7
|
+
IsOptional,
|
8
|
+
IsBoolean,
|
9
|
+
IsEmail,
|
10
|
+
} from 'class-validator';
|
11
|
+
import { validateConfig } from '../../../util';
|
12
|
+
import { MailConfig } from '../../../config';
|
13
|
+
|
14
|
+
class EnvironmentVariablesValidator {
|
15
|
+
@IsInt()
|
16
|
+
@Min(0)
|
17
|
+
@Max(65535)
|
18
|
+
@IsOptional()
|
19
|
+
MAIL_PORT: number;
|
20
|
+
|
21
|
+
@IsString()
|
22
|
+
MAIL_HOST: string;
|
23
|
+
|
24
|
+
@IsString()
|
25
|
+
@IsOptional()
|
26
|
+
MAIL_USER: string;
|
27
|
+
|
28
|
+
@IsString()
|
29
|
+
@IsOptional()
|
30
|
+
MAIL_PASSWORD: string;
|
31
|
+
|
32
|
+
@IsEmail()
|
33
|
+
MAIL_DEFAULT_EMAIL: string;
|
34
|
+
|
35
|
+
@IsString()
|
36
|
+
MAIL_DEFAULT_NAME: string;
|
37
|
+
|
38
|
+
@IsBoolean()
|
39
|
+
MAIL_IGNORE_TLS: boolean;
|
40
|
+
|
41
|
+
@IsBoolean()
|
42
|
+
MAIL_SECURE: boolean;
|
43
|
+
|
44
|
+
@IsBoolean()
|
45
|
+
MAIL_REQUIRE_TLS: boolean;
|
46
|
+
}
|
47
|
+
|
48
|
+
export default registerAs<MailConfig>('mail', () => {
|
49
|
+
validateConfig(process.env, EnvironmentVariablesValidator);
|
50
|
+
|
51
|
+
return {
|
52
|
+
port: process.env.MAIL_PORT ? parseInt(process.env.MAIL_PORT, 10) : 587,
|
53
|
+
host: process.env.MAIL_HOST,
|
54
|
+
user: process.env.MAIL_USER,
|
55
|
+
password: process.env.MAIL_PASSWORD,
|
56
|
+
defaultEmail: process.env.MAIL_DEFAULT_EMAIL,
|
57
|
+
defaultName: process.env.MAIL_DEFAULT_NAME,
|
58
|
+
ignoreTLS: process.env.MAIL_IGNORE_TLS === 'true',
|
59
|
+
secure: process.env.MAIL_SECURE === 'true',
|
60
|
+
requireTLS: process.env.MAIL_REQUIRE_TLS === 'true',
|
61
|
+
};
|
62
|
+
});
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import fs from 'node:fs/promises';
|
2
|
+
import Handlebars from 'handlebars';
|
3
|
+
import nodemailer from 'nodemailer';
|
4
|
+
import { Injectable } from '@nestjs/common';
|
5
|
+
import { ConfigService } from '@nestjs/config';
|
6
|
+
import { AllConfigType } from '../../config';
|
7
|
+
|
8
|
+
@Injectable()
|
9
|
+
export class MailerService {
|
10
|
+
private readonly transporter: nodemailer.Transporter;
|
11
|
+
constructor(private readonly configService: ConfigService<AllConfigType>) {
|
12
|
+
this.transporter = nodemailer.createTransport({
|
13
|
+
host: configService.get('mail.host', { infer: true }),
|
14
|
+
port: configService.get('mail.port', { infer: true }),
|
15
|
+
ignoreTLS: configService.get('mail.ignoreTLS', { infer: true }),
|
16
|
+
secure: configService.get('mail.secure', { infer: true }),
|
17
|
+
requireTLS: configService.get('mail.requireTLS', { infer: true }),
|
18
|
+
auth: {
|
19
|
+
user: configService.get('mail.user', { infer: true }),
|
20
|
+
pass: configService.get('mail.password', { infer: true }),
|
21
|
+
},
|
22
|
+
});
|
23
|
+
}
|
24
|
+
|
25
|
+
async sendMail({
|
26
|
+
templatePath,
|
27
|
+
context,
|
28
|
+
...mailOptions
|
29
|
+
}: nodemailer.SendMailOptions & {
|
30
|
+
templatePath: string;
|
31
|
+
context: Record<string, unknown>;
|
32
|
+
}): Promise<void> {
|
33
|
+
let html: string | undefined;
|
34
|
+
if (templatePath) {
|
35
|
+
const template = await fs.readFile(templatePath, 'utf-8');
|
36
|
+
html = Handlebars.compile(template, {
|
37
|
+
strict: true,
|
38
|
+
})(context);
|
39
|
+
}
|
40
|
+
|
41
|
+
await this.transporter.sendMail({
|
42
|
+
...mailOptions,
|
43
|
+
from: mailOptions.from
|
44
|
+
? mailOptions.from
|
45
|
+
: `"${this.configService.get('mail.defaultName', {
|
46
|
+
infer: true,
|
47
|
+
})}" <${this.configService.get('mail.defaultEmail', {
|
48
|
+
infer: true,
|
49
|
+
})}>`,
|
50
|
+
html: mailOptions.html ? mailOptions.html : html,
|
51
|
+
});
|
52
|
+
}
|
53
|
+
}
|
File without changes
|
@@ -1,3 +1,3 @@
|
|
1
1
|
export class BaseDocument {
|
2
|
-
|
3
|
-
}
|
2
|
+
id?: string;
|
3
|
+
}
|
@@ -1,5 +1,13 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
SearchOptions,
|
3
|
+
SearchParams,
|
4
|
+
SearchResponse,
|
5
|
+
DocumentSchema,
|
6
|
+
} from 'typesense/lib/Typesense/Documents';
|
2
7
|
|
3
8
|
export interface SearchDocumentService<Document extends DocumentSchema> {
|
4
|
-
|
9
|
+
searchDocument(
|
10
|
+
searchParameters: SearchParams,
|
11
|
+
options: SearchOptions,
|
12
|
+
): Promise<SearchResponse<Document>>;
|
5
13
|
}
|
@@ -1 +1 @@
|
|
1
|
-
export class GenericSchema {}
|
1
|
+
export class GenericSchema {}
|
@@ -1 +1 @@
|
|
1
|
-
export * from './generic.schema';
|
1
|
+
export * from './generic.schema';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from 'typesense/lib/Typesense/Collections';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from 'typesense/lib/Typesense/Documents';
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { Client } from 'typesense';
|
2
2
|
import { Logger, Type } from '@nestjs/common';
|
3
3
|
import { plainToClass } from 'class-transformer';
|
4
|
-
import { CollectionCreateSchema } from '
|
4
|
+
import { CollectionCreateSchema } from '../collection';
|
5
5
|
import {
|
6
6
|
SearchParams,
|
7
7
|
SearchOptions,
|
8
8
|
SearchResponse,
|
9
9
|
DeleteResponse,
|
10
10
|
ImportResponse,
|
11
|
-
} from '
|
11
|
+
} from '../document';
|
12
12
|
import { BaseDocument } from '../../document';
|
13
13
|
import { SearchDocumentService } from '../../interface';
|
14
14
|
import { EntityGeneric } from '../../../../generic';
|
@@ -19,6 +19,7 @@ export abstract class ClientService<
|
|
19
19
|
Entity extends EntityGeneric,
|
20
20
|
> implements SearchDocumentService<Document>
|
21
21
|
{
|
22
|
+
private readonly logger = new Logger(ClientService.name);
|
22
23
|
protected readonly entity: Type<Entity>;
|
23
24
|
protected abstract cache_s: number;
|
24
25
|
protected readonly skipCheckSchema: boolean = false;
|
@@ -81,6 +82,7 @@ export abstract class ClientService<
|
|
81
82
|
}
|
82
83
|
return documents;
|
83
84
|
} catch (error) {
|
85
|
+
this.logger.error(error);
|
84
86
|
return null;
|
85
87
|
}
|
86
88
|
}
|
@@ -110,7 +112,7 @@ export abstract class ClientService<
|
|
110
112
|
.documents()
|
111
113
|
.import(data, { action: 'upsert' });
|
112
114
|
} catch (error) {
|
113
|
-
|
115
|
+
this.logger.error(error);
|
114
116
|
}
|
115
117
|
}
|
116
118
|
}
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
export { Client } from 'typesense';
|
@@ -0,0 +1 @@
|
|
1
|
+
// export { CollectionSchema } from 'typesense/src/Typesense/Collection';
|
@@ -0,0 +1,89 @@
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
2
|
+
|
3
|
+
import { Field } from './field.decorator';
|
4
|
+
import { FIELD_METADATA } from './field.decorator';
|
5
|
+
import { Schema } from './schema.decorator';
|
6
|
+
|
7
|
+
describe('typesense', () => {
|
8
|
+
describe('decorators', () => {
|
9
|
+
describe('field', () => {
|
10
|
+
it('should enhance field with metadata', () => {
|
11
|
+
@Schema()
|
12
|
+
class Test {
|
13
|
+
@Field('string')
|
14
|
+
field!: string;
|
15
|
+
}
|
16
|
+
|
17
|
+
expect(Reflect.getMetadata(FIELD_METADATA, Test)).toEqual(
|
18
|
+
expect.arrayContaining([
|
19
|
+
expect.objectContaining({
|
20
|
+
name: 'field',
|
21
|
+
type: 'string',
|
22
|
+
}),
|
23
|
+
]),
|
24
|
+
);
|
25
|
+
});
|
26
|
+
|
27
|
+
it('should enhance field with custom name metadata', () => {
|
28
|
+
@Schema()
|
29
|
+
class Test {
|
30
|
+
@Field('string', { name: 'custom' })
|
31
|
+
field!: string;
|
32
|
+
}
|
33
|
+
|
34
|
+
expect(Reflect.getMetadata(FIELD_METADATA, Test)).toEqual(
|
35
|
+
expect.arrayContaining([
|
36
|
+
expect.objectContaining({
|
37
|
+
name: 'custom',
|
38
|
+
type: 'string',
|
39
|
+
}),
|
40
|
+
]),
|
41
|
+
);
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
45
|
+
it('should enhance field with options metadata', () => {
|
46
|
+
@Schema()
|
47
|
+
class Test {
|
48
|
+
@Field('string', { facet: true, index: true, optional: true })
|
49
|
+
field!: string;
|
50
|
+
}
|
51
|
+
|
52
|
+
expect(Reflect.getMetadata(FIELD_METADATA, Test)).toEqual(
|
53
|
+
expect.arrayContaining([
|
54
|
+
expect.objectContaining({
|
55
|
+
name: 'field',
|
56
|
+
type: 'string',
|
57
|
+
facet: true,
|
58
|
+
index: true,
|
59
|
+
optional: true,
|
60
|
+
}),
|
61
|
+
]),
|
62
|
+
);
|
63
|
+
});
|
64
|
+
|
65
|
+
it('should enhance field with multiple fields metadata', () => {
|
66
|
+
@Schema()
|
67
|
+
class Test {
|
68
|
+
@Field('string')
|
69
|
+
field!: string;
|
70
|
+
|
71
|
+
@Field('string')
|
72
|
+
field2!: string;
|
73
|
+
}
|
74
|
+
|
75
|
+
expect(Reflect.getMetadata(FIELD_METADATA, Test)).toEqual(
|
76
|
+
expect.arrayContaining([
|
77
|
+
expect.objectContaining({
|
78
|
+
name: 'field',
|
79
|
+
type: 'string',
|
80
|
+
}),
|
81
|
+
expect.objectContaining({
|
82
|
+
name: 'field2',
|
83
|
+
type: 'string',
|
84
|
+
}),
|
85
|
+
]),
|
86
|
+
);
|
87
|
+
});
|
88
|
+
});
|
89
|
+
});
|