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