@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.cjs.default.js +1 -0
- package/index.cjs.js +136 -118
- package/index.cjs.mjs +2 -0
- package/index.esm.js +136 -118
- package/mailgun/index.cjs.default.js +1 -0
- package/mailgun/index.cjs.js +496 -503
- package/mailgun/index.cjs.mjs +2 -0
- package/mailgun/index.esm.js +496 -503
- package/mailgun/package.json +19 -20
- package/openai/index.cjs.default.js +1 -0
- package/openai/index.cjs.js +194 -161
- package/openai/index.cjs.mjs +2 -0
- package/openai/index.esm.js +194 -161
- package/openai/package.json +19 -20
- package/package.json +32 -55
- package/stripe/index.cjs.default.js +1 -0
- package/stripe/index.cjs.js +158 -128
- package/stripe/index.cjs.mjs +2 -0
- package/stripe/index.esm.js +158 -128
- package/stripe/package.json +19 -20
- package/typeform/index.cjs.default.js +1 -0
- package/typeform/index.cjs.js +257 -240
- package/typeform/index.cjs.mjs +2 -0
- package/typeform/index.esm.js +257 -240
- package/typeform/package.json +19 -20
- package/vapiai/index.cjs.default.js +1 -0
- package/vapiai/index.cjs.js +203 -190
- package/vapiai/index.cjs.mjs +2 -0
- package/vapiai/index.esm.js +203 -190
- package/vapiai/package.json +19 -20
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
|
-
|
|
12
|
+
return isLocalhost(context);
|
|
13
13
|
});
|
|
14
14
|
function isLocalhost(context) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const req = context.switchToHttp().getRequest();
|
|
40
|
+
req.body = RawBodyToParsedQueryString(req.body);
|
|
41
|
+
return req.body;
|
|
42
42
|
});
|
|
43
43
|
function RawBodyToJson(rawBody) {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const string = RawBodyToString(rawBody);
|
|
45
|
+
return JSON.parse(string);
|
|
46
46
|
}
|
|
47
47
|
function RawBodyToParsedQueryString(rawBody) {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const string = RawBodyToString(rawBody);
|
|
49
|
+
return parse(string);
|
|
50
50
|
}
|
|
51
51
|
function RawBodyToString(rawBody) {
|
|
52
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
use(req, res, next) {
|
|
94
|
+
bodyParser.json()(req, res, next);
|
|
95
|
+
}
|
|
96
96
|
};
|
|
97
|
-
JsonBodyMiddleware = __decorate([
|
|
97
|
+
JsonBodyMiddleware = __decorate([
|
|
98
|
+
Injectable()
|
|
99
|
+
], JsonBodyMiddleware);
|
|
98
100
|
|
|
99
101
|
let RawBodyMiddleware = class RawBodyMiddleware {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
})(req, res, next);
|
|
104
|
-
}
|
|
102
|
+
use(req, res, next) {
|
|
103
|
+
bodyParser.raw({ type: '*/*' })(req, res, next);
|
|
104
|
+
}
|
|
105
105
|
};
|
|
106
|
-
RawBodyMiddleware = __decorate([
|
|
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
|
-
|
|
111
|
-
|
|
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
|
-
|
|
118
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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([
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
164
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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([
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
261
|
+
return process.env['NODE_ENV'] === 'test';
|
|
248
262
|
}
|
|
249
263
|
|
|
250
264
|
let ServerEnvironmentService = class ServerEnvironmentService {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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([
|
|
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;
|