Skip to content

Commit bfa3273

Browse files
committed
fix: issues with configs
1 parent 90cf1ea commit bfa3273

27 files changed

+124
-73
lines changed

src/app.module.ts

+4-27
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
1+
import { SWAGGER_API_ENDPOINT } from "@common/constant";
2+
import { ClearCacheMiddleware, RealIpMiddleware } from "@common/middlewares";
13
import { applyRawBodyOnlyTo } from "@golevelup/nestjs-webhooks";
4+
import { SharedModule } from "@modules/shared/shared.module";
25
import type { MiddlewareConsumer, NestModule } from "@nestjs/common";
36
import { Module, RequestMethod } from "@nestjs/common";
4-
import { APP_GUARD, APP_INTERCEPTOR } from "@nestjs/core";
5-
import { SentryInterceptor } from "@ntegral/nestjs-sentry";
6-
import { CustomThrottlerGuard } from "@common/guards";
7-
import { ClearCacheInterceptor, HttpCacheInterceptor } from "@common/interceptors";
8-
import { ClearCacheMiddleware, RealIpMiddleware } from "@common/middlewares";
9-
import { NestCacheModule } from "@lib/cache";
10-
import { SharedModule } from "@modules/shared/shared.module";
117
import { AppController } from "app.controller";
12-
import { SWAGGER_API_ENDPOINT } from "@common/constant";
138

149
const stripeWebhookPath = "stripe/webhook";
1510
const excludedPaths = [stripeWebhookPath, SWAGGER_API_ENDPOINT];
1611

