1 | (function webpackUniversalModuleDefinition(root, factory) {
|
2 | if(typeof exports === 'object' && typeof module === 'object')
|
3 | module.exports = factory();
|
4 | else if(typeof define === 'function' && define.amd)
|
5 | define([], factory);
|
6 | else {
|
7 | var a = factory();
|
8 | for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
9 | }
|
10 | })(global, function() {
|
11 | return (function(modules) {
|
12 |
|
13 | var installedModules = {};
|
14 |
|
15 |
|
16 | function __webpack_require__(moduleId) {
|
17 |
|
18 |
|
19 | if(installedModules[moduleId]) {
|
20 | return installedModules[moduleId].exports;
|
21 | }
|
22 |
|
23 | var module = installedModules[moduleId] = {
|
24 | i: moduleId,
|
25 | l: false,
|
26 | exports: {}
|
27 | };
|
28 |
|
29 |
|
30 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31 |
|
32 |
|
33 | module.l = true;
|
34 |
|
35 |
|
36 | return module.exports;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 | __webpack_require__.m = modules;
|
42 |
|
43 |
|
44 | __webpack_require__.c = installedModules;
|
45 |
|
46 |
|
47 | __webpack_require__.d = function(exports, name, getter) {
|
48 | if(!__webpack_require__.o(exports, name)) {
|
49 | Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
50 | }
|
51 | };
|
52 |
|
53 |
|
54 | __webpack_require__.r = function(exports) {
|
55 | if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
56 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
57 | }
|
58 | Object.defineProperty(exports, '__esModule', { value: true });
|
59 | };
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | __webpack_require__.t = function(value, mode) {
|
67 | if(mode & 1) value = __webpack_require__(value);
|
68 | if(mode & 8) return value;
|
69 | if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
70 | var ns = Object.create(null);
|
71 | __webpack_require__.r(ns);
|
72 | Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
73 | if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
74 | return ns;
|
75 | };
|
76 |
|
77 |
|
78 | __webpack_require__.n = function(module) {
|
79 | var getter = module && module.__esModule ?
|
80 | function getDefault() { return module['default']; } :
|
81 | function getModuleExports() { return module; };
|
82 | __webpack_require__.d(getter, 'a', getter);
|
83 | return getter;
|
84 | };
|
85 |
|
86 |
|
87 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
88 |
|
89 |
|
90 | __webpack_require__.p = "";
|
91 |
|
92 |
|
93 |
|
94 | return __webpack_require__(__webpack_require__.s = "./src/Plugins/BodyParser/main.ts");
|
95 | })
|
96 |
|
97 | ({
|
98 |
|
99 | "./node_modules/content-type/index.js":
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | (function(module, exports, __webpack_require__) {
|
105 |
|
106 | "use strict";
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g
|
130 | var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/
|
131 | var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g
|
140 |
|
141 |
|
142 |
|
143 |
|
144 | var QUOTE_REGEXP = /([\\"])/g
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | exports.format = format
|
161 | exports.parse = parse
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 | function format (obj) {
|
172 | if (!obj || typeof obj !== 'object') {
|
173 | throw new TypeError('argument obj is required')
|
174 | }
|
175 |
|
176 | var parameters = obj.parameters
|
177 | var type = obj.type
|
178 |
|
179 | if (!type || !TYPE_REGEXP.test(type)) {
|
180 | throw new TypeError('invalid type')
|
181 | }
|
182 |
|
183 | var string = type
|
184 |
|
185 |
|
186 | if (parameters && typeof parameters === 'object') {
|
187 | var param
|
188 | var params = Object.keys(parameters).sort()
|
189 |
|
190 | for (var i = 0; i < params.length; i++) {
|
191 | param = params[i]
|
192 |
|
193 | if (!TOKEN_REGEXP.test(param)) {
|
194 | throw new TypeError('invalid parameter name')
|
195 | }
|
196 |
|
197 | string += '; ' + param + '=' + qstring(parameters[param])
|
198 | }
|
199 | }
|
200 |
|
201 | return string
|
202 | }
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 | function parse (string) {
|
213 | if (!string) {
|
214 | throw new TypeError('argument string is required')
|
215 | }
|
216 |
|
217 |
|
218 | var header = typeof string === 'object'
|
219 | ? getcontenttype(string)
|
220 | : string
|
221 |
|
222 | if (typeof header !== 'string') {
|
223 | throw new TypeError('argument string is required to be a string')
|
224 | }
|
225 |
|
226 | var index = header.indexOf(';')
|
227 | var type = index !== -1
|
228 | ? header.substr(0, index).trim()
|
229 | : header.trim()
|
230 |
|
231 | if (!TYPE_REGEXP.test(type)) {
|
232 | throw new TypeError('invalid media type')
|
233 | }
|
234 |
|
235 | var obj = new ContentType(type.toLowerCase())
|
236 |
|
237 |
|
238 | if (index !== -1) {
|
239 | var key
|
240 | var match
|
241 | var value
|
242 |
|
243 | PARAM_REGEXP.lastIndex = index
|
244 |
|
245 | while ((match = PARAM_REGEXP.exec(header))) {
|
246 | if (match.index !== index) {
|
247 | throw new TypeError('invalid parameter format')
|
248 | }
|
249 |
|
250 | index += match[0].length
|
251 | key = match[1].toLowerCase()
|
252 | value = match[2]
|
253 |
|
254 | if (value[0] === '"') {
|
255 |
|
256 | value = value
|
257 | .substr(1, value.length - 2)
|
258 | .replace(QESC_REGEXP, '$1')
|
259 | }
|
260 |
|
261 | obj.parameters[key] = value
|
262 | }
|
263 |
|
264 | if (index !== header.length) {
|
265 | throw new TypeError('invalid parameter format')
|
266 | }
|
267 | }
|
268 |
|
269 | return obj
|
270 | }
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | function getcontenttype (obj) {
|
281 | var header
|
282 |
|
283 | if (typeof obj.getHeader === 'function') {
|
284 |
|
285 | header = obj.getHeader('content-type')
|
286 | } else if (typeof obj.headers === 'object') {
|
287 |
|
288 | header = obj.headers && obj.headers['content-type']
|
289 | }
|
290 |
|
291 | if (typeof header !== 'string') {
|
292 | throw new TypeError('content-type header is missing from object')
|
293 | }
|
294 |
|
295 | return header
|
296 | }
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 | function qstring (val) {
|
307 | var str = String(val)
|
308 |
|
309 |
|
310 | if (TOKEN_REGEXP.test(str)) {
|
311 | return str
|
312 | }
|
313 |
|
314 | if (str.length > 0 && !TEXT_REGEXP.test(str)) {
|
315 | throw new TypeError('invalid parameter value')
|
316 | }
|
317 |
|
318 | return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"'
|
319 | }
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 | function ContentType (type) {
|
326 | this.parameters = Object.create(null)
|
327 | this.type = type
|
328 | }
|
329 |
|
330 |
|
331 | }),
|
332 |
|
333 | "./src/Plugins/BodyParser/Constants/ContentType.ts":
|
334 |
|
335 |
|
336 |
|
337 |
|
338 | (function(module, exports, __webpack_require__) {
|
339 |
|
340 | "use strict";
|
341 |
|
342 | Object.defineProperty(exports, "__esModule", { value: true });
|
343 | var ContentType;
|
344 | (function (ContentType) {
|
345 | ContentType["APPLICATION_JSON"] = "application/json";
|
346 | })(ContentType || (ContentType = {}));
|
347 | exports.default = ContentType;
|
348 |
|
349 |
|
350 | }),
|
351 |
|
352 | "./src/Plugins/BodyParser/Constants/ErrorTypes.ts":
|
353 |
|
354 |
|
355 |
|
356 |
|
357 | (function(module, exports, __webpack_require__) {
|
358 |
|
359 | "use strict";
|
360 |
|
361 | Object.defineProperty(exports, "__esModule", { value: true });
|
362 | var ErrorTypes;
|
363 | (function (ErrorTypes) {
|
364 | ErrorTypes["BODY_PARSER_OPTION_TYPE_INVALID"] = "BODY_PARSER_OPTION_TYPE_INVALID";
|
365 | ErrorTypes["BODY_PARSER_REQUEST_HEADERS_MISSING"] = "BODY_PARSER_REQUEST_HEADERS_MISSING";
|
366 | ErrorTypes["BODY_PARSER_REQUEST_HEADERS_CONTENT_TYPE_KEY_INVALID"] = "BODY_PARSER_REQUEST_HEADERS_CONTENT_TYPE_KEY_INVALID";
|
367 | ErrorTypes["BODY_PARSER_REQUEST_HEADERS_CONTENT_TYPE_VALUE_INVALID"] = "BODY_PARSER_REQUEST_HEADERS_CONTENT_TYPE_VALUE_INVALID";
|
368 | ErrorTypes["BODY_PARSER_JSON_PARSE_FAILED"] = "BODY_PARSER_JSON_PARSE_FAILED";
|
369 | })(ErrorTypes || (ErrorTypes = {}));
|
370 | exports.default = ErrorTypes;
|
371 |
|
372 |
|
373 | }),
|
374 |
|
375 | "./src/Plugins/BodyParser/Constants/ParsingOption.ts":
|
376 |
|
377 |
|
378 |
|
379 |
|
380 | (function(module, exports, __webpack_require__) {
|
381 |
|
382 | "use strict";
|
383 |
|
384 | Object.defineProperty(exports, "__esModule", { value: true });
|
385 | var ParsingOption;
|
386 | (function (ParsingOption) {
|
387 | ParsingOption["JSON"] = "json";
|
388 | ParsingOption["RAW"] = "raw";
|
389 | ParsingOption["TEXT"] = "text";
|
390 | ParsingOption["URL_ENCODED"] = "urlencoded";
|
391 | })(ParsingOption || (ParsingOption = {}));
|
392 | exports.default = ParsingOption;
|
393 |
|
394 |
|
395 | }),
|
396 |
|
397 | "./src/Plugins/BodyParser/Constants/RequestHeaders.ts":
|
398 |
|
399 |
|
400 |
|
401 |
|
402 | (function(module, exports, __webpack_require__) {
|
403 |
|
404 | "use strict";
|
405 |
|
406 | Object.defineProperty(exports, "__esModule", { value: true });
|
407 | var RequestHeaders;
|
408 | (function (RequestHeaders) {
|
409 | RequestHeaders["CONTENT_TYPE"] = "content-type";
|
410 | })(RequestHeaders || (RequestHeaders = {}));
|
411 | exports.default = RequestHeaders;
|
412 |
|
413 |
|
414 | }),
|
415 |
|
416 | "./src/Plugins/BodyParser/Utils/toLowerCaseShallow.ts":
|
417 |
|
418 |
|
419 |
|
420 |
|
421 | (function(module, exports, __webpack_require__) {
|
422 |
|
423 | "use strict";
|
424 |
|
425 | Object.defineProperty(exports, "__esModule", { value: true });
|
426 | var toLowerCaseShallow = function (obj) {
|
427 | return Object.keys(obj).reduce(function (output, currentKey) {
|
428 | var key = currentKey.toLowerCase();
|
429 | var value = obj[currentKey];
|
430 | if (typeof value === 'string')
|
431 | value = value.toLowerCase();
|
432 | output[key] = value;
|
433 | return output;
|
434 | }, {});
|
435 | };
|
436 | exports.default = toLowerCaseShallow;
|
437 |
|
438 |
|
439 | }),
|
440 |
|
441 | "./src/Plugins/BodyParser/bodyParser.ts":
|
442 |
|
443 |
|
444 |
|
445 |
|
446 | (function(module, exports, __webpack_require__) {
|
447 |
|
448 | "use strict";
|
449 |
|
450 | Object.defineProperty(exports, "__esModule", { value: true });
|
451 | var _a;
|
452 | var ParsingOption_1 = __webpack_require__( "./src/Plugins/BodyParser/Constants/ParsingOption.ts");
|
453 | var json_1 = __webpack_require__( "./src/Plugins/BodyParser/json.ts");
|
454 | var bodyParser = (_a = {},
|
455 | _a[ParsingOption_1.default.JSON] = json_1.default,
|
456 | _a);
|
457 | exports.default = bodyParser;
|
458 |
|
459 |
|
460 | }),
|
461 |
|
462 | "./src/Plugins/BodyParser/json.ts":
|
463 |
|
464 |
|
465 |
|
466 |
|
467 | (function(module, exports, __webpack_require__) {
|
468 |
|
469 | "use strict";
|
470 |
|
471 | Object.defineProperty(exports, "__esModule", { value: true });
|
472 | var contentType = __webpack_require__( "./node_modules/content-type/index.js");
|
473 | var createError_1 = __webpack_require__( "./src/Utils/createError.ts");
|
474 | var ContentType_1 = __webpack_require__( "./src/Plugins/BodyParser/Constants/ContentType.ts");
|
475 | var ErrorTypes_1 = __webpack_require__( "./src/Plugins/BodyParser/Constants/ErrorTypes.ts");
|
476 | var RequestHeaders_1 = __webpack_require__( "./src/Plugins/BodyParser/Constants/RequestHeaders.ts");
|
477 | var toLowerCaseShallow_1 = __webpack_require__( "./src/Plugins/BodyParser/Utils/toLowerCaseShallow.ts");
|
478 | var jsonParser = function (handler) {
|
479 | var request = handler.event;
|
480 | if (!request.headers) {
|
481 | throw createError_1.default({
|
482 | type: ErrorTypes_1.default.BODY_PARSER_REQUEST_HEADERS_MISSING
|
483 | });
|
484 | }
|
485 | var content;
|
486 | request.headers = toLowerCaseShallow_1.default(request.headers);
|
487 | try {
|
488 | content = contentType.parse(handler.event);
|
489 | }
|
490 | catch (e) {
|
491 | throw createError_1.default({
|
492 | type: ErrorTypes_1.default.BODY_PARSER_REQUEST_HEADERS_CONTENT_TYPE_KEY_INVALID,
|
493 | details: RequestHeaders_1.default.CONTENT_TYPE,
|
494 | source: e
|
495 | });
|
496 | }
|
497 | if (content.type !== ContentType_1.default.APPLICATION_JSON) {
|
498 | throw createError_1.default({
|
499 | type: ErrorTypes_1.default.BODY_PARSER_REQUEST_HEADERS_CONTENT_TYPE_VALUE_INVALID,
|
500 | details: content.type
|
501 | });
|
502 | }
|
503 | try {
|
504 | request.body = JSON.parse(request.body);
|
505 | }
|
506 | catch (e) {
|
507 | throw createError_1.default({
|
508 | type: ErrorTypes_1.default.BODY_PARSER_JSON_PARSE_FAILED,
|
509 | details: e
|
510 | });
|
511 | }
|
512 | };
|
513 | exports.default = jsonParser;
|
514 |
|
515 |
|
516 | }),
|
517 |
|
518 | "./src/Plugins/BodyParser/main.ts":
|
519 |
|
520 |
|
521 |
|
522 |
|
523 | (function(module, exports, __webpack_require__) {
|
524 |
|
525 | "use strict";
|
526 |
|
527 | Object.defineProperty(exports, "__esModule", { value: true });
|
528 | var createError_1 = __webpack_require__( "./src/Utils/createError.ts");
|
529 | var bodyParser_1 = __webpack_require__( "./src/Plugins/BodyParser/bodyParser.ts");
|
530 | var ErrorTypes_1 = __webpack_require__( "./src/Plugins/BodyParser/Constants/ErrorTypes.ts");
|
531 | var ParsingOption_1 = __webpack_require__( "./src/Plugins/BodyParser/Constants/ParsingOption.ts");
|
532 | var validate = function (config) {
|
533 | if (!Object['values'](ParsingOption_1.default).includes(config.type)) {
|
534 | return createError_1.default({
|
535 | type: ErrorTypes_1.default.BODY_PARSER_OPTION_TYPE_INVALID,
|
536 | details: 'one of json|raw|text|urlencoded'
|
537 | });
|
538 | }
|
539 | };
|
540 | var bodyParserPlugin = function (config) {
|
541 | var pluginManifest = {
|
542 | plugin: {
|
543 | onRequest: function (handler) {
|
544 | var error = validate(config);
|
545 | if (error) {
|
546 | throw error;
|
547 | }
|
548 | var parser = bodyParser_1.default[config.type];
|
549 | parser(handler);
|
550 | }
|
551 | }
|
552 | };
|
553 | return pluginManifest;
|
554 | };
|
555 | exports.default = bodyParserPlugin;
|
556 |
|
557 |
|
558 | }),
|
559 |
|
560 | "./src/Utils/createError.ts":
|
561 |
|
562 |
|
563 |
|
564 |
|
565 | (function(module, exports, __webpack_require__) {
|
566 |
|
567 | "use strict";
|
568 |
|
569 | Object.defineProperty(exports, "__esModule", { value: true });
|
570 | var createError = function (errorEvent) {
|
571 | return errorEvent;
|
572 | };
|
573 | exports.default = createError;
|
574 |
|
575 |
|
576 | })
|
577 |
|
578 | });
|
579 | });
|
580 |
|
\ | No newline at end of file |