@dereekb/nestjs 13.0.0 → 13.0.1

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/index.esm.js CHANGED
@@ -9,47 +9,47 @@ import { ConfigService, ConfigModule } from '@nestjs/config';
9
9
  * Returns true if the request is from localhost:4200.
10
10
  */
11
11
  const IsRequestFromLocalHost = createParamDecorator((data, context) => {
12
- return isLocalhost(context);
12
+ return isLocalhost(context);
13
13
  });
14
14
  function isLocalhost(context) {
15
- const req = context.switchToHttp().getRequest();
16
- const origin = req.headers['origin'] ?? '';
17
- return origin.startsWith('http://localhost') || origin.startsWith('https://localhost');
15
+ const req = context.switchToHttp().getRequest();
16
+ const origin = req.headers['origin'] ?? '';
17
+ return origin.startsWith('http://localhost') || origin.startsWith('https://localhost');
18
18
  }
19
19
 
20
20
  const ParseRawBody = createParamDecorator(async (_, context) => {
21
- const req = context.switchToHttp().getRequest();
22
- if (!req.readable) {
23
- console.error('RawBody request was not readable. This is generally due to bad configuration.');
24
- throw new BadRequestException('Invalid body');
25
- }
26
- const body = await rawbody(req);
27
- return body;
21
+ const req = context.switchToHttp().getRequest();
22
+ if (!req.readable) {
23
+ console.error('RawBody request was not readable. This is generally due to bad configuration.');
24
+ throw new BadRequestException('Invalid body');
25
+ }
26
+ const body = await rawbody(req);
27
+ return body;
28
28
  });
29
29
  const RawBody = createParamDecorator(async (_, context) => {
30
- const req = context.switchToHttp().getRequest();
31
- const body = req.body;
32
- if (!Buffer.isBuffer(body)) {
33
- console.error('RawBody expected a buffer set to req.body.');
34
- throw new InternalServerErrorException('failed parsing body');
35
- }
36
- return body;
30
+ const req = context.switchToHttp().getRequest();
31
+ const body = req.body;
32
+ if (!Buffer.isBuffer(body)) {
33
+ console.error('RawBody expected a buffer set to req.body.');
34
+ throw new InternalServerErrorException('failed parsing body');
35
+ }
36
+ return body;
37
37
  });
38
38
  const ParsedQueryRawBody = createParamDecorator(async (_, context) => {
39
- const req = context.switchToHttp().getRequest();
40
- req.body = RawBodyToParsedQueryString(req.body);
41
- return req.body;
39
+ const req = context.switchToHttp().getRequest();
40
+ req.body = RawBodyToParsedQueryString(req.body);
41
+ return req.body;
42
42
  });
43
43
  function RawBodyToJson(rawBody) {
44
- const string = RawBodyToString(rawBody);
45
- return JSON.parse(string);
44
+ const string = RawBodyToString(rawBody);
45
+ return JSON.parse(string);
46
46
  }
47
47
  function RawBodyToParsedQueryString(rawBody) {
48
- const string = RawBodyToString(rawBody);
49
- return parse(string);
48
+ const string = RawBodyToString(rawBody);
49
+ return parse(string);
50
50
  }
51
51
  function RawBodyToString(rawBody) {
52
- return rawBody.toString('utf8').trim();
52
+ return rawBody.toString('utf8').trim();
53
53
  }
54
54
 
55
55
  /******************************************************************************
@@ -90,45 +90,49 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
90
90
  };
91
91
 
92
92
  let JsonBodyMiddleware = class JsonBodyMiddleware {
93
- use(req, res, next) {
94
- bodyParser.json()(req, res, next);
95
- }
93
+ use(req, res, next) {
94
+ bodyParser.json()(req, res, next);
95
+ }
96
96
  };
97
- JsonBodyMiddleware = __decorate([Injectable()], JsonBodyMiddleware);
97
+ JsonBodyMiddleware = __decorate([
98
+ Injectable()
99
+ ], JsonBodyMiddleware);
98
100
 
99
101
  let RawBodyMiddleware = class RawBodyMiddleware {
100
- use(req, res, next) {
101
- bodyParser.raw({
102
- type: '*/*'
103
- })(req, res, next);
104
- }
102
+ use(req, res, next) {
103
+ bodyParser.raw({ type: '*/*' })(req, res, next);
104
+ }
105
105
  };
