Skip to content

Commit

Permalink
fix: sentry config
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Sep 10, 2023
1 parent 033a638 commit 2dedd0d
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 118 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"jspdf",
"jwtid",
"jwttoken",
"KHTML",
"lukeed",
"Mercurius",
"mikro",
Expand Down
4 changes: 2 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ import { ConfigService } from "@nestjs/config";

@Injectable()
export class DatabaseService {
constructor(private configService: ConfigService) {}
constructor(private configService: ConfigService<Configs, true>) {}

getDatabaseUrl(): string {
return this.configService.get<string>("database.url");
return this.configService.get("database.url");
}

// ... other methods to access configuration settings related to database
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
"@golevelup/nestjs-rabbitmq": "^4.0.0",
"@golevelup/nestjs-stripe": "^0.6.3",
"@golevelup/nestjs-webhooks": "^0.2.16",
"@mikro-orm/core": "^5.7.14",
"@mikro-orm/migrations": "^5.7.14",
"@mikro-orm/core": "^5.8.0",
"@mikro-orm/migrations": "^5.8.0",
"@mikro-orm/nestjs": "^5.2.1",
"@mikro-orm/postgresql": "^5.7.14",
"@mikro-orm/reflection": "^5.7.14",
"@mikro-orm/postgresql": "^5.8.0",
"@mikro-orm/reflection": "^5.8.0",
"@mikro-orm/sql-highlighter": "^1.0.1",
"@nestjs/axios": "^3.0.0",
"@nestjs/cache-manager": "^2.1.0",
Expand Down Expand Up @@ -138,8 +138,8 @@
"@firebase/app-compat": "^0.2.18",
"@firebase/app-types": "^0.9.0",
"@golevelup/ts-jest": "^0.4.0",
"@mikro-orm/cli": "^5.7.14",
"@mikro-orm/seeder": "^5.7.14",
"@mikro-orm/cli": "^5.8.0",
"@mikro-orm/seeder": "^5.8.0",
"@nestjs/cli": "10.1.17",
"@nestjs/schematics": "10.0.2",
"@nestjs/testing": "10.2.4",
Expand Down
166 changes: 73 additions & 93 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/common/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ RABBITMQ_QUEUE: string;
RABBITMQ_DEFAULT_PREFETCH: number;

SENTRY_DSN: string;
SENTRY_ENVIRONMENT: string;

GOOGLE_CLIENT_ID: string;
GOOGLE_CLIENT_SECRET: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('IsUnique', () => {
providers: [IsUniqueConstraint, { provide: EntityManager, useValue: mockEm }],
}).compile();

isUnique = await module.get<IsUniqueConstraint>(IsUniqueConstraint);
isUnique = module.get<IsUniqueConstraint>(IsUniqueConstraint);
});

it('should pass if there are no duplicates', async () => {
Expand Down
9 changes: 5 additions & 4 deletions src/lib/cloudinary.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Module } from "@nestjs/common";
import { Global, Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { CloudinaryModule } from "nestjs-cloudinary";

@Global()
@Module({
imports: [
CloudinaryModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService<Configs, true>) => ({
isGlobal: true,
cloud_name: configService.get("cloudinary.cloud_name", { infer: true }),
api_key: configService.get("cloudinary.api_key", { infer: true }),
api_secret: configService.get("cloudinary.api_secret", { infer: true }),
cloud_name: configService.get("cloudinary.cloudName", { infer: true }),
api_key: configService.get("cloudinary.apiKey", { infer: true }),
api_secret: configService.get("cloudinary.apiSecret", { infer: true }),
}),
}),
],
Expand Down
2 changes: 2 additions & 0 deletions src/lib/config/config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
mail,
rabbitmq,
redis,
sentry,
stripe,
throttle,
twilio,
Expand All @@ -27,4 +28,5 @@ export interface Config {
stripe: ConfigType<typeof stripe>;
facebookOauth: ConfigType<typeof facebookOauth>;
googleOauth: ConfigType<typeof googleOauth>;
sentry: ConfigType<typeof sentry>;
}
4 changes: 4 additions & 0 deletions src/lib/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
rabbitmqConfigValidationSchema,
redis,
redisConfigValidationSchema,
sentry,
sentryConfigurationValidationSchema,
throttle,
throttleConfigValidationSchema,
} from "./configs";
Expand All @@ -40,6 +42,7 @@ import { HelperService } from "@common/helpers";
googleOauth,
facebookOauth,
throttle,
sentry,
],
cache: true,
isGlobal: true,
Expand All @@ -54,6 +57,7 @@ import { HelperService } from "@common/helpers";
...googleOauthConfigValidationSchema,
...facebookOauthConfigValidationSchema,
...throttleConfigValidationSchema,
...sentryConfigurationValidationSchema,
}),
validationOptions: {
abortEarly: true,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/config/configs/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerAs } from "@nestjs/config";
import Joi from "joi";
import { APP_ENVIRONMENTS, SENTRY_DSN_REGEX, VERSION_VALIDATION_MESSAGE } from "@common/constant";
import { APP_ENVIRONMENTS, VERSION_VALIDATION_MESSAGE } from "@common/constant";

// validation schema

