@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
|
@@ -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
|
-
|
|
14
|
+
return isLocalhost(context);
|
|
15
15
|
});
|
|
16
16
|
function isLocalhost(context) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const req = context.switchToHttp().getRequest();
|
|
42
|
+
req.body = RawBodyToParsedQueryString(req.body);
|
|
43
|
+
return req.body;
|
|
44
44
|
});
|
|
45
45
|
function RawBodyToJson(rawBody) {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const string = RawBodyToString(rawBody);
|
|
47
|
+
return JSON.parse(string);
|
|
48
48
|
}
|
|
49
49
|
function RawBodyToParsedQueryString(rawBody) {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const string = RawBodyToString(rawBody);
|
|
51
|
+
return querystring.parse(string);
|
|
52
52
|
}
|
|
53
53
|
function RawBodyToString(rawBody) {
|
|
54
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
use(req, res, next) {
|
|
96
|
+
bodyParser.json()(req, res, next);
|
|
97
|
+
}
|
|
98
98
|
};
|
|
99
|
-
exports.JsonBodyMiddleware = __decorate([
|
|
99
|
+
exports.JsonBodyMiddleware = __decorate([
|
|
100
|
+
common.Injectable()
|
|
101
|
+
], exports.JsonBodyMiddleware);
|
|
100
102
|
|
|
101
103
|
exports.RawBodyMiddleware = class RawBodyMiddleware {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
})(req, res, next);
|
|
106
|
-
}
|
|
104
|
+
use(req, res, next) {
|
|
105
|
+
bodyParser.raw({ type: '*/*' })(req, res, next);
|
|
106
|
+
}
|
|
107
107
|
};
|
|
108
|
-
exports.RawBodyMiddleware = __decorate([
|
|
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
|
-
|
|
113
|
-
|
|
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
|
-
|
|
120
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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([
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
166
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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([
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
|
|
263
|
+
return process.env['NODE_ENV'] === 'test';
|
|
250
264
|
}
|
|
251
265
|
|
|
252
266
|
exports.ServerEnvironmentService = class ServerEnvironmentService {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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([
|
|
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