@spytecgps/lambda-utils 1.0.20 → 2.0.2-rc1

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.
Files changed (62) hide show
  1. package/README.md +6 -1
  2. package/dist/errors/BadRequestError.d.ts +6 -6
  3. package/dist/errors/BadRequestError.js +28 -28
  4. package/dist/errors/BaseError.d.ts +3 -0
  5. package/dist/errors/{ConflictError.js → BaseError.js} +24 -28
  6. package/dist/errors/ConflictError.d.ts +6 -6
  7. package/dist/errors/ForbiddenError.d.ts +6 -6
  8. package/dist/errors/HttpError.d.ts +8 -8
  9. package/dist/errors/HttpError.js +32 -32
  10. package/dist/errors/NotFoundError.d.ts +6 -6
  11. package/dist/errors/NotFoundError.js +28 -28
  12. package/dist/errors/UnauthorizedError.d.ts +6 -6
  13. package/dist/errors/UnauthorizedError.js +28 -28
  14. package/dist/errors/index.d.ts +6 -6
  15. package/dist/errors/index.js +12 -16
  16. package/dist/index.d.ts +7 -7
  17. package/dist/index.js +1 -19
  18. package/dist/logger/index.d.ts +4 -0
  19. package/dist/logger/logger.d.ts +3 -3
  20. package/dist/logger/logger.js +57 -51
  21. package/dist/middleware/contextualLogger.d.ts +15 -15
  22. package/dist/middleware/contextualLogger.js +87 -87
  23. package/dist/middleware/index.d.ts +12 -12
  24. package/dist/middleware/index.js +62 -62
  25. package/dist/middleware/ioLogger.d.ts +1 -1
  26. package/dist/middleware/ioLogger.js +14 -14
  27. package/dist/middleware/middleware.test.d.ts +1 -1
  28. package/dist/middleware/middleware.test.js +167 -167
  29. package/dist/middleware/responseWrapper.d.ts +3 -3
  30. package/dist/middleware/responseWrapper.js +12 -12
  31. package/dist/middleware/types.d.ts +7 -7
  32. package/dist/middleware/types.js +2 -2
  33. package/dist/middleware/validation.d.ts +9 -9
  34. package/dist/middleware/validation.js +27 -27
  35. package/dist/types.d.ts +58 -58
  36. package/dist/types.js +2 -2
  37. package/dist/utils/cache.d.ts +23 -23
  38. package/dist/utils/cacheWrapper.d.ts +2 -2
  39. package/dist/utils/index.d.ts +4 -4
  40. package/dist/utils/timeOut.d.ts +1 -1
  41. package/dist/validation/custom.d.ts +18 -18
  42. package/dist/validation/custom.js +122 -161
  43. package/dist/validation/index.d.ts +6 -5
  44. package/dist/validation/index.js +20 -25
  45. package/dist/validation/requestContext.d.ts +14 -14
  46. package/dist/validation/requestContext.js +54 -56
  47. package/dist/validation/validateEvent.d.ts +3 -3
  48. package/dist/validation/validateEvent.js +25 -25
  49. package/dist/wrappers/apiGatewayEventWrapper.d.ts +4 -4
  50. package/dist/wrappers/apiGatewayEventWrapper.js +82 -79
  51. package/dist/wrappers/index.d.ts +4 -4
  52. package/dist/wrappers/index.js +21 -21
  53. package/dist/wrappers/response.d.ts +8 -8
  54. package/dist/wrappers/response.js +35 -36
  55. package/dist/wrappers/sqsEventWrapper.d.ts +3 -3
  56. package/dist/wrappers/sqsEventWrapper.js +116 -120
  57. package/package.json +34 -34
  58. package/dist/errors/ForbiddenError.js +0 -28
  59. package/dist/utils/cache.js +0 -58
  60. package/dist/utils/cacheWrapper.js +0 -55
  61. package/dist/utils/index.js +0 -17
  62. package/dist/utils/timeOut.js +0 -15