1712
@Module({
13+
imports: [SharedModule],
1814
controllers: [AppController],
19-
imports: [SharedModule, NestCacheModule],
20-
providers: [
21-
{
22-
provide: APP_INTERCEPTOR,
23-
useClass: SentryInterceptor,
24-
},
25-
{
26-
provide: APP_GUARD,
27-
useClass: CustomThrottlerGuard,
28-
},
29-
{
30-
provide: APP_INTERCEPTOR,
31-
useClass: HttpCacheInterceptor,
32-
},
33-
{
34-
provide: APP_INTERCEPTOR,
35-
useClass: ClearCacheInterceptor,
36-
},
37-
],
3815
})
3916
export class AppModule implements NestModule {
4017
configure(consumer: MiddlewareConsumer) {

src/common/constant/string.constants.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { capitalize } from "helper-fns";
2-
import { readPackageSync } from "read-pkg";
32

43
export const REQUEST_ID_TOKEN_HEADER = "x-request-id";
54
export const VERSION_VALIDATION_MESSAGE = "Version must start with \"v\" followed by a number.";
@@ -10,8 +9,12 @@ export const THROTTLE_LIMIT_RESPONSE = "Too many requests, please try again late
109
export const MULTER_IMAGE_FILTER = "Only image files are allowed!.";
1110
export const API_UNAUTHORISED_RESPONSE = "No auth token in request.";
1211

13-
// swagger constants
14-
const packageJson = readPackageSync();
12+
// swagger constants, TODO: dfix this too
13+
const packageJson = {
14+
name: "nestjs-boilerplate",
15+
version: "1.0.0",
16+
description: "NestJS Boilerplate",
17+
};
1518

1619
export const APP_NAME = packageJson.name;
1720
export const SWAGGER_API_CURRENT_VERSION = packageJson.version;

src/generated/i18n-generated.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* DO NOT EDIT, file generated by nestjs-i18n */
2+
3+
import { Path } from "nestjs-i18n";
4+
export type I18nTranslations = {
5+
"exception": {
6+
"itemExists": string;
7+
"itemDoesNotExist": string;
8+
"unauthorized": string;
9+
"internalError": string;
10+
"otpRequired": string;
11+
"usernameRequired": string;
12+
"followerFollowingSame": string;
13+
"invalidOTP": string;
14+
"inactiveUser": string;
15+
"invalidCredentials": string;
16+
"invalidTwoFaCode": string;
17+
"forbidden": string;
18+
"userInactive": string;
19+
"notFound": string;
20+
"itemExpired": string;
21+
"emailLooksGood": string;
22+
"unsupportedFileType": string;
23+
"incorrectOldPassword": string;
24+
"badRequest": string;
25+
"invalidRefreshToken": string;
26+
"deleteDefaultError": string;
27+
"tooManyTries": string;
28+
"refreshToken": string;
29+
"token": string;
30+
"tooManyRequests": string;
31+
"invalidCursor": string;
32+
"cursorInvalidDate": string;
33+
"cursorInvalidNumber": string;
34+
"apiUnauthorizedResponse": string;
35+
"tooManyRequest": string;
36+
};
37+
"validation": {
38+
"isNotEmpty": string;
39+
"maxLength": string;
40+
"minLength": string;
41+
"max": string;
42+
"min": string;
43+
"isPassword": string;
44+
"isIn": string;
45+
"isEnum": string;
46+
"isDataType": string;
47+
};
48+
};
49+
export type I18nPath = Path<I18nTranslations>;

src/lib/i18n/i18n.module.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import path from "node:path";
22

33
import { Module } from "@nestjs/common";
4-
import { AcceptLanguageResolver, CookieResolver, HeaderResolver, I18nModule, QueryResolver } from "nestjs-i18n";
54
import { ConfigModule, ConfigService } from "@nestjs/config";
5+
import { AcceptLanguageResolver, HeaderResolver, I18nModule, QueryResolver } from "nestjs-i18n";
66

77
@Module({
88
imports: [
99
I18nModule.forRootAsync({
10+
imports: [ConfigModule],
11+
inject: [ConfigService],
1012
useFactory: (configService: ConfigService<Configs, true>) => ({
11-
imports: [ConfigModule],
12-
inject: [ConfigService],
1313
fallbackLanguage: "en",
1414
fallbacks: {
1515
"np-*": "np",
@@ -26,12 +26,6 @@ import { ConfigModule, ConfigService } from "@nestjs/config";
2626
includeSubfolders: true,
2727
},
2828
typesOutputPath: configService.get("app.env", { infer: true }).startsWith("prod") ? undefined : path.join(`${process.cwd()}/src/generated/i18n-generated.ts`),
29-
resolvers: [
30-
new HeaderResolver(["x-custom-lang"]),
31-
AcceptLanguageResolver,
32-
new CookieResolver(),
33-
{ use: QueryResolver, options: ["lang", "locale"] },
34-
],
3529
}),
3630
resolvers: [
3731
{ use: QueryResolver, options: ["lang"] },
@@ -42,4 +36,4 @@ import { ConfigModule, ConfigService } from "@nestjs/config";
4236
],
4337
exports: [I18nModule],
4438
})
45-
export class NestI18nModule {}
39+
export class NestI18nModule { }

src/lib/pino/pino.module.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const basePinoOptions = {
1414
@Module({
1515
imports: [
1616
LoggerModule.forRootAsync({
17-
useFactory: (configService: ConfigService<Configs, true>) => ({
18-
imports: [ConfigModule],
19-
inject: [ConfigService],
17+
imports: [ConfigModule],
18+
inject: [ConfigService],
19+
useFactory: (_configService: ConfigService<Configs, true>) => ({
2020
pinoHttp: {
2121
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
2222
name: "ultimate-nest",
@@ -34,7 +34,7 @@ const basePinoOptions = {
3434
paths: redactFields,
3535
censor: "**GDPR COMPLIANT**",
3636
},
37-
transport: configService.get("app.env", { infer: true }).startsWith("prod")
37+
transport: true
3838
? {
3939
targets: [
4040
{

src/lib/sentry.module.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { Module } from "@nestjs/common";
1+
import { Global, Module } from "@nestjs/common";
22
import { ConfigModule, ConfigService } from "@nestjs/config";
33
import { SentryModule } from "@ntegral/nestjs-sentry";
44

5+
@Global()
56
@Module({
67
imports: [
78
SentryModule.forRootAsync({
89
imports: [ConfigModule],
910
inject: [ConfigService],
1011
useFactory: async (configService: ConfigService<Configs, true>) => ({
1112
dsn: configService.get("sentry.sentryDsn", { infer: true }),
12-
environment: configService.get("sentry.sentryDsn", { infer: true }),
13+
environment: configService.get("sentry.environment", { infer: true }),
1314
debug: true,
1415
tracesSampleRate: 1,
1516
}),

src/main.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
import "@total-typescript/ts-reset";
22

3-
import bodyParser from "body-parser";
4-
import chalk from "chalk";
3+
import { AppUtils, HelperService } from "@common/helpers";
54
import { Logger, ValidationPipe } from "@nestjs/common";
65
import { ConfigService } from "@nestjs/config";
76
import { NestFactory } from "@nestjs/core";
87
import type { NestExpressApplication } from "@nestjs/platform-express";
98
import { ExpressAdapter } from "@nestjs/platform-express";
9+
import bodyParser from "body-parser";
10+
import chalk from "chalk";
1011
import { useContainer } from "class-validator";
1112
import compression from "compression";
1213
import helmet from "helmet";
1314
import { I18nValidationExceptionFilter } from "nestjs-i18n";
1415
import { LoggerErrorInterceptor } from "nestjs-pino";
15-
import { createLogger } from "@lib/pino/app.logger";
16-
import { AppUtils, HelperService } from "@common/helpers";
17-
import { SocketIOAdapter } from "./socket-io.adapter";
1816
import { AppModule } from "./app.module";
17+
import { SocketIOAdapter } from "./socket-io.adapter";
1918

2019
declare const module: { hot: { accept: () => void; dispose: (argument: () => Promise<void>) => void } };
2120

2221
const logger = new Logger("Bootstrap");
2322

2423
async function bootstrap() {
2524
const app = await NestFactory.create<NestExpressApplication>(AppModule, new ExpressAdapter(), {
26-
logger: await createLogger(),
2725
snapshot: true,
2826
});
2927

src/modules/category/category.service.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import { BaseRepository } from "@common/database";
33
import type { OffsetPaginationDto } from "@common/dtos";
44
import { Category } from "@entities";
55
import { BaseService } from "@lib/crud/crud.service";
6+
import { InjectRepository } from "@mikro-orm/nestjs";
67

78
@Injectable()
89
export class CategoryService extends BaseService<Category, OffsetPaginationDto> {
910
protected readonly queryName = "c"; // the name of the query used in the pagination
1011
protected readonly searchField = "name"; // the field to search for when searching for tags
1112
constructor(
12-
// @ts-expect-error: Unused import error
13-
// eslint-disable-next-line ts/no-unsafe-call
14-
@InjectRepository(Category) private categoryRepository: BaseRepository<Category>,
13+
// @ts-expect-error: Unused import error
14+
// eslint-disable-next-line ts/no-unsafe-call
15+
@InjectRepository(Category) private categoryRepository: BaseRepository<Category>,
1516
) {
1617
super(categoryRepository);
1718
}

src/modules/shared/shared.module.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Module } from "@nestjs/common";
2-
import { ScheduleModule } from "@nestjs/schedule";
31
import { IsUniqueConstraint } from "@common/decorators/validation";
2+
import { CustomThrottlerGuard } from "@common/guards";
3+
import { ClearCacheInterceptor, HttpCacheInterceptor } from "@common/interceptors";
4+
import { NestCacheModule } from "@lib/cache";
45
import { NestConfigModule } from "@lib/config/config.module";
56
import {
67
NestCaslModule,
@@ -25,6 +26,9 @@ import { ProfileModule } from "@modules/profile/profile.module";
2526
import { TagsModule } from "@modules/tags/tags.module";
2627
import { TwoFactorModule } from "@modules/twofa/twofa.module";
2728
import { UserModule } from "@modules/user/user.module";
29+
import { Module } from "@nestjs/common";
30+
import { APP_GUARD, APP_INTERCEPTOR } from "@nestjs/core";
31+
import { ScheduleModule } from "@nestjs/schedule";
2832

2933
@Module({
3034
imports: [
@@ -44,14 +48,34 @@ import { UserModule } from "@modules/user/user.module";
4448
NestPinoModule,
4549
NestI18nModule,
4650
NestCloudinaryModule,
51+
NestCacheModule,
4752
NestSentryModule,
4853
NestCaslModule,
4954
NestThrottlerModule,
5055
NestHttpModule,
5156
NestServeStaticModule,
57+
NestSentryModule,
5258
NestJwtModule,
5359
ScheduleModule.forRoot(),
5460
],
55-
providers: [IsUniqueConstraint],
61+
providers: [
62+
IsUniqueConstraint,
63+
// {
64+
// provide: APP_INTERCEPTOR, // TODO: fix sentry
65+
// useClass: SentryInterceptor,
66+
// },
67+
{
68+
provide: APP_GUARD,
69+
useClass: CustomThrottlerGuard,
70+
},
71+
{
72+
provide: APP_INTERCEPTOR,
73+
useClass: HttpCacheInterceptor,
74+
},
75+
{
76+
provide: APP_INTERCEPTOR,
77+
useClass: ClearCacheInterceptor,
78+
},
79+
],
5680
})
5781
export class SharedModule {}

temp/BaseEntity.js.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"data":{"propertyOrder":{},"properties":{"id":{"name":"id","reference":"scalar","primary":true,"hidden":true,"index":true,"type":"number","array":false},"idx":{"name":"idx","reference":"scalar","index":true,"getter":false,"setter":false,"type":"string","array":false,"optional":true},"isActive":{"name":"isActive","reference":"scalar","getter":false,"setter":false,"type":"boolean","array":false,"optional":true},"isDeleted":{"name":"isDeleted","reference":"scalar","hidden":true,"getter":false,"setter":false,"type":"boolean","array":false,"optional":true},"deletedAt":{"name":"deletedAt","reference":"scalar","getter":false,"setter":false,"type":"Date","array":false,"optional":true},"createdAt":{"name":"createdAt","reference":"scalar","getter":false,"setter":false,"type":"Date","array":false,"optional":true},"updatedAt":{"name":"updatedAt","reference":"scalar","hidden":true,"getter":false,"setter":false,"type":"Date","array":false,"optional":true}},"props":[{"name":"id","reference":"scalar","primary":true,"hidden":true,"index":true,"type":"number","array":false},{"name":"idx","reference":"scalar","index":true,"getter":false,"setter":false,"type":"string","array":false,"optional":true},{"name":"isActive","reference":"scalar","getter":false,"setter":false,"type":"boolean","array":false,"optional":true},{"name":"isDeleted","reference":"scalar","hidden":true,"getter":false,"setter":false,"type":"boolean","array":false,"optional":true},{"name":"deletedAt","reference":"scalar","getter":false,"setter":false,"type":"Date","array":false,"optional":true},{"name":"createdAt","reference":"scalar","getter":false,"setter":false,"type":"Date","array":false,"optional":true},{"name":"updatedAt","reference":"scalar","hidden":true,"getter":false,"setter":false,"type":"Date","array":false,"optional":true}],"primaryKeys":["id"],"filters":{},"hooks":{},"indexes":[],"uniques":[],"checks":[],"concurrencyCheckKeys":{},"className":"BaseEntity","path":"./dist/common/database/base.entity.js","abstract":true,"constructorParams":[],"toJsonParams":[],"useCache":true,"compositePK":false,"simplePK":true,"relations":[]},"origin":"./dist/common/database/base.entity.js","hash":"0a512305f18ebe86f440150896ef51f0","version":"5.7.12"}
1+
{"data":{"propertyOrder":{},"properties":{"id":{"name":"id","reference":"scalar","primary":true,"hidden":true,"index":true,"type":"number","array":false},"idx":{"name":"idx","reference":"scalar","index":true,"getter":false,"setter":false,"type":"string","array":false,"optional":true},"isActive":{"name":"isActive","reference":"scalar","getter":false,"setter":false,"type":"boolean","array":false,"optional":true},"isDeleted":{"name":"isDeleted","reference":"scalar","hidden":true,"getter":false,"setter":false,"type":"boolean","array":false,"optional":true},"deletedAt":{"name":"deletedAt","reference":"scalar","getter":false,"setter":false,"type":"Date","array":false,"optional":true},"createdAt":{"name":"createdAt","reference":"scalar","getter":false,"setter":false,"type":"Date","array":false,"optional":true},"updatedAt":{"name":"updatedAt","reference":"scalar","hidden":true,"getter":false,"setter":false,"type":"Date","array":false,"optional":true}},"props":[{"name":"id","reference":"scalar","primary":true,"hidden":true,"index":true,"type":"number","array":false},{"name":"idx","reference":"scalar","index":true,"getter":false,"setter":false,"type":"string","array":false,"optional":true},{"name":"isActive","reference":"scalar","getter":false,"setter":false,"type":"boolean","array":false,"optional":true},{"name":"isDeleted","reference":"scalar","hidden":true,"getter":false,"setter":false,"type":"boolean","array":false,"optional":true},{"name":"deletedAt","reference":"scalar","getter":false,"setter":false,"type":"Date","array":false,"optional":true},{"name":"createdAt","reference":"scalar","getter":false,"setter":false,"type":"Date","array":false,"optional":true},{"name":"updatedAt","reference":"scalar","hidden":true,"getter":false,"setter":false,"type":"Date","array":false,"optional":true}],"primaryKeys":["id"],"filters":{},"hooks":{},"indexes":[],"uniques":[],"concurrencyCheckKeys":{},"className":"BaseEntity","path":"./dist/common/database/base.entity.js","abstract":true,"constructorParams":[],"toJsonParams":[],"useCache":true,"compositePK":false,"simplePK":true,"relations":[]},"origin":"./dist/common/database/base.entity.js","hash":"a2153d72199ccfeab857a9c5b5d94af8","version":"5.8.9"}

temp/Category.js.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"data":{"propertyOrder":{},"properties":{"name":{"name":"name","reference":"scalar","index":true,"getter":false,"setter":false,"type":"string","array":false},"description":{"name":"description","reference":"scalar","getter":false,"setter":false,"type":"string","array":false},"posts":{"name":"posts","reference":"m:n","cascade":["persist"],"type":"Post","fixedOrder":false,"array":false}},"props":[{"name":"name","reference":"scalar","index":true,"getter":false,"setter":false,"type":"string","array":false},{"name":"description","reference":"scalar","getter":false,"setter":false,"type":"string","array":false},{"name":"posts","reference":"m:n","cascade":["persist"],"type":"Post","fixedOrder":false,"array":false}],"primaryKeys":[],"filters":{},"hooks":{},"indexes":[],"uniques":[],"checks":[],"concurrencyCheckKeys":{},"className":"Category","path":"./dist/entities/category.entity.js","name":"Category","abstract":false,"constructorParams":["partial"],"toJsonParams":[],"extends":"BaseEntity","useCache":true,"relations":[{"name":"posts","reference":"m:n","cascade":["persist"],"type":"Post","fixedOrder":false,"array":false}],"collection":"category"},"origin":"./dist/entities/category.entity.js","hash":"fc4f3683c61704e000098ea26e174c85","version":"5.7.12"}
1+
{"data":{"propertyOrder":{},"properties":{"name":{"name":"name","reference":"scalar","index":true,"getter":false,"setter":false,"type":"string","array":false},"description":{"name":"description","reference":"scalar","getter":false,"setter":false,"type":"string","array":false},"posts":{"name":"posts","reference":"m:n","cascade":["persist"],"type":"Post","fixedOrder":false,"array":false}},"props":[{"name":"name","reference":"scalar","index":true,"getter":false,"setter":false,"type":"string","array":false},{"name":"description","reference":"scalar","getter":false,"setter":false,"type":"string","array":false},{"name":"posts","reference":"m:n","cascade":["persist"],"type":"Post","fixedOrder":false,"array":false}],"primaryKeys":[],"filters":{},"hooks":{},"indexes":[],"uniques":[],"concurrencyCheckKeys":{},"className":"Category","path":"./dist/entities/category.entity.js","name":"Category","abstract":false,"constructorParams":["partial"],"toJsonParams":[],"extends":"BaseEntity","useCache":true,"relations":[{"name":"posts","reference":"m:n","cascade":["persist"],"type":"Post","fixedOrder":false,"array":false}],"collection":"category"},"origin":"./dist/entities/category.entity.js","hash":"8e2ec5a16c5fbab38c730eb820e536a7","version":"5.8.9"}

0 commit comments

Comments
 (0)