@nestledjs/api 1.0.3 → 1.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestledjs/api",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "generators": "./generators.json",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -62,4 +62,12 @@ export class ConfigService {
62
62
  },
63
63
  }
64
64
  }
65
+
66
+ get prismaOptimizeEnabled(): boolean {
67
+ return this.config.get<boolean>('prisma.optimize.enabled') ?? false
68
+ }
69
+
70
+ get prismaOptimizeApiKey(): string | undefined {
71
+ return this.config.get<string>('prisma.optimize.apiKey')
72
+ }
65
73
  }
@@ -30,4 +30,10 @@ export const configuration = () => ({
30
30
  user: process.env['SMTP_USER'],
31
31
  pass: process.env['SMTP_PASS'],
32
32
  },
33
+ prisma: {
34
+ optimize: {
35
+ enabled: process.env['OPTIMIZE_ENABLED'] === 'true',
36
+ apiKey: process.env['OPTIMIZE_API_KEY'],
37
+ },
38
+ },
33
39
  })
@@ -1,8 +1,10 @@
1
1
  import { Module } from '@nestjs/common'
2
+ import { ConfigModule } from '@<%= npmScope %>/api/config'
2
3
 
3
4
  import { ApiCoreDataAccessService } from './api-core-data-access.service'
4
5
 
5
6
  @Module({
7
+ imports: [ConfigModule],
6
8
  providers: [ApiCoreDataAccessService],
7
9
  exports: [ApiCoreDataAccessService],
8
10
  })
@@ -1,14 +1,14 @@
1
1
  import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'
2
2
  import { Prisma, PrismaClient } from '@<%= npmScope %>/api/prisma'
3
+ import { ConfigService } from '@<%= npmScope %>/api/config'
3
4
  import { CorePagingInput } from './dto/core-paging.input'
4
5
 
5
-
6
6
  @Injectable()
7
7
  export class ApiCoreDataAccessService
8
8
  extends PrismaClient
9
9
  implements OnModuleInit, OnModuleDestroy
10
10
  {
11
- constructor() {
11
+ constructor(private readonly configService: ConfigService) {
12
12
  const config: Prisma.PrismaClientOptions = {
13
13
  datasources: {
14
14
  db: { url: `${process.env['DATABASE_URL']}?connection_limit=30` },
@@ -19,26 +19,25 @@ export class ApiCoreDataAccessService
19
19
  ? [{ emit: 'event', level: 'query' }]
20
20
  : [{ emit: 'event', level: 'warn' }],
21
21
  }
22
+
23
+ // Must call super first before accessing this
22
24
  super(config)
23
25
  this.queryCount = 0
24
26
 
25
- // Only add Prisma Optimize extension in development
26
- if (process.env['OPTIMIZE_API_KEY'] && process.env['USE_OPTIMIZE'] === 'true') {
27
- const apiKey = process.env['OPTIMIZE_API_KEY']
28
- if (!apiKey) {
29
- console.warn('Not Running Prisma Optimize - No API Key Set')
30
- }
27
+ // Check for Prisma Optimize setup using config service
28
+ const optimizeEnabled = configService.prismaOptimizeEnabled
29
+ const optimizeApiKey = configService.prismaOptimizeApiKey
31
30
 
31
+ if (optimizeEnabled && optimizeApiKey) {
32
+ console.log('🚀 Prisma Optimize enabled with API key')
32
33
  const { withOptimize } = require('@prisma/extension-optimize')
33
- const extendedClient = new PrismaClient(config).$extends(withOptimize({ apiKey }))
34
+ const extendedClient = new PrismaClient(config).$extends(
35
+ withOptimize({ apiKey: optimizeApiKey })
36
+ )
34
37
  Object.assign(this, extendedClient)
35
- try {
36
- const { withOptimize } = require('@prisma/extension-optimize')
37
- const extendedClient = new PrismaClient(config).$extends(withOptimize({ apiKey }))
38
- Object.assign(this, extendedClient)
39
- } catch (err) {
40
- console.warn('Not Running Prisma Optimize - @prisma/extension-optimize not installed or failed to load:', err)
41
- }
38
+ } else if (optimizeEnabled && !optimizeApiKey) {
39
+ console.warn('⚠️ OPTIMIZE_ENABLED is true but OPTIMIZE_API_KEY is not set')
40
+ }
42
41
  }
43
42
 
44
43
  public queryCount: number
@@ -1,32 +0,0 @@
1
- export const configuration = () => ({
2
- prefix: 'api',
3
- environment: process.env['NODE_ENV'],
4
- host: process.env['HOST'],
5
- port: parseInt(process.env['PORT'] ?? '3000', 10),
6
- apiUrl: process.env['API_URL'],
7
- api: {
8
- cookie: {
9
- name: process.env['API_COOKIE_NAME'],
10
- options: {
11
- domain: process.env['API_COOKIE_DOMAIN'],
12
- httpOnly: true,
13
- },
14
- },
15
- cors: {
16
- origin: [process.env['WEB_URL']],
17
- },
18
- },
19
- siteUrl: process.env['SITE_URL'] || process.env['API_URL']?.replace('/api', ''),
20
- app: {
21
- email: process.env['APP_EMAIL'],
22
- supportEmail: process.env['APP_SUPPORT_EMAIL'],
23
- adminEmails: process.env['APP_ADMIN_EMAILS'],
24
- name: process.env['APP_NAME'],
25
- },
26
- smtp: {
27
- host: process.env['SMTP_HOST'],
28
- port: process.env['SMTP_PORT'],
29
- user: process.env['SMTP_USER'],
30
- pass: process.env['SMTP_PASS'],
31
- },
32
- })
@@ -1,25 +0,0 @@
1
- import * as Joi from 'joi'
2
-
3
- export const validationSchema = Joi.object({
4
- NODE_ENV: Joi.string().valid('development', 'production', 'test'),
5
- HOST: Joi.string().alphanum().default('localhost'),
6
- PORT: Joi.number().default(3000),
7
- WEB_PORT: Joi.number().default(4200),
8
- WEB_URL: Joi.string().default(
9
- `http://${process.env['HOST'] || 'localhost'}:${process.env['WEB_PORT']}`
10
- ),
11
- API_COOKIE_DOMAIN: Joi.string().default('localhost'),
12
- API_COOKIE_NAME: Joi.string().default('__session'),
13
- API_URL: Joi.string().default(
14
- `http://${process.env['HOST'] || 'localhost'}:${process.env['PORT']}/api`
15
- ),
16
- APP_NAME: Joi.string().required(),
17
- APP_EMAIL: Joi.string().email().required(),
18
- APP_SUPPORT_EMAIL: Joi.string().email().required(),
19
- APP_ADMIN_EMAILS: Joi.string().required(),
20
- SITE_URL: Joi.string().uri().required(),
21
- SMTP_HOST: Joi.string().required(),
22
- SMTP_PORT: Joi.string().required(),
23
- SMTP_USER: Joi.string().required(),
24
- SMTP_PASS: Joi.string().required(),
25
- })