@@ -1,4 +1,4 @@
1
- import { LambdaCache } from './cache';
2
- export * from './cacheWrapper';
3
- export * from './timeOut';
4
- export { LambdaCache };
1
+ import { LambdaCache } from './cache';
2
+ export * from './cacheWrapper';
3
+ export * from './timeOut';
4
+ export { LambdaCache };
@@ -1 +1 @@
1
- export declare const promiseWithTimeout: <T>(promise: Promise<T>, ms: number, timeoutError?: Error) => Promise<T>;
1
+ export declare const promiseWithTimeout: <T>(promise: Promise<T>, ms: number, timeoutError?: Error) => Promise<T>;
@@ -1,18 +1,18 @@
1
- import * as Joi from 'joi';
2
- import { ArraySchema, ObjectSchema, SchemaMap, StringSchema } from 'joi';
3
- export declare const json: any;
4
- export declare const urlEncoded: any;
5
- export declare const imeiSchema: Joi.StringSchema<string>;
6
- export declare const iccidSchema: Joi.StringSchema<string>;
7
- interface SpytecJoi extends Joi.Root {
8
- urlEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
9
- jsonObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
10
- imei(): StringSchema;
11
- iccid(): StringSchema;
12
- delimitedArray(): ArraySchema;
13
- dateString(): StringSchema;
14
- jsonArray<TSchema = any, T = TSchema>(schema?: Joi.SchemaMap<T>): ArraySchema<TSchema>;
15
- base64ThenUriEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
16
- }
17
- export declare const SpytecJoi: SpytecJoi;
18
- export {};
1
+ import * as Joi from 'joi';
2
+ import { ArraySchema, ObjectSchema, SchemaMap, StringSchema } from 'joi';
3
+ export declare const json: any;
4
+ export declare const urlEncoded: any;
5
+ export declare const imeiSchema: Joi.StringSchema<string>;
6
+ export declare const iccidSchema: Joi.StringSchema<string>;
7
+ interface SpytecJoi extends Joi.Root {
8
+ urlEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
9
+ jsonObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
10
+ imei(): StringSchema;
11
+ iccid(): StringSchema;
12
+ delimitedArray(): ArraySchema;
13
+ dateString(): StringSchema;
14
+ jsonArray<TSchema = any, T = TSchema>(schema?: Joi.SchemaMap<T>): ArraySchema<TSchema>;
15
+ base64ThenUriEncodedObject<TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema>;
16
+ }
17
+ export declare const SpytecJoi: SpytecJoi;
18
+ export {};
@@ -1,161 +1,122 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.SpytecJoi = exports.iccidSchema = exports.imeiSchema = exports.urlEncoded = exports.json = void 0;
26
- var Joi = __importStar(require("joi"));
27
- var qs = __importStar(require("qs"));
28
- var dayjs_1 = __importDefault(require("dayjs"));
29
- var timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
30
- var utc_1 = __importDefault(require("dayjs/plugin/utc"));
31
- dayjs_1.default.extend(utc_1.default);
32
- dayjs_1.default.extend(timezone_1.default);
33
- exports.json = Joi.extend(function (joi) {
34
- return {
35
- type: 'object',
36
- base: joi.object(),
37
- messages: {
38
- 'json.valid': 'must be valid JSON',
39
- },
40
- coerce: function (value) {
41
- try {
42
- return { value: JSON.parse(value) };
43
- }
44
- catch (err) {
45
- return null;
46
- }
47
- },
48
- validate: function (value, helpers) {
49
- if (!value) {
50
- return { value: value, errors: helpers.error('json.valid') };
51
- }
52
- return { value: value };
53
- },
54
- };
55
- });
56
- exports.urlEncoded = Joi.extend(function (joi) {
57
- return {
58
- type: 'object',
59
- base: joi.object(),
60
- coerce: function (value) {
61
- return { value: qs.parse(value) };
62
- },
63
- };
64
- });
65
- exports.imeiSchema = Joi.string()
66
- .regex(/^\d{15,16}$/)
67
- .message('Invalid IMEI');
68
- exports.iccidSchema = Joi.string()
69
- .regex(/^[0-9A-Za-z]{18,22}$/)
70
- .message('Invalid ICCID');
71
- exports.SpytecJoi = Joi.extend(function (joi) { return ({
72
- type: 'imei',
73
- messages: 'Invalid IMEI',
74
- base: joi.string().regex(/^\d{15,16}$/),
75
- }); }, function (joi) { return ({
76
- type: 'iccid',
77
- messages: 'Invalid ICCID',
78
- base: joi.string().regex(/^[0-9A-Za-z]{18,22}$/),
79
- }); }, function (joi) { return ({
80
- type: 'urlEncodedObject',
81
- base: joi.object(),
82
- coerce: function (value) {
83
- return { value: qs.parse(value) };
84
- },
85
- }); }, function (joi) { return ({
86
- type: 'jsonObject',
87
- base: joi.object(),
88
- coerce: function (value) {
89
- try {
90
- return { value: JSON.parse(value) };
91
- }
92
- catch (err) {
93
- return null;
94
- }
95
- },
96
- validate: function (value, helpers) {
97
- if (!value) {
98
- return { value: value, errors: helpers.error('json.valid') };
99
- }
100
- return { value: value };
101
- },
102
- }); }, function (joi) { return ({
103
- type: 'delimitedArray',
104
- base: joi.array().default([]),
105
- coerce: function (value) { return ({
106
- value: value.split ? value.split(',') : value,
107
- }); },
108
- }); }, function (joi) { return ({
109
- type: 'queryStringParameters',
110
- messages: 'Missing query parameters',
111
- base: joi.object().required(),
112
- }); }, function (joi) { return ({
113
- type: 'date',
114
- base: joi.date(),
115
- prepare: function (value, helpers) {
116
- try {
117
- var dayjsDate = dayjs_1.default.tz(value, 'UTC');
118
- if (dayjsDate.isValid()) {
119
- return { value: dayjsDate.toDate() };
120
- }
121
- }
122
- catch (error) {
123
- return helpers.error('any.invalid');
124
- }
125
- },
126
- }); }, function (joi) { return ({
127
- type: 'jsonArray',
128
- base: joi.array(),
129
- coerce: function (value) {
130
- try {
131
- return { value: JSON.parse(value) };
132
- }
133
- catch (err) {
134
- return { value: null };
135
- }
136
- },
137
- validate: function (value, helpers) {
138
- if (!Array.isArray(value)) {
139
- return { value: value, errors: helpers.error('jsonArray.schema') };
140
- }
141
- return { value: value };
142
- },
143
- }); }, function (joi) { return ({
144
- type: 'base64ThenUriEncodedObject',
145
- base: joi.object(),
146
- coerce: function (value) {
147
- try {
148
- var decodedValue = decodeURIComponent(Buffer.from(value, 'base64').toString());
149
- return { value: JSON.parse(decodedValue) };
150
- }
151
- catch (err) {
152
- return null;
153
- }
154
- },
155
- validate: function (value, helpers) {
156
- if (!value) {
157
- return { value: value, errors: helpers.error('json.valid') };
158
- }
159
- return { value: value };
160
- },
161
- }); });
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.SpytecJoi = exports.iccidSchema = exports.imeiSchema = exports.urlEncoded = exports.json = void 0;
23
+ var Joi = __importStar(require("joi"));
24
+ var qs = __importStar(require("qs"));
25
+ var moment = __importStar(require("moment-timezone"));
26
+ exports.json = Joi.extend(function (joi) {
27
+ return {
28
+ type: 'object',
29
+ base: joi.object(),
30
+ messages: {
31
+ 'json.valid': 'must be valid JSON',
32
+ },
33
+ coerce: function (value) {
34
+ try {
35
+ return { value: JSON.parse(value) };
36
+ }
37
+ catch (err) {
38
+ return null;
39
+ }
40
+ },
41
+ validate: function (value, helpers) {
42
+ if (!value) {
43
+ return { value: value, errors: helpers.error('json.valid') };
44
+ }
45
+ return { value: value };
46
+ },
47
+ };
48
+ });
49
+ exports.urlEncoded = Joi.extend(function (joi) {
50
+ return {
51
+ type: 'object',
52
+ base: joi.object(),
53
+ coerce: function (value) {
54
+ return { value: qs.parse(value) };
55
+ },
56
+ };
57
+ });
58
+ exports.imeiSchema = Joi.string()
59
+ .regex(/^\d{15,16}$/)
60
+ .error(new Error('Invalid IMEI'));
61
+ exports.iccidSchema = Joi.string()
62
+ .regex(/^[0-9A-Za-z]{18,22}$/)
63
+ .error(new Error('Invalid ICCID'));
64
+ exports.SpytecJoi = Joi.extend(function (joi) { return ({
65
+ type: 'imei',
66
+ base: joi
67
+ .string()
68
+ .regex(/^\d{15,16}$/)
69
+ .error(new Error('Invalid IMEI')),
70
+ }); }, function (joi) { return ({
71
+ type: 'iccid',
72
+ base: joi
73
+ .string()
74
+ .regex(/^[0-9A-Za-z]{18,22}$/)
75
+ .error(new Error('Invalid ICCID')),
76
+ }); }, function (joi) { return ({
77
+ type: 'urlEncodedObject',
78
+ base: joi.object(),
79
+ coerce: function (value) {
80
+ return { value: qs.parse(value) };
81
+ },
82
+ }); }, function (joi) { return ({
83
+ type: 'jsonObject',
84
+ base: joi.object(),
85
+ messages: {
86
+ 'json.valid': 'must be valid JSON',
87
+ },
88
+ coerce: function (value) {
89
+ try {
90
+ return { value: JSON.parse(value) };
91
+ }
92
+ catch (err) {
93
+ return null;
94
+ }
95
+ },
96
+ validate: function (value, helpers) {
97
+ if (!value) {
98
+ return { value: value, errors: helpers.error('json.valid') };
99
+ }
100
+ return { value: value };
101
+ },
102
+ }); }, function (joi) { return ({
103
+ type: 'delimitedArray',
104
+ base: joi.array().default([]),
105
+ coerce: function (value) { return ({
106
+ value: value.split ? value.split(',') : value,
107
+ }); },
108
+ }); }, function (joi) { return ({
109
+ type: 'queryStringParameters',
110
+ base: joi
111
+ .object()
112
+ .required()
113
+ .error(new Error('Missing query parameters')),
114
+ }); }, function (joi) { return ({
115
+ type: 'date',
116
+ base: joi.date(),
117
+ prepare: function (value) {
118
+ return {
119
+ value: moment.tz(value, 'UTC').toDate(),
120
+ };
121
+ },
122
+ }); });
@@ -1,5 +1,6 @@
1
- import validateEvent from './validateEvent';
2
- export { validateEvent };
3
- export * from './custom';
4
- export * from './requestContext';
5
- export declare const defaultApiSchema: import("joi").ObjectSchema<Pick<import("aws-lambda").APIGatewayProxyEventBase<import("../types").SpytecAuthContext>, "headers" | "path" | "multiValueHeaders" | "httpMethod" | "isBase64Encoded" | "multiValueQueryStringParameters" | "stageVariables" | "requestContext" | "resource">>;
1
+ import { BaseAPIGatewayEvent } from '../types';
2
+ import validateEvent from './validateEvent';
3
+ export { validateEvent };
4
+ export * from './custom';
5
+ export * from './requestContext';
6
+ export declare const defaultApiSchema: import("joi").ObjectSchema<BaseAPIGatewayEvent>;
@@ -1,25 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- };
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.defaultApiSchema = exports.validateEvent = void 0;
17
- var validateEvent_1 = __importDefault(require("./validateEvent"));
18
- exports.validateEvent = validateEvent_1.default;
19
- var requestContext_1 = require("./requestContext");
20
- var custom_1 = require("./custom");
21
- __exportStar(require("./custom"), exports);
22
- __exportStar(require("./requestContext"), exports);
23
- exports.defaultApiSchema = custom_1.SpytecJoi.object({
24
- requestContext: requestContext_1.getRequestContextValidator(),
25
- });
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.validateEvent = void 0;
17
+ var validateEvent_1 = __importDefault(require("./validateEvent"));
18
+ exports.validateEvent = validateEvent_1.default;
19
+ __exportStar(require("./custom"), exports);
20
+ __exportStar(require("./requestContext"), exports);
@@ -1,14 +1,14 @@
1
- import * as Joi from 'joi';
2
- import { AuthClass, SpytecAuthContext } from '../types';
3
- import { APIGatewayEventRequestContextWithAuthorizer } from 'aws-lambda/common/api-gateway';
4
- interface GetAuthorizerValidatorParams {
5
- scope?: string;
6
- type?: AuthClass;
7
- }
8
- export declare const getAuthorizerValidator: ({ scope, type }?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<SpytecAuthContext>;
9
- /**
10
- * @deprecated
11
- */
12
- export declare const requestContextValidator: Joi.ObjectSchema<any>;
13
- export declare const getRequestContextValidator: (params?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<APIGatewayEventRequestContextWithAuthorizer<SpytecAuthContext>>;
14
- export {};
1
+ import { APIGatewayEventRequestContextWithAuthorizer } from 'aws-lambda/common/api-gateway';
2
+ import * as Joi from 'joi';
3
+ import { AuthClass, SpytecAuthContext } from '../types';
4
+ interface GetAuthorizerValidatorParams {
5
+ scope?: string;
6
+ type?: AuthClass;
7
+ }
8
+ export declare const getAuthorizerValidator: ({ scope, type }?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<SpytecAuthContext>;
9
+ /**
10
+ * @deprecated
11
+ */
12
+ export declare const requestContextValidator: Joi.ObjectSchema<any>;
13
+ export declare const getRequestContextValidator: (params?: GetAuthorizerValidatorParams) => Joi.ObjectSchema<APIGatewayEventRequestContextWithAuthorizer<SpytecAuthContext>>;
14
+ export {};
@@ -1,56 +1,54 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getRequestContextValidator = exports.requestContextValidator = exports.getAuthorizerValidator = void 0;
23
- var Joi = __importStar(require("joi"));
24
- var errors_1 = require("../errors");
25
- var custom_1 = require("./custom");
26
- exports.getAuthorizerValidator = function (_a) {
27
- var _b = _a === void 0 ? {} : _a, scope = _b.scope, type = _b.type;
28
- return Joi.object({
29
- clientId: Joi.number(),
30
- resources: custom_1.json.object({}),
31
- scope: scope
32
- ? Joi.string()
33
- .pattern(new RegExp("" + scope))
34
- .error(function () { return new errors_1.UnauthorizedError("missing scope " + scope); })
35
- : Joi.optional(),
36
- type: type
37
- ? Joi.any()
38
- .valid(type)
39
- .error(function () { return new errors_1.UnauthorizedError("missing user type " + type); })
40
- : Joi.optional(),
41
- enterprise: Joi.boolean().default(false),
42
- maintenanceModule: Joi.boolean().default(false),
43
- });
44
- };
45
- /**
46
- * @deprecated
47
- */
48
- exports.requestContextValidator = Joi.object({
49
- authorizer: exports.getAuthorizerValidator(),
50
- });
51
- exports.getRequestContextValidator = function (params) {
52
- if (params === void 0) { params = {}; }
53
- return Joi.object({
54
- authorizer: exports.getAuthorizerValidator(params),
55
- });
56
- };
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getRequestContextValidator = exports.requestContextValidator = exports.getAuthorizerValidator = void 0;
23
+ var Joi = __importStar(require("joi"));
24
+ var errors_1 = require("../errors");
25
+ var custom_1 = require("./custom");
26
+ exports.getAuthorizerValidator = function (_a) {
27
+ var _b = _a === void 0 ? {} : _a, scope = _b.scope, type = _b.type;
28
+ return Joi.object({
29
+ clientId: Joi.number(),
30
+ resources: custom_1.json.object({}),
31
+ scope: scope
32
+ ? Joi.string()
33
+ .pattern(new RegExp("" + scope))
34
+ .error(function () { return new errors_1.UnauthorizedError("missing scope " + scope); })
35
+ : Joi.optional(),
36
+ type: type
37
+ ? Joi.any()
38
+ .valid(type)
39
+ .error(function () { return new errors_1.UnauthorizedError("missing user type " + type); })
40
+ : Joi.optional(),
41
+ });
42
+ };
43
+ /**
44
+ * @deprecated
45
+ */
46
+ exports.requestContextValidator = Joi.object({
47
+ authorizer: exports.getAuthorizerValidator(),
48
+ });
49
+ exports.getRequestContextValidator = function (params) {
50
+ if (params === void 0) { params = {}; }
51
+ return Joi.object({
52
+ authorizer: exports.getAuthorizerValidator(params),
53
+ });
54
+ };
@@ -1,3 +1,3 @@
1
- import { ObjectSchema, ValidationOptions } from 'joi';
2
- declare const validateEvent: <T>(event: any, schema?: ObjectSchema<T>, validateOptions?: ValidationOptions) => T;
3
- export default validateEvent;
1
+ import { ObjectSchema, ValidationOptions } from 'joi';
2
+ declare const validateEvent: <T>(event: any, schema?: ObjectSchema<T>, validateOptions?: ValidationOptions) => T;
3
+ export default validateEvent;
@@ -1,25 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var errors_1 = require("../errors");
4
- var sdk_1 = require("@spytecgps/sdk");
5
- var validateEvent = function (event, schema, validateOptions) {
6
- if (!schema) {
7
- sdk_1.logger.warn("skipping validation");
8
- return event;
9
- }
10
- var _a = schema.validate(event, {
11
- allowUnknown: (validateOptions === null || validateOptions === void 0 ? void 0 : validateOptions.allowUnknown) || true,
12
- errors: {
13
- label: 'key',
14
- wrap: {
15
- label: false,
16
- },
17
- },
18
- }), error = _a.error, value = _a.value;
19
- if (error) {
20
- sdk_1.logger.error({ error: error }, 'Validation error');
21
- throw error.isJoi ? new errors_1.BadRequestError(error.message) : error;
22
- }
23
- return value;
24
- };
25
- exports.default = validateEvent;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var errors_1 = require("../errors");
4
+ var sdk_1 = require("@spytecgps/sdk");
5
+ var validateEvent = function (event, schema, validateOptions) {
6
+ if (!schema) {
7
+ sdk_1.logger.warn("skipping validation");
8
+ return event;
9
+ }
10
+ var _a = schema.validate(event, {
11
+ allowUnknown: (validateOptions === null || validateOptions === void 0 ? void 0 : validateOptions.allowUnknown) || true,
12
+ errors: {
13
+ label: 'key',
14
+ wrap: {
15
+ label: false,
16
+ },
17
+ },
18
+ }), error = _a.error, value = _a.value;
19
+ if (error) {
20
+ sdk_1.logger.error({ error: error }, 'Validation error');
21
+ throw error.isJoi ? new errors_1.BadRequestError(error.message) : error;
22
+ }
23
+ return value;
24
+ };
25
+ exports.default = validateEvent;
@@ -1,4 +1,4 @@
1
- import { APIGatewayProxyResult } from 'aws-lambda';
2
- import { WrapperArgs } from '../types';
3
- declare const apiGatewayEventWrapper: <E, R>({ event, context, schema, handler, }: WrapperArgs<E, R>) => Promise<APIGatewayProxyResult>;
4
- export default apiGatewayEventWrapper;
1
+ import { APIGatewayProxyResult } from 'aws-lambda';
2
+ import { WrapperArgs } from '../types';
3
+ declare const apiGatewayEventWrapper: <E, R>({ event, context, schema, handler, }: WrapperArgs<E, R>) => Promise<APIGatewayProxyResult>;
4
+ export default apiGatewayEventWrapper;