106
- RawBodyMiddleware = __decorate([Injectable()], RawBodyMiddleware);
106
+ RawBodyMiddleware = __decorate([
107
+ Injectable()
108
+ ], RawBodyMiddleware);
107
109
 
108
110
  const DEFAULT_BASE_WEBHOOK_PATH = '/webhook';
109
111
  const DEFAULT_WEBHOOK_MIDDLEWARE_ROUTE_INFO = {
110
- path: `${DEFAULT_BASE_WEBHOOK_PATH}/*`,
111
- method: RequestMethod.POST
112
+ path: `${DEFAULT_BASE_WEBHOOK_PATH}/*`,
113
+ method: RequestMethod.POST
112
114
  };
113
115
  /**
114
116
  * Convenience class that configures a nestjs module (typically the root app module) to apply the proper middleware for handling webhooks.
115
117
  */
116
118
  class AppModuleWithWebhooksEnabled {
117
- configure(consumer) {
118
- consumeWebhooksWithRawBodyMiddleware(consumer);
119
- }
119
+ configure(consumer) {
120
+ consumeWebhooksWithRawBodyMiddleware(consumer);
121
+ }
120
122
  }
121
123
  /**
122
124
  * Convenience class that extends AppWithWebhooksEnabled.
123
125
  */
124
126
  let ConfigureWebhookMiddlewareModule = class ConfigureWebhookMiddlewareModule extends AppModuleWithWebhooksEnabled {
125
- logger = new Logger('ConfigureWebhookMiddlewareModule');
126
- configure(consumer) {
127
- super.configure(consumer);
128
- this.logger.debug('Configured webhook routes with proper middleware.');
129
- }
127
+ logger = new Logger('ConfigureWebhookMiddlewareModule');
128
+ configure(consumer) {
129
+ super.configure(consumer);
130
+ this.logger.debug('Configured webhook routes with proper middleware.');
131
+ }
130
132
  };
131
- ConfigureWebhookMiddlewareModule = __decorate([Module({})], ConfigureWebhookMiddlewareModule);
133
+ ConfigureWebhookMiddlewareModule = __decorate([
134
+ Module({})
135
+ ], ConfigureWebhookMiddlewareModule);
132
136
  /**
133
137
  * Configures a MiddlewareConsumer to use RawBodyMiddleware for all POST requests to /webhook/*. All other routes are consumed with the JsonBodyMiddleware.
134
138
  *
@@ -139,9 +143,9 @@ ConfigureWebhookMiddlewareModule = __decorate([Module({})], ConfigureWebhookMidd
139
143
  * @param consumer
140
144
  */
141
145
  function consumeWebhooksWithRawBodyMiddleware(consumer) {
142
- // Configure the app to not parse the body for our webhook routes.
143
- // https://stackoverflow.com/questions/54346465/access-raw-body-of-stripe-webhook-in-nest-js
144
- consumer.apply(RawBodyMiddleware).forRoutes(DEFAULT_WEBHOOK_MIDDLEWARE_ROUTE_INFO).apply(JsonBodyMiddleware).forRoutes('*');
146
+ // Configure the app to not parse the body for our webhook routes.
147
+ // https://stackoverflow.com/questions/54346465/access-raw-body-of-stripe-webhook-in-nest-js
148
+ consumer.apply(RawBodyMiddleware).forRoutes(DEFAULT_WEBHOOK_MIDDLEWARE_ROUTE_INFO).apply(JsonBodyMiddleware).forRoutes('*');
145
149
  }
146
150
 
147
151
  /**
@@ -152,17 +156,17 @@ function consumeWebhooksWithRawBodyMiddleware(consumer) {
152
156
  * @returns
153
157
  */
