@dereekb/nestjs 13.2.1 → 13.3.0
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/discord/index.cjs.js +1171 -207
- package/discord/index.esm.js +1173 -209
- package/discord/package.json +3 -3
- package/index.cjs.js +918 -144
- package/index.esm.js +914 -146
- package/mailgun/index.cjs.js +797 -315
- package/mailgun/index.esm.js +797 -315
- package/mailgun/package.json +6 -6
- package/openai/index.cjs.js +867 -154
- package/openai/index.esm.js +867 -154
- package/openai/package.json +6 -6
- package/package.json +2 -2
- package/src/lib/decorators/local.decorator.d.ts +1 -1
- package/src/lib/decorators/rawbody.d.ts +73 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/middlewares/json.middleware.d.ts +10 -0
- package/src/lib/middlewares/webhook.d.ts +1 -1
- package/src/lib/module/client/client.config.d.ts +16 -0
- package/src/lib/module/env/env.config.d.ts +6 -0
- package/src/lib/module/env/env.service.d.ts +1 -0
- package/src/lib/util/encryption/index.d.ts +1 -0
- package/src/lib/util/encryption/json.encrypt.d.ts +130 -0
- package/src/lib/util/index.d.ts +1 -0
- package/stripe/index.cjs.js +625 -114
- package/stripe/index.esm.js +625 -114
- package/stripe/package.json +6 -6
- package/typeform/index.cjs.js +930 -173
- package/typeform/index.esm.js +930 -173
- package/typeform/package.json +6 -6
- package/vapiai/index.cjs.js +876 -151
- package/vapiai/index.esm.js +876 -151
- package/vapiai/package.json +6 -6
package/index.esm.js
CHANGED
|
@@ -2,208 +2,724 @@ import { createParamDecorator, BadRequestException, InternalServerErrorException
|
|
|
2
2
|
import rawbody from 'raw-body';
|
|
3
3
|
import { parse } from 'querystring';
|
|
4
4
|
import bodyParser from 'body-parser';
|
|
5
|
-
import { asArray, mergeArrays } from '@dereekb/util';
|
|
5
|
+
import { asArray, mergeArrays, isHex, getValueFromGetter } from '@dereekb/util';
|
|
6
6
|
import { ConfigService, ConfigModule } from '@nestjs/config';
|
|
7
|
+
import { createDecipheriv, randomBytes, createCipheriv } from 'crypto';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
|
-
* Returns true if the request is from localhost
|
|
10
|
-
*/
|
|
11
|
-
const IsRequestFromLocalHost = createParamDecorator((data, context) => {
|
|
10
|
+
* Returns true if the request is from localhost.
|
|
11
|
+
*/ var IsRequestFromLocalHost = createParamDecorator(function(data, context) {
|
|
12
12
|
return isLocalhost(context);
|
|
13
13
|
});
|
|
14
14
|
function isLocalhost(context) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
var _req_headers_origin;
|
|
16
|
+
var req = context.switchToHttp().getRequest();
|
|
17
|
+
var origin = (_req_headers_origin = req.headers['origin']) !== null && _req_headers_origin !== void 0 ? _req_headers_origin : '';
|
|
17
18
|
return origin.startsWith('http://localhost') || origin.startsWith('https://localhost');
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
22
|
+
try {
|
|
23
|
+
var info = gen[key](arg);
|
|
24
|
+
var value = info.value;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
reject(error);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (info.done) {
|
|
30
|
+
resolve(value);
|
|
31
|
+
} else {
|
|
32
|
+
Promise.resolve(value).then(_next, _throw);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _async_to_generator(fn) {
|
|
36
|
+
return function() {
|
|
37
|
+
var self = this, args = arguments;
|
|
38
|
+
return new Promise(function(resolve, reject) {
|
|
39
|
+
var gen = fn.apply(self, args);
|
|
40
|
+
function _next(value) {
|
|
41
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
42
|
+
}
|
|
43
|
+
function _throw(err) {
|
|
44
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
45
|
+
}
|
|
46
|
+
_next(undefined);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function _ts_generator(thisArg, body) {
|
|
51
|
+
var f, y, t, _ = {
|
|
52
|
+
label: 0,
|
|
53
|
+
sent: function() {
|
|
54
|
+
if (t[0] & 1) throw t[1];
|
|
55
|
+
return t[1];
|
|
56
|
+
},
|
|
57
|
+
trys: [],
|
|
58
|
+
ops: []
|
|
59
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
60
|
+
return d(g, "next", {
|
|
61
|
+
value: verb(0)
|
|
62
|
+
}), d(g, "throw", {
|
|
63
|
+
value: verb(1)
|
|
64
|
+
}), d(g, "return", {
|
|
65
|
+
value: verb(2)
|
|
66
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
67
|
+
value: function() {
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
}), g;
|
|
71
|
+
function verb(n) {
|
|
72
|
+
return function(v) {
|
|
73
|
+
return step([
|
|
74
|
+
n,
|
|
75
|
+
v
|
|
76
|
+
]);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function step(op) {
|
|
80
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
81
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
82
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
83
|
+
if (y = 0, t) op = [
|
|
84
|
+
op[0] & 2,
|
|
85
|
+
t.value
|
|
86
|
+
];
|
|
87
|
+
switch(op[0]){
|
|
88
|
+
case 0:
|
|
89
|
+
case 1:
|
|
90
|
+
t = op;
|
|
91
|
+
break;
|
|
92
|
+
case 4:
|
|
93
|
+
_.label++;
|
|
94
|
+
return {
|
|
95
|
+
value: op[1],
|
|
96
|
+
done: false
|
|
97
|
+
};
|
|
98
|
+
case 5:
|
|
99
|
+
_.label++;
|
|
100
|
+
y = op[1];
|
|
101
|
+
op = [
|
|
102
|
+
0
|
|
103
|
+
];
|
|
104
|
+
continue;
|
|
105
|
+
case 7:
|
|
106
|
+
op = _.ops.pop();
|
|
107
|
+
_.trys.pop();
|
|
108
|
+
continue;
|
|
109
|
+
default:
|
|
110
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
111
|
+
_ = 0;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
115
|
+
_.label = op[1];
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
119
|
+
_.label = t[1];
|
|
120
|
+
t = op;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
if (t && _.label < t[2]) {
|
|
124
|
+
_.label = t[2];
|
|
125
|
+
_.ops.push(op);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
if (t[2]) _.ops.pop();
|
|
129
|
+
_.trys.pop();
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
op = body.call(thisArg, _);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
op = [
|
|
135
|
+
6,
|
|
136
|
+
e
|
|
137
|
+
];
|
|
138
|
+
y = 0;
|
|
139
|
+
} finally{
|
|
140
|
+
f = t = 0;
|
|
141
|
+
}
|
|
142
|
+
if (op[0] & 5) throw op[1];
|
|
143
|
+
return {
|
|
144
|
+
value: op[0] ? op[1] : void 0,
|
|
145
|
+
done: true
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* NestJS parameter decorator that reads the raw request body directly from the incoming stream.
|
|
151
|
+
*
|
|
152
|
+
* Requires the request to still be readable (i.e., no prior body-parsing middleware has consumed it).
|
|
153
|
+
*
|
|
154
|
+
* @throws {BadRequestException} When the request stream is not readable
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* @Post('webhook')
|
|
159
|
+
* handleWebhook(@ParseRawBody() body: RawBodyBuffer) { ... }
|
|
160
|
+
* ```
|
|
161
|
+
*/ var ParseRawBody = createParamDecorator(function(_, context) {
|
|
162
|
+
return _async_to_generator(function() {
|
|
163
|
+
var req, body;
|
|
164
|
+
return _ts_generator(this, function(_state) {
|
|
165
|
+
switch(_state.label){
|
|
166
|
+
case 0:
|
|
167
|
+
req = context.switchToHttp().getRequest();
|
|
168
|
+
if (!req.readable) {
|
|
169
|
+
console.error('RawBody request was not readable. This is generally due to bad configuration.');
|
|
170
|
+
throw new BadRequestException('Invalid body');
|
|
171
|
+
}
|
|
172
|
+
return [
|
|
173
|
+
4,
|
|
174
|
+
rawbody(req)
|
|
175
|
+
];
|
|
176
|
+
case 1:
|
|
177
|
+
body = _state.sent();
|
|
178
|
+
return [
|
|
179
|
+
2,
|
|
180
|
+
body
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
})();
|
|
28
185
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
186
|
+
/**
|
|
187
|
+
* NestJS parameter decorator that retrieves the already-parsed raw body buffer from `req.body`.
|
|
188
|
+
*
|
|
189
|
+
* Expects that a prior middleware (e.g., raw body middleware) has already set `req.body` to a Buffer.
|
|
190
|
+
*
|
|
191
|
+
* @throws {InternalServerErrorException} When `req.body` is not a Buffer
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* @Post('webhook')
|
|
196
|
+
* handleWebhook(@RawBody() body: RawBodyBuffer) { ... }
|
|
197
|
+
* ```
|
|
198
|
+
*/ var RawBody = createParamDecorator(function(_, context) {
|
|
199
|
+
return _async_to_generator(function() {
|
|
200
|
+
var req, body;
|
|
201
|
+
return _ts_generator(this, function(_state) {
|
|
202
|
+
req = context.switchToHttp().getRequest();
|
|
203
|
+
body = req.body;
|
|
204
|
+
if (!Buffer.isBuffer(body)) {
|
|
205
|
+
console.error('RawBody expected a buffer set to req.body.');
|
|
206
|
+
throw new InternalServerErrorException('failed parsing body');
|
|
207
|
+
}
|
|
208
|
+
return [
|
|
209
|
+
2,
|
|
210
|
+
body
|
|
211
|
+
];
|
|
212
|
+
});
|
|
213
|
+
})();
|
|
37
214
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
215
|
+
/**
|
|
216
|
+
* NestJS parameter decorator that parses the raw body buffer as a URL-encoded query string
|
|
217
|
+
* and replaces `req.body` with the parsed result.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* @Post('form')
|
|
222
|
+
* handleForm(@ParsedQueryRawBody() body: ParsedUrlQuery) { ... }
|
|
223
|
+
* ```
|
|
224
|
+
*/ var ParsedQueryRawBody = createParamDecorator(function(_, context) {
|
|
225
|
+
return _async_to_generator(function() {
|
|
226
|
+
var req;
|
|
227
|
+
return _ts_generator(this, function(_state) {
|
|
228
|
+
req = context.switchToHttp().getRequest();
|
|
229
|
+
req.body = RawBodyToParsedQueryString(req.body);
|
|
230
|
+
return [
|
|
231
|
+
2,
|
|
232
|
+
req.body
|
|
233
|
+
];
|
|
234
|
+
});
|
|
235
|
+
})();
|
|
42
236
|
});
|
|
43
|
-
|
|
44
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Parses a raw body buffer as JSON.
|
|
239
|
+
*
|
|
240
|
+
* @param rawBody - The raw body buffer to parse
|
|
241
|
+
* @returns The parsed JSON object
|
|
242
|
+
* @throws {SyntaxError} When the body is not valid JSON
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* const data = RawBodyToJson<{ id: string }>(rawBody);
|
|
247
|
+
* ```
|
|
248
|
+
*/ function RawBodyToJson(rawBody) {
|
|
249
|
+
var string = RawBodyToString(rawBody);
|
|
45
250
|
return JSON.parse(string);
|
|
46
251
|
}
|
|
47
|
-
|
|
48
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Parses a raw body buffer as a URL-encoded query string.
|
|
254
|
+
*
|
|
255
|
+
* @param rawBody - The raw body buffer to parse
|
|
256
|
+
* @returns The parsed query parameters
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* const params = RawBodyToParsedQueryString(rawBody); // { key: "value" }
|
|
261
|
+
* ```
|
|
262
|
+
*/ function RawBodyToParsedQueryString(rawBody) {
|
|
263
|
+
var string = RawBodyToString(rawBody);
|
|
49
264
|
return parse(string);
|
|
50
265
|
}
|
|
51
|
-
|
|
266
|
+
/**
|
|
267
|
+
* Converts a raw body buffer to a trimmed UTF-8 string.
|
|
268
|
+
*
|
|
269
|
+
* @param rawBody - The raw body buffer to convert
|
|
270
|
+
* @returns The decoded and trimmed string content
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const text = RawBodyToString(rawBody);
|
|
275
|
+
* ```
|
|
276
|
+
*/ function RawBodyToString(rawBody) {
|
|
52
277
|
return rawBody.toString('utf8').trim();
|
|
53
278
|
}
|
|
54
279
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
74
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
75
|
-
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;
|
|
76
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function __param(paramIndex, decorator) {
|
|
80
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
84
|
-
var e = new Error(message);
|
|
85
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
280
|
+
function _type_of$2(obj) {
|
|
281
|
+
"@swc/helpers - typeof";
|
|
282
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
283
|
+
}
|
|
284
|
+
function __decorate(decorators, target, key, desc) {
|
|
285
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
286
|
+
if ((typeof Reflect === "undefined" ? "undefined" : _type_of$2(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
287
|
+
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;
|
|
288
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
289
|
+
}
|
|
290
|
+
function __param(paramIndex, decorator) {
|
|
291
|
+
return function(target, key) {
|
|
292
|
+
decorator(target, key, paramIndex);
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
296
|
+
var e = new Error(message);
|
|
297
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
86
298
|
};
|
|
87
299
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
300
|
+
function _class_call_check$7(instance, Constructor) {
|
|
301
|
+
if (!(instance instanceof Constructor)) {
|
|
302
|
+
throw new TypeError("Cannot call a class as a function");
|
|
91
303
|
}
|
|
92
|
-
}
|
|
304
|
+
}
|
|
305
|
+
function _defineProperties$5(target, props) {
|
|
306
|
+
for(var i = 0; i < props.length; i++){
|
|
307
|
+
var descriptor = props[i];
|
|
308
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
309
|
+
descriptor.configurable = true;
|
|
310
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
311
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function _create_class$5(Constructor, protoProps, staticProps) {
|
|
315
|
+
if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
|
|
316
|
+
return Constructor;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* NestJS middleware that applies JSON body parsing to incoming requests using `body-parser`.
|
|
320
|
+
*
|
|
321
|
+
* Useful when the global body parser is disabled and JSON parsing needs to be applied selectively to specific routes.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* consumer.apply(JsonBodyMiddleware).forRoutes('api');
|
|
326
|
+
* ```
|
|
327
|
+
*/ var JsonBodyMiddleware = /*#__PURE__*/ function() {
|
|
328
|
+
function JsonBodyMiddleware() {
|
|
329
|
+
_class_call_check$7(this, JsonBodyMiddleware);
|
|
330
|
+
}
|
|
331
|
+
_create_class$5(JsonBodyMiddleware, [
|
|
332
|
+
{
|
|
333
|
+
key: "use",
|
|
334
|
+
value: function use(req, res, next) {
|
|
335
|
+
bodyParser.json()(req, res, next);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
]);
|
|
339
|
+
return JsonBodyMiddleware;
|
|
340
|
+
}();
|
|
93
341
|
JsonBodyMiddleware = __decorate([
|
|
94
342
|
Injectable()
|
|
95
343
|
], JsonBodyMiddleware);
|
|
96
344
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
345
|
+
function _class_call_check$6(instance, Constructor) {
|
|
346
|
+
if (!(instance instanceof Constructor)) {
|
|
347
|
+
throw new TypeError("Cannot call a class as a function");
|
|
100
348
|
}
|
|
101
|
-
}
|
|
349
|
+
}
|
|
350
|
+
function _defineProperties$4(target, props) {
|
|
351
|
+
for(var i = 0; i < props.length; i++){
|
|
352
|
+
var descriptor = props[i];
|
|
353
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
354
|
+
descriptor.configurable = true;
|
|
355
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
356
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function _create_class$4(Constructor, protoProps, staticProps) {
|
|
360
|
+
if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
|
|
361
|
+
return Constructor;
|
|
362
|
+
}
|
|
363
|
+
var RawBodyMiddleware = /*#__PURE__*/ function() {
|
|
364
|
+
function RawBodyMiddleware() {
|
|
365
|
+
_class_call_check$6(this, RawBodyMiddleware);
|
|
366
|
+
}
|
|
367
|
+
_create_class$4(RawBodyMiddleware, [
|
|
368
|
+
{
|
|
369
|
+
key: "use",
|
|
370
|
+
value: function use(req, res, next) {
|
|
371
|
+
bodyParser.raw({
|
|
372
|
+
type: '*/*'
|
|
373
|
+
})(req, res, next);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
]);
|
|
377
|
+
return RawBodyMiddleware;
|
|
378
|
+
}();
|
|
102
379
|
RawBodyMiddleware = __decorate([
|
|
103
380
|
Injectable()
|
|
104
381
|
], RawBodyMiddleware);
|
|
105
382
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
383
|
+
function _assert_this_initialized(self) {
|
|
384
|
+
if (self === void 0) {
|
|
385
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
386
|
+
}
|
|
387
|
+
return self;
|
|
388
|
+
}
|
|
389
|
+
function _call_super(_this, derived, args) {
|
|
390
|
+
derived = _get_prototype_of(derived);
|
|
391
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
392
|
+
}
|
|
393
|
+
function _class_call_check$5(instance, Constructor) {
|
|
394
|
+
if (!(instance instanceof Constructor)) {
|
|
395
|
+
throw new TypeError("Cannot call a class as a function");
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
function _defineProperties$3(target, props) {
|
|
399
|
+
for(var i = 0; i < props.length; i++){
|
|
400
|
+
var descriptor = props[i];
|
|
401
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
402
|
+
descriptor.configurable = true;
|
|
403
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
404
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function _create_class$3(Constructor, protoProps, staticProps) {
|
|
408
|
+
if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
|
|
409
|
+
return Constructor;
|
|
410
|
+
}
|
|
411
|
+
function _define_property$3(obj, key, value) {
|
|
412
|
+
if (key in obj) {
|
|
413
|
+
Object.defineProperty(obj, key, {
|
|
414
|
+
value: value,
|
|
415
|
+
enumerable: true,
|
|
416
|
+
configurable: true,
|
|
417
|
+
writable: true
|
|
418
|
+
});
|
|
419
|
+
} else {
|
|
420
|
+
obj[key] = value;
|
|
421
|
+
}
|
|
422
|
+
return obj;
|
|
423
|
+
}
|
|
424
|
+
function _get(target, property, receiver) {
|
|
425
|
+
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
426
|
+
_get = Reflect.get;
|
|
427
|
+
} else {
|
|
428
|
+
_get = function get(target, property, receiver) {
|
|
429
|
+
var base = _super_prop_base(target, property);
|
|
430
|
+
if (!base) return;
|
|
431
|
+
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
432
|
+
if (desc.get) {
|
|
433
|
+
return desc.get.call(receiver || target);
|
|
434
|
+
}
|
|
435
|
+
return desc.value;
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
return _get(target, property, receiver || target);
|
|
439
|
+
}
|
|
440
|
+
function _get_prototype_of(o) {
|
|
441
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
442
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
443
|
+
};
|
|
444
|
+
return _get_prototype_of(o);
|
|
445
|
+
}
|
|
446
|
+
function _inherits(subClass, superClass) {
|
|
447
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
448
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
449
|
+
}
|
|
450
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
451
|
+
constructor: {
|
|
452
|
+
value: subClass,
|
|
453
|
+
writable: true,
|
|
454
|
+
configurable: true
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
458
|
+
}
|
|
459
|
+
function _possible_constructor_return(self, call) {
|
|
460
|
+
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
|
|
461
|
+
return call;
|
|
462
|
+
}
|
|
463
|
+
return _assert_this_initialized(self);
|
|
464
|
+
}
|
|
465
|
+
function _set_prototype_of(o, p) {
|
|
466
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
467
|
+
o.__proto__ = p;
|
|
468
|
+
return o;
|
|
469
|
+
};
|
|
470
|
+
return _set_prototype_of(o, p);
|
|
471
|
+
}
|
|
472
|
+
function _super_prop_base(object, property) {
|
|
473
|
+
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
|
474
|
+
object = _get_prototype_of(object);
|
|
475
|
+
if (object === null) break;
|
|
476
|
+
}
|
|
477
|
+
return object;
|
|
478
|
+
}
|
|
479
|
+
function _type_of$1(obj) {
|
|
480
|
+
"@swc/helpers - typeof";
|
|
481
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
482
|
+
}
|
|
483
|
+
function _is_native_reflect_construct() {
|
|
484
|
+
try {
|
|
485
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
486
|
+
} catch (_) {}
|
|
487
|
+
return (_is_native_reflect_construct = function() {
|
|
488
|
+
return !!result;
|
|
489
|
+
})();
|
|
490
|
+
}
|
|
491
|
+
var DEFAULT_BASE_WEBHOOK_PATH = '/webhook';
|
|
492
|
+
var DEFAULT_WEBHOOK_MIDDLEWARE_ROUTE_INFO = {
|
|
493
|
+
path: "".concat(DEFAULT_BASE_WEBHOOK_PATH, "/{*path}"),
|
|
109
494
|
method: RequestMethod.POST
|
|
110
495
|
};
|
|
111
496
|
/**
|
|
112
497
|
* Convenience class that configures a nestjs module (typically the root app module) to apply the proper middleware for handling webhooks.
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
consumeWebhooksWithRawBodyMiddleware(consumer);
|
|
498
|
+
*/ var AppModuleWithWebhooksEnabled = /*#__PURE__*/ function() {
|
|
499
|
+
function AppModuleWithWebhooksEnabled() {
|
|
500
|
+
_class_call_check$5(this, AppModuleWithWebhooksEnabled);
|
|
117
501
|
}
|
|
118
|
-
|
|
502
|
+
_create_class$3(AppModuleWithWebhooksEnabled, [
|
|
503
|
+
{
|
|
504
|
+
key: "configure",
|
|
505
|
+
value: function configure(consumer) {
|
|
506
|
+
consumeWebhooksWithRawBodyMiddleware(consumer);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
]);
|
|
510
|
+
return AppModuleWithWebhooksEnabled;
|
|
511
|
+
}();
|
|
119
512
|
/**
|
|
120
513
|
* Convenience class that extends AppWithWebhooksEnabled.
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this
|
|
514
|
+
*/ var ConfigureWebhookMiddlewareModule = /*#__PURE__*/ function(AppModuleWithWebhooksEnabled) {
|
|
515
|
+
_inherits(ConfigureWebhookMiddlewareModule, AppModuleWithWebhooksEnabled);
|
|
516
|
+
function ConfigureWebhookMiddlewareModule() {
|
|
517
|
+
_class_call_check$5(this, ConfigureWebhookMiddlewareModule);
|
|
518
|
+
var _this;
|
|
519
|
+
_this = _call_super(this, ConfigureWebhookMiddlewareModule, arguments), _define_property$3(_this, "logger", new Logger('ConfigureWebhookMiddlewareModule'));
|
|
520
|
+
return _this;
|
|
127
521
|
}
|
|
128
|
-
|
|
522
|
+
_create_class$3(ConfigureWebhookMiddlewareModule, [
|
|
523
|
+
{
|
|
524
|
+
key: "configure",
|
|
525
|
+
value: function configure(consumer) {
|
|
526
|
+
_get(_get_prototype_of(ConfigureWebhookMiddlewareModule.prototype), "configure", this).call(this, consumer);
|
|
527
|
+
this.logger.debug('Configured webhook routes with proper middleware.');
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
]);
|
|
531
|
+
return ConfigureWebhookMiddlewareModule;
|
|
532
|
+
}(AppModuleWithWebhooksEnabled);
|
|
129
533
|
ConfigureWebhookMiddlewareModule = __decorate([
|
|
130
534
|
Module({})
|
|
131
535
|
], ConfigureWebhookMiddlewareModule);
|
|
132
536
|
/**
|
|
133
|
-
* Configures a MiddlewareConsumer to use RawBodyMiddleware for all POST requests to /webhook
|
|
537
|
+
* Configures a MiddlewareConsumer to use RawBodyMiddleware for all POST requests to /webhook/{*path}. All other routes are consumed with the JsonBodyMiddleware.
|
|
134
538
|
*
|
|
135
539
|
* This is required for various webhooks that require the full body to properly parse content.
|
|
136
540
|
*
|
|
137
541
|
* Be sure to also set bodyParsing: false in the nest app options.
|
|
138
542
|
*
|
|
139
543
|
* @param consumer
|
|
140
|
-
*/
|
|
141
|
-
function consumeWebhooksWithRawBodyMiddleware(consumer) {
|
|
544
|
+
*/ function consumeWebhooksWithRawBodyMiddleware(consumer) {
|
|
142
545
|
// Configure the app to not parse the body for our webhook routes.
|
|
143
546
|
// 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('*');
|
|
547
|
+
consumer.apply(RawBodyMiddleware).forRoutes(DEFAULT_WEBHOOK_MIDDLEWARE_ROUTE_INFO).apply(JsonBodyMiddleware).forRoutes('{*path}');
|
|
145
548
|
}
|
|
146
549
|
|
|
550
|
+
function _type_of(obj) {
|
|
551
|
+
"@swc/helpers - typeof";
|
|
552
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
553
|
+
}
|
|
147
554
|
/**
|
|
148
555
|
* Merges two module metadata entries together.
|
|
149
556
|
*
|
|
150
557
|
* @param base
|
|
151
558
|
* @param additional
|
|
152
559
|
* @returns
|
|
153
|
-
*/
|
|
154
|
-
|
|
560
|
+
*/ function mergeModuleMetadata(base) {
|
|
561
|
+
var additional = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
155
562
|
return {
|
|
156
|
-
controllers: mergeArrays([
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
563
|
+
controllers: mergeArrays([
|
|
564
|
+
base.controllers,
|
|
565
|
+
additional.controllers
|
|
566
|
+
]),
|
|
567
|
+
imports: mergeArrays([
|
|
568
|
+
base.imports,
|
|
569
|
+
additional.imports
|
|
570
|
+
]),
|
|
571
|
+
exports: mergeArrays([
|
|
572
|
+
base.exports,
|
|
573
|
+
additional.exports
|
|
574
|
+
]),
|
|
575
|
+
providers: mergeArrays([
|
|
576
|
+
base.providers,
|
|
577
|
+
additional.providers
|
|
578
|
+
])
|
|
160
579
|
};
|
|
161
580
|
}
|
|
162
581
|
function injectionTokensFromProviders(providers) {
|
|
163
|
-
return asArray(providers).map((x)
|
|
164
|
-
return typeof x === 'object' ? x.provide : x;
|
|
582
|
+
return asArray(providers).map(function(x) {
|
|
583
|
+
return (typeof x === "undefined" ? "undefined" : _type_of(x)) === 'object' ? x.provide : x;
|
|
165
584
|
});
|
|
166
585
|
}
|
|
167
586
|
|
|
168
587
|
/**
|
|
169
588
|
* Environment variable that specfies the ClientWebAppUrl for your application
|
|
170
|
-
*/
|
|
171
|
-
const CLIENT_WEB_APP_URL_ENV_VAR = 'CLIENT_WEB_APP_URL';
|
|
589
|
+
*/ var CLIENT_WEB_APP_URL_ENV_VAR = 'CLIENT_WEB_APP_URL';
|
|
172
590
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (!config.client.clientWebAppUrl) {
|
|
177
|
-
throw new Error('No client app url specified.');
|
|
178
|
-
}
|
|
591
|
+
function _class_call_check$4(instance, Constructor) {
|
|
592
|
+
if (!(instance instanceof Constructor)) {
|
|
593
|
+
throw new TypeError("Cannot call a class as a function");
|
|
179
594
|
}
|
|
180
595
|
}
|
|
181
|
-
|
|
596
|
+
function _defineProperties$2(target, props) {
|
|
597
|
+
for(var i = 0; i < props.length; i++){
|
|
598
|
+
var descriptor = props[i];
|
|
599
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
600
|
+
descriptor.configurable = true;
|
|
601
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
602
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
606
|
+
if (staticProps) _defineProperties$2(Constructor, staticProps);
|
|
607
|
+
return Constructor;
|
|
608
|
+
}
|
|
609
|
+
function _define_property$2(obj, key, value) {
|
|
610
|
+
if (key in obj) {
|
|
611
|
+
Object.defineProperty(obj, key, {
|
|
612
|
+
value: value,
|
|
613
|
+
enumerable: true,
|
|
614
|
+
configurable: true,
|
|
615
|
+
writable: true
|
|
616
|
+
});
|
|
617
|
+
} else {
|
|
618
|
+
obj[key] = value;
|
|
619
|
+
}
|
|
620
|
+
return obj;
|
|
621
|
+
}
|
|
182
622
|
/**
|
|
183
|
-
*
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
this
|
|
623
|
+
* Abstract service configuration that provides access to the client application config.
|
|
624
|
+
*
|
|
625
|
+
* Subclass this to supply environment-specific client URLs to NestJS services.
|
|
626
|
+
*/ var ClientAppServiceConfig = /*#__PURE__*/ function() {
|
|
627
|
+
function ClientAppServiceConfig() {
|
|
628
|
+
_class_call_check$4(this, ClientAppServiceConfig);
|
|
629
|
+
_define_property$2(this, "client", void 0);
|
|
189
630
|
}
|
|
190
|
-
|
|
191
|
-
|
|
631
|
+
_create_class$2(ClientAppServiceConfig, null, [
|
|
632
|
+
{
|
|
633
|
+
key: "assertValidConfig",
|
|
634
|
+
value: /**
|
|
635
|
+
* Validates that the configuration contains a non-empty client web app URL.
|
|
636
|
+
*
|
|
637
|
+
* @param config - The configuration to validate
|
|
638
|
+
* @throws {Error} When `clientWebAppUrl` is not specified
|
|
639
|
+
*/ function assertValidConfig(config) {
|
|
640
|
+
if (!config.client.clientWebAppUrl) {
|
|
641
|
+
throw new Error('No client app url specified.');
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
]);
|
|
646
|
+
return ClientAppServiceConfig;
|
|
647
|
+
}
|
|
648
|
+
();
|
|
649
|
+
|
|
650
|
+
function _class_call_check$3(instance, Constructor) {
|
|
651
|
+
if (!(instance instanceof Constructor)) {
|
|
652
|
+
throw new TypeError("Cannot call a class as a function");
|
|
192
653
|
}
|
|
193
|
-
|
|
194
|
-
|
|
654
|
+
}
|
|
655
|
+
function _defineProperties$1(target, props) {
|
|
656
|
+
for(var i = 0; i < props.length; i++){
|
|
657
|
+
var descriptor = props[i];
|
|
658
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
659
|
+
descriptor.configurable = true;
|
|
660
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
661
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
195
662
|
}
|
|
196
|
-
|
|
197
|
-
|
|
663
|
+
}
|
|
664
|
+
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
665
|
+
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
666
|
+
return Constructor;
|
|
667
|
+
}
|
|
668
|
+
function _define_property$1(obj, key, value) {
|
|
669
|
+
if (key in obj) {
|
|
670
|
+
Object.defineProperty(obj, key, {
|
|
671
|
+
value: value,
|
|
672
|
+
enumerable: true,
|
|
673
|
+
configurable: true,
|
|
674
|
+
writable: true
|
|
675
|
+
});
|
|
676
|
+
} else {
|
|
677
|
+
obj[key] = value;
|
|
198
678
|
}
|
|
199
|
-
|
|
679
|
+
return obj;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Provides information about companion apps and websites for the project.
|
|
683
|
+
*/ var ClientAppService = /*#__PURE__*/ function() {
|
|
684
|
+
function ClientAppService(config) {
|
|
685
|
+
_class_call_check$3(this, ClientAppService);
|
|
686
|
+
_define_property$1(this, "_config", void 0);
|
|
687
|
+
this._config = config;
|
|
688
|
+
}
|
|
689
|
+
_create_class$1(ClientAppService, [
|
|
690
|
+
{
|
|
691
|
+
key: "config",
|
|
692
|
+
get: function get() {
|
|
693
|
+
return this._config;
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
key: "webAppUrl",
|
|
698
|
+
get: function get() {
|
|
699
|
+
return this.config.client.clientWebAppUrl;
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
key: "webAppHost",
|
|
704
|
+
get: function get() {
|
|
705
|
+
return this.webAppUrl.split('://', 2)[1];
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
]);
|
|
709
|
+
return ClientAppService;
|
|
710
|
+
}();
|
|
200
711
|
ClientAppService = __decorate([
|
|
201
712
|
Injectable(),
|
|
202
713
|
__param(0, Inject(ClientAppServiceConfig))
|
|
203
714
|
], ClientAppService);
|
|
204
715
|
|
|
716
|
+
function _class_call_check$2(instance, Constructor) {
|
|
717
|
+
if (!(instance instanceof Constructor)) {
|
|
718
|
+
throw new TypeError("Cannot call a class as a function");
|
|
719
|
+
}
|
|
720
|
+
}
|
|
205
721
|
function clientAppConfigFactory(configService) {
|
|
206
|
-
|
|
722
|
+
var config = {
|
|
207
723
|
client: {
|
|
208
724
|
clientWebAppUrl: configService.get(CLIENT_WEB_APP_URL_ENV_VAR)
|
|
209
725
|
}
|
|
@@ -211,37 +727,49 @@ function clientAppConfigFactory(configService) {
|
|
|
211
727
|
ClientAppServiceConfig.assertValidConfig(config);
|
|
212
728
|
return config;
|
|
213
729
|
}
|
|
214
|
-
|
|
730
|
+
var ClientAppModule = function ClientAppModule() {
|
|
731
|
+
_class_call_check$2(this, ClientAppModule);
|
|
215
732
|
};
|
|
216
733
|
ClientAppModule = __decorate([
|
|
217
734
|
Module({
|
|
218
|
-
imports: [
|
|
735
|
+
imports: [
|
|
736
|
+
ConfigModule
|
|
737
|
+
],
|
|
219
738
|
providers: [
|
|
220
739
|
{
|
|
221
740
|
provide: ClientAppServiceConfig,
|
|
222
|
-
inject: [
|
|
741
|
+
inject: [
|
|
742
|
+
ConfigService
|
|
743
|
+
],
|
|
223
744
|
useFactory: clientAppConfigFactory
|
|
224
745
|
}
|
|
225
746
|
],
|
|
226
|
-
exports: [
|
|
747
|
+
exports: [
|
|
748
|
+
ClientAppService
|
|
749
|
+
]
|
|
227
750
|
})
|
|
228
751
|
], ClientAppModule);
|
|
229
752
|
|
|
753
|
+
function _class_call_check$1(instance, Constructor) {
|
|
754
|
+
if (!(instance instanceof Constructor)) {
|
|
755
|
+
throw new TypeError("Cannot call a class as a function");
|
|
756
|
+
}
|
|
757
|
+
}
|
|
230
758
|
/**
|
|
231
759
|
* A server environment configuration.
|
|
232
760
|
*
|
|
233
761
|
* Explicitly states whether or not this is a production environment, and optionally some other config.
|
|
234
762
|
*
|
|
235
763
|
* This config is not meant to replace other typical configurations, like .env files, but instead is part of the build system.
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
|
-
}
|
|
764
|
+
*/ var ServerEnvironmentConfig = function ServerEnvironmentConfig() {
|
|
765
|
+
_class_call_check$1(this, ServerEnvironmentConfig);
|
|
766
|
+
}
|
|
767
|
+
;
|
|
239
768
|
|
|
240
769
|
// MARK: Tokens
|
|
241
770
|
/**
|
|
242
771
|
* Token to access a configured ServerEnvironmentServiceConfig for the app.
|
|
243
|
-
*/
|
|
244
|
-
const SERVER_ENV_TOKEN = 'SERVER_ENV_TOKEN';
|
|
772
|
+
*/ var SERVER_ENV_TOKEN = 'SERVER_ENV_TOKEN';
|
|
245
773
|
function serverEnvTokenProvider(env) {
|
|
246
774
|
return {
|
|
247
775
|
provide: SERVER_ENV_TOKEN,
|
|
@@ -251,32 +779,272 @@ function serverEnvTokenProvider(env) {
|
|
|
251
779
|
|
|
252
780
|
/**
|
|
253
781
|
* Checks process.env.NODE_ENV for "test"
|
|
254
|
-
*/
|
|
255
|
-
function isTestNodeEnv() {
|
|
782
|
+
*/ function isTestNodeEnv() {
|
|
256
783
|
return process.env['NODE_ENV'] === 'test';
|
|
257
784
|
}
|
|
258
785
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
this.env = env;
|
|
263
|
-
}
|
|
264
|
-
get isTestingEnv() {
|
|
265
|
-
return isTestNodeEnv();
|
|
786
|
+
function _class_call_check(instance, Constructor) {
|
|
787
|
+
if (!(instance instanceof Constructor)) {
|
|
788
|
+
throw new TypeError("Cannot call a class as a function");
|
|
266
789
|
}
|
|
267
|
-
|
|
268
|
-
|
|
790
|
+
}
|
|
791
|
+
function _defineProperties(target, props) {
|
|
792
|
+
for(var i = 0; i < props.length; i++){
|
|
793
|
+
var descriptor = props[i];
|
|
794
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
795
|
+
descriptor.configurable = true;
|
|
796
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
797
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
269
798
|
}
|
|
270
|
-
|
|
271
|
-
|
|
799
|
+
}
|
|
800
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
801
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
802
|
+
return Constructor;
|
|
803
|
+
}
|
|
804
|
+
function _define_property(obj, key, value) {
|
|
805
|
+
if (key in obj) {
|
|
806
|
+
Object.defineProperty(obj, key, {
|
|
807
|
+
value: value,
|
|
808
|
+
enumerable: true,
|
|
809
|
+
configurable: true,
|
|
810
|
+
writable: true
|
|
811
|
+
});
|
|
812
|
+
} else {
|
|
813
|
+
obj[key] = value;
|
|
272
814
|
}
|
|
273
|
-
|
|
274
|
-
|
|
815
|
+
return obj;
|
|
816
|
+
}
|
|
817
|
+
var ServerEnvironmentService = /*#__PURE__*/ function() {
|
|
818
|
+
function ServerEnvironmentService(env) {
|
|
819
|
+
_class_call_check(this, ServerEnvironmentService);
|
|
820
|
+
_define_property(this, "env", void 0);
|
|
821
|
+
this.env = env;
|
|
275
822
|
}
|
|
276
|
-
|
|
823
|
+
_create_class(ServerEnvironmentService, [
|
|
824
|
+
{
|
|
825
|
+
key: "isTestingEnv",
|
|
826
|
+
get: function get() {
|
|
827
|
+
return isTestNodeEnv();
|
|
828
|
+
}
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
key: "isProduction",
|
|
832
|
+
get: function get() {
|
|
833
|
+
return this.env.production;
|
|
834
|
+
}
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
key: "isStaging",
|
|
838
|
+
get: function get() {
|
|
839
|
+
return Boolean(this.env.staging);
|
|
840
|
+
}
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
key: "developerToolsEnabled",
|
|
844
|
+
get: function get() {
|
|
845
|
+
return Boolean(!this.isProduction && this.env.developerToolsEnabled);
|
|
846
|
+
}
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
key: "appUrl",
|
|
850
|
+
get: function get() {
|
|
851
|
+
return this.env.appUrl;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
]);
|
|
855
|
+
return ServerEnvironmentService;
|
|
856
|
+
}();
|
|
277
857
|
ServerEnvironmentService = __decorate([
|
|
278
858
|
Injectable(),
|
|
279
859
|
__param(0, Inject(SERVER_ENV_TOKEN))
|
|
280
860
|
], ServerEnvironmentService);
|
|
281
861
|
|
|
282
|
-
|
|
862
|
+
// MARK: Constants
|
|
863
|
+
/**
|
|
864
|
+
* AES-256-GCM encryption constants.
|
|
865
|
+
*/ var ENCRYPTED_FIELD_ALGORITHM = 'aes-256-gcm';
|
|
866
|
+
var ENCRYPTED_FIELD_IV_LENGTH = 12;
|
|
867
|
+
var ENCRYPTED_FIELD_AUTH_TAG_LENGTH = 16;
|
|
868
|
+
var ENCRYPTED_FIELD_KEY_LENGTH = 32;
|
|
869
|
+
/**
|
|
870
|
+
* Validates that the given secret is a 64-character hexadecimal string (32 bytes for AES-256).
|
|
871
|
+
*
|
|
872
|
+
* @example
|
|
873
|
+
* ```typescript
|
|
874
|
+
* isValidAES256GCMEncryptionSecret('a'.repeat(64)); // true
|
|
875
|
+
* isValidAES256GCMEncryptionSecret('too-short'); // false
|
|
876
|
+
* ```
|
|
877
|
+
*/ function isValidAES256GCMEncryptionSecret(secret) {
|
|
878
|
+
return secret.length === ENCRYPTED_FIELD_KEY_LENGTH * 2 && isHex(secret);
|
|
879
|
+
}
|
|
880
|
+
// MARK: Key Resolution
|
|
881
|
+
/**
|
|
882
|
+
* Factory that eagerly resolves and validates the encryption key from a secret source.
|
|
883
|
+
*
|
|
884
|
+
* The getter is called immediately and the key is validated on creation. The returned
|
|
885
|
+
* function provides the resolved Buffer without re-resolving or re-validating.
|
|
886
|
+
*
|
|
887
|
+
* @example
|
|
888
|
+
* ```typescript
|
|
889
|
+
* const getKey = resolveEncryptionKey('a'.repeat(64));
|
|
890
|
+
* const key: Buffer = getKey();
|
|
891
|
+
* ```
|
|
892
|
+
*
|
|
893
|
+
* @param source - The secret source configuration.
|
|
894
|
+
* @returns A getter that returns the resolved 32-byte Buffer for AES-256 encryption.
|
|
895
|
+
* @throws Error if the resolved key is not 64 hex characters.
|
|
896
|
+
*/ function resolveEncryptionKey(source) {
|
|
897
|
+
var hex = getValueFromGetter(source);
|
|
898
|
+
if (!isValidAES256GCMEncryptionSecret(hex)) {
|
|
899
|
+
throw new Error("resolveEncryptionKey: expected a ".concat(ENCRYPTED_FIELD_KEY_LENGTH * 2, "-character hexadecimal key, got ").concat(hex.length, " characters. Ensure the key contains only hex characters (0-9, a-f)."));
|
|
900
|
+
}
|
|
901
|
+
var key = Buffer.from(hex, 'hex');
|
|
902
|
+
return function() {
|
|
903
|
+
return key;
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Creates an `AES256GCMEncryption` instance that captures the resolved key in a closure.
|
|
908
|
+
*
|
|
909
|
+
* @example
|
|
910
|
+
* ```typescript
|
|
911
|
+
* const encryption = createAES256GCMEncryption('a'.repeat(64));
|
|
912
|
+
*
|
|
913
|
+
* const encrypted = encryption.encryptValue({ sensitive: 'data' });
|
|
914
|
+
* const decrypted = encryption.decryptValue<{ sensitive: string }>(encrypted);
|
|
915
|
+
*
|
|
916
|
+
* const encryptedStr = encryption.encryptString('hello');
|
|
917
|
+
* const decryptedStr = encryption.decryptString(encryptedStr);
|
|
918
|
+
* // decryptedStr === 'hello'
|
|
919
|
+
* ```
|
|
920
|
+
*
|
|
921
|
+
* @param source - The hex-encoded secret or getter for the AES-256 key.
|
|
922
|
+
* @returns An `AES256GCMEncryption` instance.
|
|
923
|
+
* @throws Error if the resolved key is not 64 hex characters.
|
|
924
|
+
*/ function createAES256GCMEncryption(source) {
|
|
925
|
+
var getKey = resolveEncryptionKey(source);
|
|
926
|
+
function encryptStringFn(plaintext) {
|
|
927
|
+
var key = getKey();
|
|
928
|
+
var iv = randomBytes(ENCRYPTED_FIELD_IV_LENGTH);
|
|
929
|
+
var cipher = createCipheriv(ENCRYPTED_FIELD_ALGORITHM, key, iv);
|
|
930
|
+
var encrypted = Buffer.concat([
|
|
931
|
+
cipher.update(plaintext, 'utf8'),
|
|
932
|
+
cipher.final()
|
|
933
|
+
]);
|
|
934
|
+
var authTag = cipher.getAuthTag();
|
|
935
|
+
var combined = Buffer.concat([
|
|
936
|
+
iv,
|
|
937
|
+
encrypted,
|
|
938
|
+
authTag
|
|
939
|
+
]);
|
|
940
|
+
return combined.toString('base64');
|
|
941
|
+
}
|
|
942
|
+
function decryptStringFn(encoded) {
|
|
943
|
+
var key = getKey();
|
|
944
|
+
var combined = Buffer.from(encoded, 'base64');
|
|
945
|
+
var iv = combined.subarray(0, ENCRYPTED_FIELD_IV_LENGTH);
|
|
946
|
+
var authTag = combined.subarray(combined.length - ENCRYPTED_FIELD_AUTH_TAG_LENGTH);
|
|
947
|
+
var ciphertext = combined.subarray(ENCRYPTED_FIELD_IV_LENGTH, combined.length - ENCRYPTED_FIELD_AUTH_TAG_LENGTH);
|
|
948
|
+
var decipher = createDecipheriv(ENCRYPTED_FIELD_ALGORITHM, key, iv);
|
|
949
|
+
decipher.setAuthTag(authTag);
|
|
950
|
+
var decrypted = Buffer.concat([
|
|
951
|
+
decipher.update(ciphertext),
|
|
952
|
+
decipher.final()
|
|
953
|
+
]);
|
|
954
|
+
return decrypted.toString('utf8');
|
|
955
|
+
}
|
|
956
|
+
var result = {
|
|
957
|
+
encryptString: encryptStringFn,
|
|
958
|
+
decryptString: decryptStringFn,
|
|
959
|
+
encryptValue: function encryptValue(value) {
|
|
960
|
+
return encryptStringFn(JSON.stringify(value));
|
|
961
|
+
},
|
|
962
|
+
decryptValue: function decryptValue(encoded) {
|
|
963
|
+
return JSON.parse(decryptStringFn(encoded));
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
return result;
|
|
967
|
+
}
|
|
968
|
+
// MARK: Standalone Functions (backwards compatibility)
|
|
969
|
+
/**
|
|
970
|
+
* Encrypts a JSON-serializable value to a base64-encoded string using AES-256-GCM.
|
|
971
|
+
*
|
|
972
|
+
* Format: base64(IV (12 bytes) + ciphertext + authTag (16 bytes))
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
* ```typescript
|
|
976
|
+
* const getKey = resolveEncryptionKey(mySecret);
|
|
977
|
+
* const encrypted = encryptValue({ sensitive: 'data' }, getKey());
|
|
978
|
+
* const decrypted = decryptValue<{ sensitive: string }>(encrypted, getKey());
|
|
979
|
+
* ```
|
|
980
|
+
*
|
|
981
|
+
* @param value - The value to encrypt (must be JSON-serializable).
|
|
982
|
+
* @param key - The 32-byte encryption key from `resolveEncryptionKey()`.
|
|
983
|
+
* @returns The encrypted value as a base64 string.
|
|
984
|
+
*/ function encryptValue(value, key) {
|
|
985
|
+
var iv = randomBytes(ENCRYPTED_FIELD_IV_LENGTH);
|
|
986
|
+
var cipher = createCipheriv(ENCRYPTED_FIELD_ALGORITHM, key, iv);
|
|
987
|
+
var plaintext = JSON.stringify(value);
|
|
988
|
+
var encrypted = Buffer.concat([
|
|
989
|
+
cipher.update(plaintext, 'utf8'),
|
|
990
|
+
cipher.final()
|
|
991
|
+
]);
|
|
992
|
+
var authTag = cipher.getAuthTag();
|
|
993
|
+
var combined = Buffer.concat([
|
|
994
|
+
iv,
|
|
995
|
+
encrypted,
|
|
996
|
+
authTag
|
|
997
|
+
]);
|
|
998
|
+
return combined.toString('base64');
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Decrypts a base64-encoded string back to the original value.
|
|
1002
|
+
*
|
|
1003
|
+
* @param encoded - The base64-encoded encrypted string (IV + ciphertext + authTag).
|
|
1004
|
+
* @param key - The 32-byte encryption key Buffer from calling the getter returned by `resolveEncryptionKey()`.
|
|
1005
|
+
* @returns The decrypted JSON-parsed value.
|
|
1006
|
+
*/ function decryptValue(encoded, key) {
|
|
1007
|
+
var combined = Buffer.from(encoded, 'base64');
|
|
1008
|
+
var iv = combined.subarray(0, ENCRYPTED_FIELD_IV_LENGTH);
|
|
1009
|
+
var authTag = combined.subarray(combined.length - ENCRYPTED_FIELD_AUTH_TAG_LENGTH);
|
|
1010
|
+
var ciphertext = combined.subarray(ENCRYPTED_FIELD_IV_LENGTH, combined.length - ENCRYPTED_FIELD_AUTH_TAG_LENGTH);
|
|
1011
|
+
var decipher = createDecipheriv(ENCRYPTED_FIELD_ALGORITHM, key, iv);
|
|
1012
|
+
decipher.setAuthTag(authTag);
|
|
1013
|
+
var decrypted = Buffer.concat([
|
|
1014
|
+
decipher.update(ciphertext),
|
|
1015
|
+
decipher.final()
|
|
1016
|
+
]);
|
|
1017
|
+
return JSON.parse(decrypted.toString('utf8'));
|
|
1018
|
+
}
|
|
1019
|
+
// MARK: StringEncryptionProvider
|
|
1020
|
+
/**
|
|
1021
|
+
* Creates a `StringEncryptionProvider` backed by AES-256-GCM from a secret source.
|
|
1022
|
+
*
|
|
1023
|
+
* The key is resolved and validated eagerly at creation time. The provider encrypts/decrypts
|
|
1024
|
+
* raw strings (no JSON serialization) — suitable for use with `selectiveFieldEncryptor`.
|
|
1025
|
+
*
|
|
1026
|
+
* @example
|
|
1027
|
+
* ```typescript
|
|
1028
|
+
* const provider = createAesStringEncryptionProvider('a'.repeat(64));
|
|
1029
|
+
* const encrypted = provider.encrypt('sensitive data');
|
|
1030
|
+
* const decrypted = provider.decrypt(encrypted);
|
|
1031
|
+
* // decrypted === 'sensitive data'
|
|
1032
|
+
* ```
|
|
1033
|
+
*
|
|
1034
|
+
* @param source - The hex-encoded secret or getter for the AES-256 key.
|
|
1035
|
+
* @returns A `StringEncryptionProvider` that encrypts/decrypts strings via AES-256-GCM.
|
|
1036
|
+
* @throws Error if the resolved key is not 64 hex characters.
|
|
1037
|
+
*/ function createAesStringEncryptionProvider(source) {
|
|
1038
|
+
var encryption = createAES256GCMEncryption(source);
|
|
1039
|
+
var result = {
|
|
1040
|
+
encrypt: function encrypt(plaintext) {
|
|
1041
|
+
return encryption.encryptString(plaintext);
|
|
1042
|
+
},
|
|
1043
|
+
decrypt: function decrypt(ciphertext) {
|
|
1044
|
+
return encryption.decryptString(ciphertext);
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
return result;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
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, createAES256GCMEncryption, createAesStringEncryptionProvider, decryptValue, encryptValue, injectionTokensFromProviders, isLocalhost, isTestNodeEnv, isValidAES256GCMEncryptionSecret, mergeModuleMetadata, resolveEncryptionKey, serverEnvTokenProvider };
|