Expand All @@ -18,7 +18,7 @@ export const appConfigValidationSchema = {
ALLOWED_HOSTS: Joi.string().optional(),
SWAGGER_USER: Joi.string().required(),
SWAGGER_PASSWORD: Joi.string().required(),
SENTRY_DSN: Joi.string().pattern(SENTRY_DSN_REGEX).required(),

};

// config
Expand Down
6 changes: 3 additions & 3 deletions src/lib/config/configs/cloudinary.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const cloudinaryConfigValidationSchema = {
};

export const cloudinary = registerAs("cloudinary", () => ({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
cloudName: process.env.CLOUDINARY_CLOUD_NAME,
apiKey: process.env.CLOUDINARY_API_KEY,
apiSecret: process.env.CLOUDINARY_API_SECRET,
}));
3 changes: 3 additions & 0 deletions src/lib/config/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// This is autogenerated file , edit if only you are sure

export * from "./app.config";
export * from "./cloudinary.config";
export * from "./database.config";
Expand All @@ -7,6 +9,7 @@ export * from "./minio.config";
export * from "./oauth2.config";
export * from "./rabbitmq.config";
export * from "./redis.config";
export * from "./sentry.config";
export * from "./stripe.config";
export * from "./throttle.config";
export * from "./twilio.config";
13 changes: 13 additions & 0 deletions src/lib/config/configs/sentry.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { registerAs } from "@nestjs/config";
import Joi from "joi";
import { SENTRY_DSN_REGEX } from "@common/constant";

export const sentryConfigurationValidationSchema = {
SENTRY_DSN: Joi.string().pattern(SENTRY_DSN_REGEX).required(),
SENTRY_ENVIRONMENT: Joi.string().required(),
};

export const sentry = registerAs("sentry", () => ({
sentryDsn: process.env.SENTRY_DSN,
environment: process.env.SENTRY_ENVIRONMENT,
}));
2 changes: 1 addition & 1 deletion src/lib/http.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Module } from "@nestjs/common";
"Accept": "application/json",
"Content-Type": "application/json",
"user-agent":
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
},
}),
],
Expand Down
2 changes: 1 addition & 1 deletion src/lib/minio.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NestMinioModule } from "nestjs-minio";
port: configService.get("minio.port"),
accessKey: configService.get("minio.accessKey"),
secretKey: configService.get("minio.secretKey"),
useSSL: configService.get<boolean>("minio.ssl"),
useSSL: configService.get("minio.ssl"),
}),
}),
],
Expand Down
4 changes: 2 additions & 2 deletions src/lib/orm.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { baseOptions } from "@common/database/mikro-orm-cli.config";
...baseOptions,
host: configService.get("database.host", { infer: true }),
port: configService.get("database.port", { infer: true }),
password: configService.get("database.password", { infer: true }),
user: configService.get("database.user", { infer: true }),
dbName: configService.get("database.dbName", { infer: true }),
user: configService.get("database.user", { infer: true }),
password: configService.get("database.password", { infer: true }),
}),
}),
MikroOrmModule.forFeature({
Expand Down
4 changes: 2 additions & 2 deletions src/lib/sentry.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { SentryModule } from "@ntegral/nestjs-sentry";
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService<Configs, true>) => ({
dsn: configService.get("app.sentryDsn", { infer: true }),
dsn: configService.get("sentry.sentryDsn", { infer: true }),
environment: configService.get("sentry.sentryDsn", { infer: true }),
debug: true,
environment: "development",
tracesSampleRate: 1,
}),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/modules/auth/strategies/magic-login.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class MagicLoginStrategy extends PassportStrategy(Strategy, "magicLogin")
template: EmailTemplate.MAGIC_LOGIN_TEMPLATE,
replacements: {
link: `${this.configService.get("app.url", { infer: true })}/v1/${href}`,
expiry: this.configService.get<string>("jwt.magicLinkExpiry", { infer: true }),
expiry: this.configService.get("jwt.magicLinkExpiry", { infer: true }),
},
to: destination,
subject: EmailSubject.MAGIC_LOGIN,
Expand Down
12 changes: 12 additions & 0 deletions src/socket-io.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class SocketIOAdapter extends IoAdapter {
super(app);
}

/**
* The function connects to a Redis server and creates a Redis adapter.
* @returns a promise that resolves to void.
*/
async connectToRedis(): Promise<void> {
const pubClient = createClient({
url: this.configService.get("redis.url", { infer: true }),
Expand All @@ -27,6 +31,14 @@ export class SocketIOAdapter extends IoAdapter {
this.adapterConstructor = createAdapter(pubClient, subClient);
}

/**
* The function creates an IO server with CORS options and an adapter constructor.
* @param port - The `port` parameter is the port number on which the server will listen for
* incoming connections. It is a number that specifies the port, such as 3000 or 8080.
* @param [options] - The `options` parameter is an optional object that can contain
* additional configuration options for the server. It is of type `ServerOptions`.
* @returns a server object.
*/
createIOServer(port: number, options?: ServerOptions): any {
const cors = {
origin: this.configService.get("app.allowedOrigins", { infer: true }),
Expand Down

0 comments on commit 2dedd0d

Please sign in to comment.