154
158
  function mergeModuleMetadata(base, additional = {}) {
155
- return {
156
- controllers: mergeArrays([base.controllers, additional.controllers]),
157
- imports: mergeArrays([base.imports, additional.imports]),
158
- exports: mergeArrays([base.exports, additional.exports]),
159
- providers: mergeArrays([base.providers, additional.providers])
160
- };
159
+ return {
160
+ controllers: mergeArrays([base.controllers, additional.controllers]),
161
+ imports: mergeArrays([base.imports, additional.imports]),
162
+ exports: mergeArrays([base.exports, additional.exports]),
163
+ providers: mergeArrays([base.providers, additional.providers])
164
+ };
161
165
  }
162
166
  function injectionTokensFromProviders(providers) {
163
- return asArray(providers).map(x => {
164
- return typeof x === 'object' ? x.provide : x;
165
- });
167
+ return asArray(providers).map((x) => {
168
+ return typeof x === 'object' ? x.provide : x;
169
+ });
166
170
  }
167
171
 
168
172
  /**
@@ -171,53 +175,62 @@ function injectionTokensFromProviders(providers) {
171
175
  const CLIENT_WEB_APP_URL_ENV_VAR = 'CLIENT_WEB_APP_URL';
172
176
 
173
177
  class ClientAppServiceConfig {
174
- client;
175
- static assertValidConfig(config) {
176
- if (!config.client.clientWebAppUrl) {
177
- throw new Error('No client app url specified.');
178
+ client;
179
+ static assertValidConfig(config) {
180
+ if (!config.client.clientWebAppUrl) {
181
+ throw new Error('No client app url specified.');
182
+ }
178
183
  }
179
- }
180
184
  }
181
185
 
182
186
  /**
183
187
  * Provides information about companion apps and websites for the project.
184
188
  */
185
189
  let ClientAppService = class ClientAppService {
186
- _config;
187
- constructor(config) {
188
- this._config = config;
189
- }
190
- get config() {
191
- return this._config;
192
- }
193
- get webAppUrl() {
194
- return this.config.client.clientWebAppUrl;
195
- }
196
- get webAppHost() {
197
- return this.webAppUrl.split('://', 2)[1];
198
- }
190
+ _config;
191
+ constructor(config) {
192
+ this._config = config;
193
+ }
194
+ get config() {
195
+ return this._config;
196
+ }
197
+ get webAppUrl() {
198
+ return this.config.client.clientWebAppUrl;
199
+ }
200
+ get webAppHost() {
201
+ return this.webAppUrl.split('://', 2)[1];
202
+ }
199
203
  };
200
- ClientAppService = __decorate([Injectable(), __param(0, Inject(ClientAppServiceConfig)), __metadata("design:paramtypes", [ClientAppServiceConfig])], ClientAppService);
204
+ ClientAppService = __decorate([
205
+ Injectable(),
206
+ __param(0, Inject(ClientAppServiceConfig)),
207
+ __metadata("design:paramtypes", [ClientAppServiceConfig])
208
+ ], ClientAppService);
201
209
 
202
210
  function clientAppConfigFactory(configService) {
203
- const config = {
204
- client: {
205
- clientWebAppUrl: configService.get(CLIENT_WEB_APP_URL_ENV_VAR)
206
- }
207
- };
208
- ClientAppServiceConfig.assertValidConfig(config);
209
- return config;
211
+ const config = {
212
+ client: {
213
+ clientWebAppUrl: configService.get(CLIENT_WEB_APP_URL_ENV_VAR)
214
+ }
215
+ };
216
+ ClientAppServiceConfig.assertValidConfig(config);
217
+ return config;
210
218
  }
211
- let ClientAppModule = class ClientAppModule {};
212
- ClientAppModule = __decorate([Module({
213
- imports: [ConfigModule],
214
- providers: [{
215
- provide: ClientAppServiceConfig,
216
- inject: [ConfigService],
217
- useFactory: clientAppConfigFactory
218
- }],
219
- exports: [ClientAppService]
220
- })], ClientAppModule);
219
+ let ClientAppModule = class ClientAppModule {
220
+ };
221
+ ClientAppModule = __decorate([
222
+ Module({
223
+ imports: [ConfigModule],
224
+ providers: [
225
+ {
226
+ provide: ClientAppServiceConfig,
227
+ inject: [ConfigService],
228
+ useFactory: clientAppConfigFactory
229
+ }
230
+ ],
231
+ exports: [ClientAppService]
232
+ })
233
+ ], ClientAppModule);
221
234
 
