@triproject/nestjs-core 1.0.5 → 1.0.13
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/.swcrc +24 -0
- package/README.md +297 -38
- package/dist/bootstrap.js +1 -43
- package/dist/config.js +1 -50
- package/dist/controllers/controller.js +1 -56
- package/dist/drivers/cache/cache.d.ts +1 -1
- package/dist/drivers/cache/cache.driver.js +1 -22
- package/dist/drivers/cache/cache.js +1 -92
- package/dist/drivers/cache/index.js +1 -19
- package/dist/drivers/cache/redis.js +1 -52
- package/dist/drivers/db/db.helper.js +1 -217
- package/dist/drivers/db/db.module.js +1 -44
- package/dist/drivers/db/db.service.js +1 -49
- package/dist/drivers/db/index.js +1 -21
- package/dist/drivers/db/migration.d.ts +133 -5
- package/dist/drivers/db/migration.js +1 -81
- package/dist/drivers/db/repository.js +1 -255
- package/dist/drivers/encryptions/encryption.js +1 -50
- package/dist/drivers/encryptions/encryption.module.js +1 -24
- package/dist/drivers/encryptions/index.js +1 -19
- package/dist/drivers/encryptions/jwt.js +1 -46
- package/dist/drivers/encryptions/password-hash.js +1 -38
- package/dist/drivers/encryptions/snap.signature.js +1 -110
- package/dist/drivers/logger/app.logger.js +2 -183
- package/dist/drivers/logger/cloudwatch.d.ts +18 -0
- package/dist/drivers/logger/cloudwatch.js +1 -0
- package/dist/drivers/logger/cloudwatch.logger.d.ts +1 -0
- package/dist/drivers/logger/cloudwatch.logger.js +1 -0
- package/dist/drivers/logger/index.js +1 -18
- package/dist/drivers/logger/slack.logger.js +1 -24
- package/dist/drivers/mail/index.js +1 -22
- package/dist/drivers/mail/mail-template.js +8 -41
- package/dist/drivers/mail/mail.config.js +1 -4
- package/dist/drivers/mail/mail.js +13 -73
- package/dist/drivers/mail/mail.module.js +1 -26
- package/dist/drivers/mail/mail.queue.js +1 -37
- package/dist/drivers/mail/mailer.js +1 -62
- package/dist/drivers/notifications/index.js +1 -21
- package/dist/drivers/notifications/notification.config.js +1 -4
- package/dist/drivers/notifications/notification.module.js +1 -25
- package/dist/drivers/notifications/notification.queue.js +1 -37
- package/dist/drivers/notifications/push-notification.js +1 -75
- package/dist/drivers/notifications/slack.js +1 -95
- package/dist/drivers/queues/app.queue.js +1 -66
- package/dist/drivers/queues/index.js +1 -18
- package/dist/drivers/queues/queue.module.js +1 -41
- package/dist/helpers/exception.helper.js +1 -71
- package/dist/helpers/http.helper.js +1 -134
- package/dist/helpers/swagger.helper.js +1 -287
- package/dist/helpers/totp.helper.js +1 -30
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -24
- package/dist/middlewares/log.middleware.js +1 -59
- package/dist/types.d.js +1 -0
- package/package.json +27 -14
package/.swcrc
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/swcrc",
|
|
3
|
+
"jsc": {
|
|
4
|
+
"parser": {
|
|
5
|
+
"syntax": "typescript",
|
|
6
|
+
"decorators": true
|
|
7
|
+
},
|
|
8
|
+
"transform": {
|
|
9
|
+
"decoratorMetadata": true,
|
|
10
|
+
"legacyDecorator": true
|
|
11
|
+
},
|
|
12
|
+
"target": "esnext",
|
|
13
|
+
"keepClassNames": true,
|
|
14
|
+
"minify": {
|
|
15
|
+
"compress": true,
|
|
16
|
+
"mangle": false
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"module": {
|
|
20
|
+
"type": "commonjs"
|
|
21
|
+
},
|
|
22
|
+
"minify": true,
|
|
23
|
+
"sourceMaps": false
|
|
24
|
+
}
|
package/README.md
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
# @triproject/nestjs
|
|
1
|
+
# @triproject/nestjs-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A collection of NestJS modules and utilities to speed up development with built-in support for caching, database access, encryption, logging, mail, notifications, queues, and more.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@triproject/nestjs-core)
|
|
6
|
+
[](https://opensource.org/licenses/ISC)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🚀 **Quick Bootstrap** - Preconfigured NestJS application setup
|
|
11
|
+
- 🔐 **Encryption & Authentication** - JWT, password hashing (PBKDF2), AES-256-GCM encryption, TOTP/2FA
|
|
12
|
+
- 💾 **Database** - Sequelize ORM with TypeScript support
|
|
13
|
+
- 🗄️ **Caching** - Redis integration with helpers
|
|
14
|
+
- 📧 **Email** - Nodemailer with queue support
|
|
15
|
+
- 🔔 **Notifications** - Push notifications and Slack integration
|
|
16
|
+
- ⚡ **Queue Management** - Bull and BullMQ support
|
|
17
|
+
- 📝 **Logging** - Structured logging with Slack alerts
|
|
18
|
+
- 🎨 **Swagger** - API documentation helpers
|
|
19
|
+
- 🔌 **Modular** - Import only what you need
|
|
4
20
|
|
|
5
21
|
## Installation
|
|
6
22
|
|
|
7
23
|
```bash
|
|
8
|
-
npm install @triproject/nestjs
|
|
24
|
+
npm install @triproject/nestjs-core
|
|
9
25
|
```
|
|
10
26
|
|
|
11
27
|
## Modular Imports
|
|
@@ -15,36 +31,82 @@ This package uses subpath exports to avoid loading unnecessary dependencies. Imp
|
|
|
15
31
|
### Bootstrap (Core)
|
|
16
32
|
|
|
17
33
|
```typescript
|
|
18
|
-
import { bootstrap } from '@triproject/nestjs/bootstrap';
|
|
19
|
-
import { APP_PORT, APP_KEY } from '@triproject/nestjs/config';
|
|
34
|
+
import { bootstrap } from '@triproject/nestjs-core/bootstrap';
|
|
35
|
+
import { APP_PORT, APP_KEY } from '@triproject/nestjs-core/config';
|
|
20
36
|
```
|
|
21
37
|
|
|
22
|
-
Required peer dependencies
|
|
38
|
+
**Required peer dependencies:**
|
|
39
|
+
|
|
40
|
+
- `@nestjs/common` (^11.0.0)
|
|
41
|
+
- `@nestjs/core` (^11.0.0)
|
|
42
|
+
- `express` (^4.0.0 || ^5.0.0)
|
|
43
|
+
- `helmet` (^7.0.0 || ^8.0.0)
|
|
44
|
+
- `cookie-parser` (^1.4.0)
|
|
45
|
+
- `class-validator` (^0.14.0)
|
|
46
|
+
- `dotenv` (^16.0.0 || ^17.0.0)
|
|
47
|
+
|
|
48
|
+
### Configuration
|
|
23
49
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
50
|
+
```typescript
|
|
51
|
+
import {
|
|
52
|
+
APP_NAME,
|
|
53
|
+
APP_PORT,
|
|
54
|
+
APP_KEY,
|
|
55
|
+
DB_HOST,
|
|
56
|
+
DB_PORT,
|
|
57
|
+
REDIS_HOST,
|
|
58
|
+
REDIS_PORT,
|
|
59
|
+
// ... and more
|
|
60
|
+
} from '@triproject/nestjs-core/config';
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
All environment variables are pre-configured with sensible defaults.
|
|
30
64
|
|
|
31
65
|
### Cache (Redis)
|
|
32
66
|
|
|
33
67
|
```typescript
|
|
34
|
-
import { AppCache, Redis, CacheModule } from '@triproject/nestjs/cache';
|
|
68
|
+
import { AppCache, Redis, CacheModule } from '@triproject/nestjs-core/cache';
|
|
69
|
+
|
|
70
|
+
// In your module
|
|
71
|
+
@Module({
|
|
72
|
+
imports: [CacheModule],
|
|
73
|
+
})
|
|
74
|
+
export class AppModule {}
|
|
75
|
+
|
|
76
|
+
// In your service
|
|
77
|
+
constructor(private cache: AppCache) {}
|
|
78
|
+
|
|
79
|
+
async cacheData() {
|
|
80
|
+
await this.cache.set('key', { data: 'value' }, 3600);
|
|
81
|
+
const data = await this.cache.get<{ data: string }>('key');
|
|
82
|
+
await this.cache.delete('key');
|
|
83
|
+
}
|
|
35
84
|
```
|
|
36
85
|
|
|
37
|
-
Required peer dependencies
|
|
86
|
+
**Required peer dependencies:**
|
|
38
87
|
|
|
39
88
|
- `redis` (^4.0.0 || ^5.0.0)
|
|
40
89
|
|
|
41
90
|
### Database (Sequelize)
|
|
42
91
|
|
|
43
92
|
```typescript
|
|
44
|
-
import { DatabaseModule, Repository } from '@triproject/nestjs/db';
|
|
93
|
+
import { DatabaseModule, Repository } from '@triproject/nestjs-core/db';
|
|
94
|
+
|
|
95
|
+
// In your module
|
|
96
|
+
@Module({
|
|
97
|
+
imports: [DatabaseModule],
|
|
98
|
+
})
|
|
99
|
+
export class AppModule {}
|
|
100
|
+
|
|
101
|
+
// Base repository with pagination and common queries
|
|
102
|
+
export class UserRepository extends Repository<UserModel> {
|
|
103
|
+
constructor() {
|
|
104
|
+
super(UserModel);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
45
107
|
```
|
|
46
108
|
|
|
47
|
-
Required peer dependencies
|
|
109
|
+
**Required peer dependencies:**
|
|
48
110
|
|
|
49
111
|
- `sequelize` (^6.0.0)
|
|
50
112
|
- `sequelize-typescript` (^2.0.0)
|
|
@@ -53,28 +115,73 @@ Required peer dependencies:
|
|
|
53
115
|
### Encryption & JWT
|
|
54
116
|
|
|
55
117
|
```typescript
|
|
56
|
-
import { PasswordHash, Jwt, EncryptionModule } from '@triproject/nestjs/encryption';
|
|
118
|
+
import { PasswordHash, Jwt, Encryption, EncryptionModule } from '@triproject/nestjs-core/encryption';
|
|
119
|
+
|
|
120
|
+
// Password hashing
|
|
121
|
+
const hash = passwordHash.sign('myPassword');
|
|
122
|
+
const isValid = passwordHash.verify('myPassword', hash);
|
|
123
|
+
|
|
124
|
+
// JWT tokens
|
|
125
|
+
const token = jwt.sign({ userId: 123 }, 3600);
|
|
126
|
+
const decoded = jwt.verify<{ userId: number }>(token);
|
|
127
|
+
|
|
128
|
+
// AES-256-GCM encryption
|
|
129
|
+
const encrypted = encryption.encrypt('sensitive data');
|
|
130
|
+
const decrypted = encryption.decrypt(encrypted);
|
|
57
131
|
```
|
|
58
132
|
|
|
59
|
-
Required peer dependencies
|
|
133
|
+
**Required peer dependencies:**
|
|
60
134
|
|
|
61
135
|
- `jsonwebtoken` (^9.0.0)
|
|
62
136
|
|
|
137
|
+
**Features:**
|
|
138
|
+
|
|
139
|
+
- PBKDF2 password hashing with SHA-512
|
|
140
|
+
- RS512 JWT tokens
|
|
141
|
+
- AES-256-GCM encryption
|
|
142
|
+
- Native Node.js crypto (no external dependencies)
|
|
143
|
+
|
|
63
144
|
### Logger
|
|
64
145
|
|
|
65
146
|
```typescript
|
|
66
|
-
import { AppLogger, SlackLogger } from '@triproject/nestjs/logger';
|
|
147
|
+
import { AppLogger, SlackLogger } from '@triproject/nestjs-core/logger';
|
|
148
|
+
|
|
149
|
+
const logger = new AppLogger('MyService');
|
|
150
|
+
logger.log('Info message');
|
|
151
|
+
logger.error('Error message', error);
|
|
152
|
+
logger.warn('Warning message');
|
|
153
|
+
logger.debug('Debug message');
|
|
154
|
+
|
|
155
|
+
// Slack integration
|
|
156
|
+
const slackLogger = new SlackLogger();
|
|
157
|
+
await slackLogger.error('Critical error', error);
|
|
67
158
|
```
|
|
68
159
|
|
|
69
|
-
|
|
160
|
+
**Required peer dependencies:**
|
|
161
|
+
|
|
162
|
+
- `axios` (^1.0.0)
|
|
163
|
+
- `lodash` (^4.17.0)
|
|
164
|
+
- `moment` (^2.30.0)
|
|
70
165
|
|
|
71
166
|
### Mail
|
|
72
167
|
|
|
73
168
|
```typescript
|
|
74
|
-
import { MailModule, Mailer } from '@triproject/nestjs/mail';
|
|
169
|
+
import { MailModule, Mailer } from '@triproject/nestjs-core/mail';
|
|
170
|
+
|
|
171
|
+
@Module({
|
|
172
|
+
imports: [MailModule],
|
|
173
|
+
})
|
|
174
|
+
export class AppModule {}
|
|
175
|
+
|
|
176
|
+
// Send email
|
|
177
|
+
await mailer.send({
|
|
178
|
+
to: 'user@example.com',
|
|
179
|
+
subject: 'Welcome',
|
|
180
|
+
html: '<p>Welcome to our app!</p>',
|
|
181
|
+
});
|
|
75
182
|
```
|
|
76
183
|
|
|
77
|
-
Required peer dependencies
|
|
184
|
+
**Required peer dependencies:**
|
|
78
185
|
|
|
79
186
|
- `nodemailer` (^6.0.0 || ^7.0.0)
|
|
80
187
|
- `@nestjs/bull` (^11.0.0)
|
|
@@ -83,10 +190,22 @@ Required peer dependencies:
|
|
|
83
190
|
### Notifications
|
|
84
191
|
|
|
85
192
|
```typescript
|
|
86
|
-
import { NotificationModule, PushNotification } from '@triproject/nestjs/notifications';
|
|
193
|
+
import { NotificationModule, PushNotification } from '@triproject/nestjs-core/notifications';
|
|
194
|
+
|
|
195
|
+
@Module({
|
|
196
|
+
imports: [NotificationModule],
|
|
197
|
+
})
|
|
198
|
+
export class AppModule {}
|
|
199
|
+
|
|
200
|
+
// Send push notification
|
|
201
|
+
await pushNotification.send({
|
|
202
|
+
playerIds: ['user-id'],
|
|
203
|
+
title: 'New Message',
|
|
204
|
+
message: 'You have a new message',
|
|
205
|
+
});
|
|
87
206
|
```
|
|
88
207
|
|
|
89
|
-
Required peer dependencies
|
|
208
|
+
**Required peer dependencies:**
|
|
90
209
|
|
|
91
210
|
- `@nestjs/bull` (^11.0.0)
|
|
92
211
|
- `bull` (^4.0.0)
|
|
@@ -94,10 +213,24 @@ Required peer dependencies:
|
|
|
94
213
|
### Queues (BullMQ)
|
|
95
214
|
|
|
96
215
|
```typescript
|
|
97
|
-
import { QueueModule, AppQueue } from '@triproject/nestjs/queues';
|
|
216
|
+
import { QueueModule, AppQueue } from '@triproject/nestjs-core/queues';
|
|
217
|
+
|
|
218
|
+
@Module({
|
|
219
|
+
imports: [QueueModule],
|
|
220
|
+
})
|
|
221
|
+
export class AppModule {}
|
|
222
|
+
|
|
223
|
+
// Create queue processor
|
|
224
|
+
@Processor('myQueue')
|
|
225
|
+
export class MyQueue extends AppQueue {
|
|
226
|
+
@Process('job-name')
|
|
227
|
+
async processJob(job: Job) {
|
|
228
|
+
// Process job
|
|
229
|
+
}
|
|
230
|
+
}
|
|
98
231
|
```
|
|
99
232
|
|
|
100
|
-
Required peer dependencies
|
|
233
|
+
**Required peer dependencies:**
|
|
101
234
|
|
|
102
235
|
- `@nestjs/bullmq` (^11.0.0)
|
|
103
236
|
- `bullmq` (^5.0.0)
|
|
@@ -105,36 +238,162 @@ Required peer dependencies:
|
|
|
105
238
|
### Helpers
|
|
106
239
|
|
|
107
240
|
```typescript
|
|
108
|
-
import {
|
|
241
|
+
import {
|
|
242
|
+
CatchError,
|
|
243
|
+
TransformResponseInterceptor,
|
|
244
|
+
totp,
|
|
245
|
+
SwaggerApiPaginateResponse,
|
|
246
|
+
} from '@triproject/nestjs-core/helpers';
|
|
247
|
+
|
|
248
|
+
// Error handling decorator
|
|
249
|
+
class MyService {
|
|
250
|
+
@CatchError('Operation failed')
|
|
251
|
+
async myMethod() {
|
|
252
|
+
// Automatically catches and transforms errors
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// TOTP/2FA
|
|
257
|
+
const { secret, qrCodeBase64 } = await totp.generateSecret({
|
|
258
|
+
email: 'user@example.com',
|
|
259
|
+
issuer: 'MyApp',
|
|
260
|
+
});
|
|
261
|
+
const isValid = totp.verify(secret, '123456');
|
|
262
|
+
|
|
263
|
+
// Swagger decorators
|
|
264
|
+
@SwaggerApiPaginateResponse(UserDto)
|
|
265
|
+
async getUsers() {
|
|
266
|
+
// Returns paginated response with Swagger docs
|
|
267
|
+
}
|
|
109
268
|
```
|
|
110
269
|
|
|
111
|
-
Required peer dependencies for TOTP
|
|
270
|
+
**Required peer dependencies (for TOTP):**
|
|
112
271
|
|
|
113
272
|
- `speakeasy` (^2.0.0)
|
|
114
273
|
- `qrcode` (^1.5.0)
|
|
115
274
|
|
|
116
|
-
## Usage Example
|
|
275
|
+
## Complete Usage Example
|
|
117
276
|
|
|
118
277
|
```typescript
|
|
278
|
+
// main.ts
|
|
279
|
+
import { bootstrap } from '@triproject/nestjs-core/bootstrap';
|
|
280
|
+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
281
|
+
import { AppModule } from './app.module';
|
|
282
|
+
|
|
283
|
+
const setupSwagger = (app) => {
|
|
284
|
+
const config = new DocumentBuilder().setTitle('My API').setVersion('1.0').build();
|
|
285
|
+
const document = SwaggerModule.createDocument(app, config);
|
|
286
|
+
SwaggerModule.setup('docs', app, document);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
bootstrap(AppModule, setupSwagger);
|
|
290
|
+
|
|
119
291
|
// app.module.ts
|
|
120
292
|
import { Module } from '@nestjs/common';
|
|
121
|
-
import { CacheModule } from '@triproject/nestjs/cache';
|
|
122
|
-
import { DatabaseModule } from '@triproject/nestjs/db';
|
|
123
|
-
import { EncryptionModule } from '@triproject/nestjs/encryption';
|
|
293
|
+
import { CacheModule } from '@triproject/nestjs-core/cache';
|
|
294
|
+
import { DatabaseModule } from '@triproject/nestjs-core/db';
|
|
295
|
+
import { EncryptionModule } from '@triproject/nestjs-core/encryption';
|
|
296
|
+
import { MailModule } from '@triproject/nestjs-core/mail';
|
|
124
297
|
|
|
125
298
|
@Module({
|
|
126
|
-
imports: [CacheModule,
|
|
299
|
+
imports: [DatabaseModule, CacheModule, EncryptionModule, MailModule],
|
|
127
300
|
})
|
|
128
301
|
export class AppModule {}
|
|
129
302
|
|
|
130
|
-
//
|
|
131
|
-
import {
|
|
132
|
-
import {
|
|
133
|
-
import {
|
|
303
|
+
// user.service.ts
|
|
304
|
+
import { Injectable } from '@nestjs/common';
|
|
305
|
+
import { AppCache } from '@triproject/nestjs-core/cache';
|
|
306
|
+
import { PasswordHash, Jwt } from '@triproject/nestjs-core/encryption';
|
|
134
307
|
|
|
135
|
-
|
|
308
|
+
@Injectable()
|
|
309
|
+
export class UserService {
|
|
310
|
+
constructor(private cache: AppCache, private passwordHash: PasswordHash, private jwt: Jwt) {}
|
|
311
|
+
|
|
312
|
+
async login(email: string, password: string) {
|
|
313
|
+
// Get user from cache or database
|
|
314
|
+
const user = await this.cache.get(`user:${email}`);
|
|
315
|
+
|
|
316
|
+
// Verify password
|
|
317
|
+
const isValid = this.passwordHash.verify(password, user.password);
|
|
318
|
+
if (!isValid) throw new Error('Invalid credentials');
|
|
319
|
+
|
|
320
|
+
// Generate JWT token
|
|
321
|
+
const token = this.jwt.sign({ userId: user.id }, 86400);
|
|
322
|
+
|
|
323
|
+
return { token };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Environment Variables
|
|
329
|
+
|
|
330
|
+
All configuration is done through environment variables. Create a `.env` file:
|
|
331
|
+
|
|
332
|
+
```env
|
|
333
|
+
# App
|
|
334
|
+
APP_NAME=MyApp
|
|
335
|
+
APP_PORT=3000
|
|
336
|
+
APP_KEY=your-app-secret-key
|
|
337
|
+
|
|
338
|
+
# Database
|
|
339
|
+
DB_HOST=localhost
|
|
340
|
+
DB_PORT=5432
|
|
341
|
+
DB_USER=postgres
|
|
342
|
+
DB_PASSWORD=password
|
|
343
|
+
DB_NAME=mydb
|
|
344
|
+
|
|
345
|
+
# Redis
|
|
346
|
+
REDIS_HOST=localhost
|
|
347
|
+
REDIS_PORT=6379
|
|
348
|
+
REDIS_PASSWORD=
|
|
349
|
+
|
|
350
|
+
# JWT
|
|
351
|
+
JWT_PUBLIC_KEY=your-rsa-public-key
|
|
352
|
+
JWT_PRIVATE_KEY=your-rsa-private-key
|
|
353
|
+
|
|
354
|
+
# Encryption
|
|
355
|
+
PASSWORD_HASH_SECRET=your-hash-secret
|
|
356
|
+
ENCRYPTION_KEY=your-aes-256-key
|
|
357
|
+
|
|
358
|
+
# Mail
|
|
359
|
+
MAIL_HOST=smtp.gmail.com
|
|
360
|
+
MAIL_PORT=587
|
|
361
|
+
MAIL_USERNAME=your-email
|
|
362
|
+
MAIL_PASSWORD=your-password
|
|
363
|
+
|
|
364
|
+
# Slack
|
|
365
|
+
SLACK_ERROR_WEBHOOK_URL=your-slack-webhook
|
|
366
|
+
|
|
367
|
+
# OneSignal
|
|
368
|
+
ONESIGNAL_APP_ID=your-app-id
|
|
369
|
+
ONESIGNAL_REST_API_KEY=your-api-key
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## Testing
|
|
373
|
+
|
|
374
|
+
This package includes comprehensive test coverage:
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
npm test
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## Development
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
# Install dependencies
|
|
384
|
+
npm install
|
|
385
|
+
|
|
386
|
+
# Build
|
|
387
|
+
npm run build
|
|
388
|
+
|
|
389
|
+
# Run tests
|
|
390
|
+
npm test
|
|
136
391
|
```
|
|
137
392
|
|
|
138
393
|
## License
|
|
139
394
|
|
|
140
395
|
ISC
|
|
396
|
+
|
|
397
|
+
## Contributing
|
|
398
|
+
|
|
399
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/dist/bootstrap.js
CHANGED
|
@@ -1,43 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.bootstrap = bootstrap;
|
|
7
|
-
const common_1 = require("@nestjs/common");
|
|
8
|
-
const core_1 = require("@nestjs/core");
|
|
9
|
-
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
10
|
-
const helmet_1 = __importDefault(require("helmet"));
|
|
11
|
-
const config_1 = require("./config");
|
|
12
|
-
const app_logger_1 = require("./drivers/logger/app.logger");
|
|
13
|
-
const http_helper_1 = require("./helpers/http.helper");
|
|
14
|
-
async function bootstrap(module, swaggerSetup) {
|
|
15
|
-
const logger = new app_logger_1.AppLogger(`Bootstrap App`);
|
|
16
|
-
const app = await core_1.NestFactory.create(module, { rawBody: true, logger });
|
|
17
|
-
app.use((0, cookie_parser_1.default)());
|
|
18
|
-
app.useGlobalPipes(new common_1.ValidationPipe({
|
|
19
|
-
skipMissingProperties: true,
|
|
20
|
-
whitelist: true,
|
|
21
|
-
transform: true,
|
|
22
|
-
transformOptions: {
|
|
23
|
-
enableImplicitConversion: true,
|
|
24
|
-
},
|
|
25
|
-
}));
|
|
26
|
-
app.use((0, helmet_1.default)());
|
|
27
|
-
app.useGlobalFilters(new http_helper_1.HttpExceptionFilter());
|
|
28
|
-
app.useGlobalInterceptors(new http_helper_1.TransformResponseInterceptor());
|
|
29
|
-
app.enableCors({
|
|
30
|
-
origin: config_1.ALLOWED_ORIGINS,
|
|
31
|
-
credentials: true,
|
|
32
|
-
});
|
|
33
|
-
if (swaggerSetup)
|
|
34
|
-
swaggerSetup(app);
|
|
35
|
-
await app
|
|
36
|
-
.listen(config_1.APP_PORT)
|
|
37
|
-
.then(() => {
|
|
38
|
-
logger.log(`Server started on port ${config_1.APP_PORT}`);
|
|
39
|
-
if (swaggerSetup)
|
|
40
|
-
logger.log(`Swagger docs available at http://localhost:${config_1.APP_PORT}/docs`);
|
|
41
|
-
})
|
|
42
|
-
.catch((error) => logger.error('Failed to start server', error));
|
|
43
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"bootstrap",{enumerable:!0,get:function(){return bootstrap}});let _common=require("@nestjs/common"),_core=require("@nestjs/core"),_cookieparser=/*#__PURE__*/_interop_require_default(require("cookie-parser")),_helmet=/*#__PURE__*/_interop_require_default(require("helmet")),_config=require("./config"),_applogger=require("./drivers/logger/app.logger"),_httphelper=require("./helpers/http.helper");function _interop_require_default(obj){return obj&&obj.__esModule?obj:{default:obj}}async function bootstrap(module,swaggerSetup){let logger=new _applogger.AppLogger("Bootstrap App"),app=await _core.NestFactory.create(module,{rawBody:!0,logger});app.use((0,_cookieparser.default)()),app.useGlobalPipes(new _common.ValidationPipe({skipMissingProperties:!0,whitelist:!0,transform:!0,transformOptions:{enableImplicitConversion:!0}})),app.use((0,_helmet.default)()),app.useGlobalFilters(new _httphelper.HttpExceptionFilter),app.useGlobalInterceptors(new _httphelper.TransformResponseInterceptor),app.enableCors({origin:_config.ALLOWED_ORIGINS,credentials:!0}),swaggerSetup&&swaggerSetup(app),await app.listen(_config.APP_PORT).then(()=>{logger.log(`Server started on port ${_config.APP_PORT}`),swaggerSetup&&logger.log(`Swagger docs available at http://localhost:${_config.APP_PORT}/docs`)}).catch(error=>logger.error("Failed to start server",error))}
|
package/dist/config.js
CHANGED
|
@@ -1,50 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ONESIGNAL_REST_API_KEY = exports.ONESIGNAL_APP_ID = exports.APP_LOGO_URL = exports.LANDING_PAGE_URL = exports.SLACK_ERROR_WEBHOOK_URL = exports.MAIL_EMAIL_SUPPORT = exports.MAIL_TO_CC = exports.MAIL_FROM_EMAIL = exports.MAIL_FROM_NAME = exports.MAIL_ENCRYPTION = exports.MAIL_PASSWORD = exports.MAIL_USERNAME = exports.MAIL_PORT = exports.MAIL_HOST = exports.MAIL_MAILER = exports.REDIS_TLS = exports.REDIS_PASSWORD = exports.REDIS_DB = exports.REDIS_PORT = exports.REDIS_HOST = exports.DB_ENTITIES_PATH = exports.DB_POOL_IDLE = exports.DB_POOL_ACQUIRE = exports.DB_POOL_MIN = exports.DB_MAX_POOL_SIZE = exports.DB_SSL = exports.DB_REPLICA_PORT = exports.DB_REPLICA_HOST = exports.DB_NAME = exports.DB_PASSWORD = exports.DB_USER = exports.DB_PORT = exports.DB_HOST = exports.DB_DIALECT = exports.JWT_PRIVATE_KEY = exports.JWT_PUBLIC_KEY = exports.ENCRYPTION_KEY = exports.PASSWORD_HASH_SECRET = exports.ALLOWED_ORIGINS = exports.SESSION_EXPIRATION = exports.SESSION_KEY = exports.APP_KEY = exports.APP_PORT = exports.APP_NAME = exports.NODE_ENV = void 0;
|
|
4
|
-
const dotenv_1 = require("dotenv");
|
|
5
|
-
(0, dotenv_1.config)({ quiet: true });
|
|
6
|
-
exports.NODE_ENV = process.env.NODE_ENV ?? 'development';
|
|
7
|
-
exports.APP_NAME = process.env.APP_NAME ?? 'MyApp';
|
|
8
|
-
exports.APP_PORT = Number(process.env.APP_PORT) ?? 3000;
|
|
9
|
-
exports.APP_KEY = process.env.APP_KEY ?? '';
|
|
10
|
-
exports.SESSION_KEY = process.env.SESSION_KEY ?? 'APP_SESSION';
|
|
11
|
-
exports.SESSION_EXPIRATION = Number(process.env.SESSION_EXPIRATION) ?? 86400;
|
|
12
|
-
exports.ALLOWED_ORIGINS = (process.env.ALLOWED_ORIGINS ?? 'http://localhost:3000').split(',');
|
|
13
|
-
exports.PASSWORD_HASH_SECRET = process.env.PASSWORD_HASH_SECRET ?? 'default_secret';
|
|
14
|
-
exports.ENCRYPTION_KEY = process.env.ENCRYPTION_KEY;
|
|
15
|
-
exports.JWT_PUBLIC_KEY = process.env.JWT_PUBLIC_KEY ?? '';
|
|
16
|
-
exports.JWT_PRIVATE_KEY = process.env.JWT_PRIVATE_KEY ?? '';
|
|
17
|
-
exports.DB_DIALECT = 'postgres';
|
|
18
|
-
exports.DB_HOST = process.env.DB_HOST ?? 'localhost';
|
|
19
|
-
exports.DB_PORT = Number(process.env.DB_PORT) ?? 5432;
|
|
20
|
-
exports.DB_USER = process.env.DB_USER ?? 'postgres';
|
|
21
|
-
exports.DB_PASSWORD = process.env.DB_PASSWORD ?? 'password';
|
|
22
|
-
exports.DB_NAME = process.env.DB_NAME ?? 'postgres';
|
|
23
|
-
exports.DB_REPLICA_HOST = process.env.DB_REPLICA_HOST ?? 'localhost';
|
|
24
|
-
exports.DB_REPLICA_PORT = Number(process.env.DB_REPLICA_PORT) ?? 5432;
|
|
25
|
-
exports.DB_SSL = (process.env.DB_SSL ?? 'false')?.toLowerCase() === 'true';
|
|
26
|
-
exports.DB_MAX_POOL_SIZE = Number(process.env.DB_MAX_POOL_SIZE ?? 10);
|
|
27
|
-
exports.DB_POOL_MIN = Number(process.env.DB_POOL_MIN ?? 0);
|
|
28
|
-
exports.DB_POOL_ACQUIRE = Number(process.env.DB_POOL_ACQUIRE ?? 30000);
|
|
29
|
-
exports.DB_POOL_IDLE = Number(process.env.DB_POOL_IDLE ?? 10000);
|
|
30
|
-
exports.DB_ENTITIES_PATH = './dist/**/**/*.entity.*';
|
|
31
|
-
exports.REDIS_HOST = process.env.REDIS_HOST ?? 'localhost';
|
|
32
|
-
exports.REDIS_PORT = Number(process.env.REDIS_PORT) ?? 6379;
|
|
33
|
-
exports.REDIS_DB = Number(process.env.REDIS_DB) ?? 0;
|
|
34
|
-
exports.REDIS_PASSWORD = process.env.REDIS_PASSWORD ?? '';
|
|
35
|
-
exports.REDIS_TLS = (process.env.REDIS_TLS ?? 'false')?.toLowerCase() === 'true';
|
|
36
|
-
exports.MAIL_MAILER = process.env.MAIL_MAILER ?? 'smtp';
|
|
37
|
-
exports.MAIL_HOST = process.env.MAIL_HOST ?? '127.0.0.1';
|
|
38
|
-
exports.MAIL_PORT = +(process.env.MAIL_PORT ?? 1025);
|
|
39
|
-
exports.MAIL_USERNAME = process.env.MAIL_USERNAME ?? '';
|
|
40
|
-
exports.MAIL_PASSWORD = process.env.MAIL_PASSWORD ?? '';
|
|
41
|
-
exports.MAIL_ENCRYPTION = (process.env.MAIL_ENCRYPTION ?? 'false');
|
|
42
|
-
exports.MAIL_FROM_NAME = process.env.MAIL_FROM_NAME ?? 'Support Team';
|
|
43
|
-
exports.MAIL_FROM_EMAIL = process.env.MAIL_FROM_EMAIL ?? 'no-reply@app.com';
|
|
44
|
-
exports.MAIL_TO_CC = process.env.MAIL_TO_CC ?? '';
|
|
45
|
-
exports.MAIL_EMAIL_SUPPORT = process.env.MAIL_EMAIL_SUPPORT ?? 'support@app.com';
|
|
46
|
-
exports.SLACK_ERROR_WEBHOOK_URL = process.env.SLACK_ERROR_WEBHOOK_URL ?? '';
|
|
47
|
-
exports.LANDING_PAGE_URL = process.env.LANDING_PAGE_URL ?? 'http://localhost:8000';
|
|
48
|
-
exports.APP_LOGO_URL = process.env.APP_LOGO_URL ?? '';
|
|
49
|
-
exports.ONESIGNAL_APP_ID = process.env.ONESIGNAL_APP_ID ?? '';
|
|
50
|
-
exports.ONESIGNAL_REST_API_KEY = process.env.ONESIGNAL_REST_API_KEY ?? '';
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var target=exports,all={get ALLOWED_ORIGINS(){return ALLOWED_ORIGINS},get APP_KEY(){return APP_KEY},get APP_LOGO_URL(){return APP_LOGO_URL},get APP_NAME(){return APP_NAME},get APP_PORT(){return APP_PORT},get DB_DIALECT(){return DB_DIALECT},get DB_ENTITIES_PATH(){return DB_ENTITIES_PATH},get DB_HOST(){return DB_HOST},get DB_MAX_POOL_SIZE(){return DB_MAX_POOL_SIZE},get DB_NAME(){return DB_NAME},get DB_PASSWORD(){return DB_PASSWORD},get DB_POOL_ACQUIRE(){return DB_POOL_ACQUIRE},get DB_POOL_IDLE(){return DB_POOL_IDLE},get DB_POOL_MIN(){return DB_POOL_MIN},get DB_PORT(){return DB_PORT},get DB_REPLICA_HOST(){return DB_REPLICA_HOST},get DB_REPLICA_PORT(){return DB_REPLICA_PORT},get DB_SSL(){return DB_SSL},get DB_USER(){return DB_USER},get ENCRYPTION_KEY(){return ENCRYPTION_KEY},get JWT_PRIVATE_KEY(){return JWT_PRIVATE_KEY},get JWT_PUBLIC_KEY(){return JWT_PUBLIC_KEY},get LANDING_PAGE_URL(){return LANDING_PAGE_URL},get MAIL_EMAIL_SUPPORT(){return MAIL_EMAIL_SUPPORT},get MAIL_ENCRYPTION(){return MAIL_ENCRYPTION},get MAIL_FROM_EMAIL(){return MAIL_FROM_EMAIL},get MAIL_FROM_NAME(){return MAIL_FROM_NAME},get MAIL_HOST(){return MAIL_HOST},get MAIL_MAILER(){return MAIL_MAILER},get MAIL_PASSWORD(){return MAIL_PASSWORD},get MAIL_PORT(){return MAIL_PORT},get MAIL_TO_CC(){return MAIL_TO_CC},get MAIL_USERNAME(){return MAIL_USERNAME},get NODE_ENV(){return NODE_ENV},get ONESIGNAL_APP_ID(){return ONESIGNAL_APP_ID},get ONESIGNAL_REST_API_KEY(){return ONESIGNAL_REST_API_KEY},get PASSWORD_HASH_SECRET(){return PASSWORD_HASH_SECRET},get REDIS_DB(){return REDIS_DB},get REDIS_HOST(){return REDIS_HOST},get REDIS_PASSWORD(){return REDIS_PASSWORD},get REDIS_PORT(){return REDIS_PORT},get REDIS_TLS(){return REDIS_TLS},get SESSION_EXPIRATION(){return SESSION_EXPIRATION},get SESSION_KEY(){return SESSION_KEY},get SLACK_ERROR_WEBHOOK_URL(){return SLACK_ERROR_WEBHOOK_URL}};for(var name in all)Object.defineProperty(target,name,{enumerable:!0,get:Object.getOwnPropertyDescriptor(all,name).get});(0,require("dotenv").config)({quiet:!0});let NODE_ENV=process.env.NODE_ENV??"development",APP_NAME=process.env.APP_NAME??"MyApp",APP_PORT=Number(process.env.APP_PORT)??3e3,APP_KEY=process.env.APP_KEY??"",SESSION_KEY=process.env.SESSION_KEY??"APP_SESSION",SESSION_EXPIRATION=Number(process.env.SESSION_EXPIRATION)??86400,ALLOWED_ORIGINS=(process.env.ALLOWED_ORIGINS??"http://localhost:3000").split(","),PASSWORD_HASH_SECRET=process.env.PASSWORD_HASH_SECRET??"default_secret",ENCRYPTION_KEY=process.env.ENCRYPTION_KEY,JWT_PUBLIC_KEY=process.env.JWT_PUBLIC_KEY??"",JWT_PRIVATE_KEY=process.env.JWT_PRIVATE_KEY??"",DB_DIALECT="postgres",DB_HOST=process.env.DB_HOST??"localhost",DB_PORT=Number(process.env.DB_PORT)??5432,DB_USER=process.env.DB_USER??"postgres",DB_PASSWORD=process.env.DB_PASSWORD??"password",DB_NAME=process.env.DB_NAME??"postgres",DB_REPLICA_HOST=process.env.DB_REPLICA_HOST??"localhost",DB_REPLICA_PORT=Number(process.env.DB_REPLICA_PORT)??5432,DB_SSL=(process.env.DB_SSL??"false")?.toLowerCase()==="true",DB_MAX_POOL_SIZE=Number(process.env.DB_MAX_POOL_SIZE??10),DB_POOL_MIN=Number(process.env.DB_POOL_MIN??0),DB_POOL_ACQUIRE=Number(process.env.DB_POOL_ACQUIRE??3e4),DB_POOL_IDLE=Number(process.env.DB_POOL_IDLE??1e4),DB_ENTITIES_PATH="./dist/**/**/*.entity.*",REDIS_HOST=process.env.REDIS_HOST??"localhost",REDIS_PORT=Number(process.env.REDIS_PORT)??6379,REDIS_DB=Number(process.env.REDIS_DB)??0,REDIS_PASSWORD=process.env.REDIS_PASSWORD??"",REDIS_TLS=(process.env.REDIS_TLS??"false")?.toLowerCase()==="true",MAIL_MAILER=process.env.MAIL_MAILER??"smtp",MAIL_HOST=process.env.MAIL_HOST??"127.0.0.1",MAIL_PORT=+(process.env.MAIL_PORT??1025),MAIL_USERNAME=process.env.MAIL_USERNAME??"",MAIL_PASSWORD=process.env.MAIL_PASSWORD??"",MAIL_ENCRYPTION=process.env.MAIL_ENCRYPTION??"false",MAIL_FROM_NAME=process.env.MAIL_FROM_NAME??"Support Team",MAIL_FROM_EMAIL=process.env.MAIL_FROM_EMAIL??"no-reply@app.com",MAIL_TO_CC=process.env.MAIL_TO_CC??"",MAIL_EMAIL_SUPPORT=process.env.MAIL_EMAIL_SUPPORT??"support@app.com",SLACK_ERROR_WEBHOOK_URL=process.env.SLACK_ERROR_WEBHOOK_URL??"",LANDING_PAGE_URL=process.env.LANDING_PAGE_URL??"http://localhost:8000",APP_LOGO_URL=process.env.APP_LOGO_URL??"",ONESIGNAL_APP_ID=process.env.ONESIGNAL_APP_ID??"",ONESIGNAL_REST_API_KEY=process.env.ONESIGNAL_REST_API_KEY??"";
|
|
@@ -1,56 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AppController = void 0;
|
|
13
|
-
const common_1 = require("@nestjs/common");
|
|
14
|
-
const core_1 = require("@nestjs/core");
|
|
15
|
-
const helpers_1 = require("@triproject/helpers");
|
|
16
|
-
const cache_1 = require("../drivers/cache");
|
|
17
|
-
const swagger_helper_1 = require("../helpers/swagger.helper");
|
|
18
|
-
let AppController = class AppController {
|
|
19
|
-
req;
|
|
20
|
-
appCache;
|
|
21
|
-
_cacheKey() {
|
|
22
|
-
const keys = [this.constructor.name, this.req.path, this.req.method];
|
|
23
|
-
if (this.req.query && Object.keys(this.req.query).length) {
|
|
24
|
-
keys.push((0, helpers_1.qs)(this.req.query));
|
|
25
|
-
}
|
|
26
|
-
if (this.req.body && Object.keys(this.req.body).length) {
|
|
27
|
-
keys.push((0, helpers_1.qs)(this.req.body));
|
|
28
|
-
}
|
|
29
|
-
return keys;
|
|
30
|
-
}
|
|
31
|
-
async cache(callback, ttl = 60) {
|
|
32
|
-
return await this.appCache.cache(this._cacheKey(), callback, ttl);
|
|
33
|
-
}
|
|
34
|
-
async cacheWithTimestamp(callback, ttl = 60) {
|
|
35
|
-
return await this.appCache.cacheWithTimeStamp(this._cacheKey(), callback, ttl);
|
|
36
|
-
}
|
|
37
|
-
async clearCache() {
|
|
38
|
-
await this.appCache.delAll([this.constructor.name]);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
exports.AppController = AppController;
|
|
42
|
-
__decorate([
|
|
43
|
-
(0, common_1.Inject)(core_1.REQUEST),
|
|
44
|
-
__metadata("design:type", Object)
|
|
45
|
-
], AppController.prototype, "req", void 0);
|
|
46
|
-
__decorate([
|
|
47
|
-
(0, common_1.Inject)(cache_1.AppCache),
|
|
48
|
-
__metadata("design:type", cache_1.AppCache)
|
|
49
|
-
], AppController.prototype, "appCache", void 0);
|
|
50
|
-
exports.AppController = AppController = __decorate([
|
|
51
|
-
swagger_helper_1.SwaggerApiInternalServerErrorResponse,
|
|
52
|
-
swagger_helper_1.SwaggerApiBadSwaGatewayResponse,
|
|
53
|
-
swagger_helper_1.SwaggerApiConflictResponse,
|
|
54
|
-
swagger_helper_1.SwaggerApiForbiddenResponse,
|
|
55
|
-
swagger_helper_1.SwaggerApiUnauthorizedResponse
|
|
56
|
-
], AppController);
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"AppController",{enumerable:!0,get:function(){return AppController}});let _common=require("@nestjs/common"),_core=require("@nestjs/core"),_helpers=require("@triproject/helpers"),_express=require("express"),_cache=require("../drivers/cache"),_swaggerhelper=require("../helpers/swagger.helper");function _ts_decorate(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r}function _ts_metadata(k,v){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(k,v)}let AppController=class AppController{req;appCache;_cacheKey(){let keys=[this.constructor.name,this.req.path,this.req.method];return this.req.query&&Object.keys(this.req.query).length&&keys.push((0,_helpers.qs)(this.req.query)),this.req.body&&Object.keys(this.req.body).length&&keys.push((0,_helpers.qs)(this.req.body)),keys}async cache(callback,ttl=60){return await this.appCache.cache(this._cacheKey(),callback,ttl)}async cacheWithTimestamp(callback,ttl=60){return await this.appCache.cacheWithTimeStamp(this._cacheKey(),callback,ttl)}async clearCache(){await this.appCache.delAll(this.constructor.name)}};_ts_decorate([(0,_common.Inject)(_core.REQUEST),_ts_metadata("design:type",void 0===_express.Request?Object:_express.Request)],AppController.prototype,"req",void 0),_ts_decorate([(0,_common.Inject)(_cache.AppCache),_ts_metadata("design:type",void 0===_cache.AppCache?Object:_cache.AppCache)],AppController.prototype,"appCache",void 0),AppController=_ts_decorate([_swaggerhelper.SwaggerApiInternalServerErrorResponse,_swaggerhelper.SwaggerApiBadSwaGatewayResponse,_swaggerhelper.SwaggerApiConflictResponse,_swaggerhelper.SwaggerApiForbiddenResponse,_swaggerhelper.SwaggerApiUnauthorizedResponse],AppController);
|
|
@@ -12,7 +12,7 @@ export declare class AppCache {
|
|
|
12
12
|
set<T>(key: CacheKey, value: T, ttl?: number): Promise<void>;
|
|
13
13
|
get<T>(key: CacheKey): Promise<T | undefined>;
|
|
14
14
|
del(key: CacheKey): Promise<void>;
|
|
15
|
-
delAll(key:
|
|
15
|
+
delAll(key: string): Promise<void>;
|
|
16
16
|
cache<T>(key: CacheKey, fn: () => Promise<any>, ttl?: number): Promise<T>;
|
|
17
17
|
cacheWithTimeStamp<T extends object | string | number>(key: CacheKey, value: () => Promise<T> | T, ttl?: number): Promise<CacheWithTimestamp<T>>;
|
|
18
18
|
}
|
|
@@ -1,22 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.CacheModule = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const cache_1 = require("./cache");
|
|
12
|
-
const redis_1 = require("./redis");
|
|
13
|
-
let CacheModule = class CacheModule {
|
|
14
|
-
};
|
|
15
|
-
exports.CacheModule = CacheModule;
|
|
16
|
-
exports.CacheModule = CacheModule = __decorate([
|
|
17
|
-
(0, common_1.Global)(),
|
|
18
|
-
(0, common_1.Module)({
|
|
19
|
-
providers: [redis_1.Redis, cache_1.AppCache],
|
|
20
|
-
exports: [cache_1.AppCache],
|
|
21
|
-
})
|
|
22
|
-
], CacheModule);
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"CacheModule",{enumerable:!0,get:function(){return CacheModule}});let _common=require("@nestjs/common"),_cache=require("./cache"),_redis=require("./redis");let CacheModule=class CacheModule{};CacheModule=function(decorators,target,key,desc){var d,c=arguments.length,r=c<3?target:null===desc?desc=Object.getOwnPropertyDescriptor(target,key):desc;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)(d=decorators[i])&&(r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r);return c>3&&r&&Object.defineProperty(target,key,r),r}([(0,_common.Global)(),(0,_common.Module)({providers:[_redis.Redis,_cache.AppCache],exports:[_cache.AppCache]})],CacheModule);
|