222
235
  /**
223
236
  * A server environment configuration.
@@ -226,7 +239,8 @@ ClientAppModule = __decorate([Module({
226
239
  *
227
240
  * This config is not meant to replace other typical configurations, like .env files, but instead is part of the build system.
228
241
  */
229
- class ServerEnvironmentConfig {}
242
+ class ServerEnvironmentConfig {
243
+ }
230
244
 
231
245
  // MARK: Tokens
232
246
  /**
@@ -234,37 +248,41 @@ class ServerEnvironmentConfig {}
234
248
  */
235
249
  const SERVER_ENV_TOKEN = 'SERVER_ENV_TOKEN';
236
250
  function serverEnvTokenProvider(env) {
237
- return {
238
- provide: SERVER_ENV_TOKEN,
239
- useValue: env
240
- };
251
+ return {
252
+ provide: SERVER_ENV_TOKEN,
253
+ useValue: env
254
+ };
241
255
  }
242
256
 
243
257
  /**
244
258
  * Checks process.env.NODE_ENV for "test"
245
259
  */
246
260
  function isTestNodeEnv() {
247
- return process.env['NODE_ENV'] === 'test';
261
+ return process.env['NODE_ENV'] === 'test';
248
262
  }
249
263
 
250
264
  let ServerEnvironmentService = class ServerEnvironmentService {
251
- env;
252
- constructor(env) {
253
- this.env = env;
254
- }
255
- get isTestingEnv() {
256
- return isTestNodeEnv();
257
- }
258
- get isProduction() {
259
- return this.env.production;
260
- }
261
- get isStaging() {
262
- return Boolean(this.env.staging);
263
- }
264
- get developerToolsEnabled() {
265
- return Boolean(!this.isProduction && this.env.developerToolsEnabled);
266
- }
265
+ env;
266
+ constructor(env) {
267
+ this.env = env;
268
+ }
269
+ get isTestingEnv() {
270
+ return isTestNodeEnv();
271
+ }
272
+ get isProduction() {
273
+ return this.env.production;
274
+ }
275
+ get isStaging() {
276
+ return Boolean(this.env.staging);
277
+ }
278
+ get developerToolsEnabled() {
279
+ return Boolean(!this.isProduction && this.env.developerToolsEnabled);
280
+ }
267
281
  };
268
- ServerEnvironmentService = __decorate([Injectable(), __param(0, Inject(SERVER_ENV_TOKEN)), __metadata("design:paramtypes", [ServerEnvironmentConfig])], ServerEnvironmentService);
282
+ ServerEnvironmentService = __decorate([
283
+ Injectable(),
284
+ __param(0, Inject(SERVER_ENV_TOKEN)),
285
+ __metadata("design:paramtypes", [ServerEnvironmentConfig])
286
+ ], ServerEnvironmentService);
269
287
 
270
288
  export { AppModuleWithWebhooksEnabled, CLIENT_WEB_APP_URL_ENV_VAR, ClientAppModule, ClientAppService, ClientAppServiceConfig, ConfigureWebhookMiddlewareModule, DEFAULT_BASE_WEBHOOK_PATH, DEFAULT_WEBHOOK_MIDDLEWARE_ROUTE_INFO, IsRequestFromLocalHost, JsonBodyMiddleware, ParseRawBody, ParsedQueryRawBody, RawBody, RawBodyMiddleware, RawBodyToJson, RawBodyToParsedQueryString, RawBodyToString, SERVER_ENV_TOKEN, ServerEnvironmentConfig, ServerEnvironmentService, clientAppConfigFactory, consumeWebhooksWithRawBodyMiddleware, injectionTokensFromProviders, isLocalhost, isTestNodeEnv, mergeModuleMetadata, serverEnvTokenProvider };
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;