@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.
- package/README.md +6 -1
- package/dist/errors/BadRequestError.d.ts +6 -6
- package/dist/errors/BadRequestError.js +28 -28
- package/dist/errors/BaseError.d.ts +3 -0
- package/dist/errors/{ConflictError.js → BaseError.js} +24 -28
- package/dist/errors/ConflictError.d.ts +6 -6
- package/dist/errors/ForbiddenError.d.ts +6 -6
- package/dist/errors/HttpError.d.ts +8 -8
- package/dist/errors/HttpError.js +32 -32
- package/dist/errors/NotFoundError.d.ts +6 -6
- package/dist/errors/NotFoundError.js +28 -28
- package/dist/errors/UnauthorizedError.d.ts +6 -6
- package/dist/errors/UnauthorizedError.js +28 -28
- package/dist/errors/index.d.ts +6 -6
- package/dist/errors/index.js +12 -16
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -19
- package/dist/logger/index.d.ts +4 -0
- package/dist/logger/logger.d.ts +3 -3
- package/dist/logger/logger.js +57 -51
- package/dist/middleware/contextualLogger.d.ts +15 -15
- package/dist/middleware/contextualLogger.js +87 -87
- package/dist/middleware/index.d.ts +12 -12
- package/dist/middleware/index.js +62 -62
- package/dist/middleware/ioLogger.d.ts +1 -1
- package/dist/middleware/ioLogger.js +14 -14
- package/dist/middleware/middleware.test.d.ts +1 -1
- package/dist/middleware/middleware.test.js +167 -167
- package/dist/middleware/responseWrapper.d.ts +3 -3
- package/dist/middleware/responseWrapper.js +12 -12
- package/dist/middleware/types.d.ts +7 -7
- package/dist/middleware/types.js +2 -2
- package/dist/middleware/validation.d.ts +9 -9
- package/dist/middleware/validation.js +27 -27
- package/dist/types.d.ts +58 -58
- package/dist/types.js +2 -2
- package/dist/utils/cache.d.ts +23 -23
- package/dist/utils/cacheWrapper.d.ts +2 -2
- package/dist/utils/index.d.ts +4 -4
- package/dist/utils/timeOut.d.ts +1 -1
- package/dist/validation/custom.d.ts +18 -18
- package/dist/validation/custom.js +122 -161
- package/dist/validation/index.d.ts +6 -5
- package/dist/validation/index.js +20 -25
- package/dist/validation/requestContext.d.ts +14 -14
- package/dist/validation/requestContext.js +54 -56
- package/dist/validation/validateEvent.d.ts +3 -3
- package/dist/validation/validateEvent.js +25 -25
- package/dist/wrappers/apiGatewayEventWrapper.d.ts +4 -4
- package/dist/wrappers/apiGatewayEventWrapper.js +82 -79
- package/dist/wrappers/index.d.ts +4 -4
- package/dist/wrappers/index.js +21 -21
- package/dist/wrappers/response.d.ts +8 -8
- package/dist/wrappers/response.js +35 -36
- package/dist/wrappers/sqsEventWrapper.d.ts +3 -3
- package/dist/wrappers/sqsEventWrapper.js +116 -120
- package/package.json +34 -34
- package/dist/errors/ForbiddenError.js +0 -28
- package/dist/utils/cache.js +0 -58
- package/dist/utils/cacheWrapper.js +0 -55
- package/dist/utils/index.js +0 -17
- package/dist/utils/timeOut.js +0 -15
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Utility functions for serverless packages
|
|
4
4
|
|
|
5
|
+
# Lambda Utils breaking changes
|
|
6
|
+
|
|
7
|
+
If you need to use this package on Node 14 last available version is 1.0.20
|
|
8
|
+
|
|
9
|
+
If you need to use this package on Node 16 first available version is 2.0.0
|
|
10
|
+
|
|
5
11
|
### Copy Distribution folder to local project ((local testing))
|
|
6
12
|
|
|
7
13
|
when making changes and would like to avoid commiting and publishing changes.
|
|
@@ -10,4 +16,3 @@ when making changes and would like to avoid commiting and publishing changes.
|
|
|
10
16
|
2. Run `npm run copydistfolder -- {destPath}` to copy distribution folder to local project
|
|
11
17
|
ex: `npm run copydistfolder -- ../api-reports` copies dist folder to folder -> `api-reports/node_modules/@spytecgps/lambda-utils/dist`
|
|
12
18
|
3. In order for VSCode to reload and get udpated api-core copied to node_modules dist folder -> On PC you can do Ctrl + Shift + P (mac: Cmd + Shift + P) then type "Reload Window"git
|
|
13
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class BadRequestError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class BadRequestError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
var HttpError_1 = require("./HttpError");
|
|
17
|
-
var BadRequestError = /** @class */ (function (_super) {
|
|
18
|
-
__extends(BadRequestError, _super);
|
|
19
|
-
function BadRequestError() {
|
|
20
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
_this.code = 400;
|
|
22
|
-
_this.statusCode = 400;
|
|
23
|
-
_this.name = 'BadRequestError';
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
return BadRequestError;
|
|
27
|
-
}(HttpError_1.HttpError));
|
|
28
|
-
exports.default = BadRequestError;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var HttpError_1 = require("./HttpError");
|
|
17
|
+
var BadRequestError = /** @class */ (function (_super) {
|
|
18
|
+
__extends(BadRequestError, _super);
|
|
19
|
+
function BadRequestError() {
|
|
20
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
+
_this.code = 400;
|
|
22
|
+
_this.statusCode = 400;
|
|
23
|
+
_this.name = 'BadRequestError';
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
return BadRequestError;
|
|
27
|
+
}(HttpError_1.HttpError));
|
|
28
|
+
exports.default = BadRequestError;
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
__extends(
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return ConflictError;
|
|
27
|
-
}(HttpError_1.HttpError));
|
|
28
|
-
exports.default = ConflictError;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.BaseError = void 0;
|
|
17
|
+
var BaseError = /** @class */ (function (_super) {
|
|
18
|
+
__extends(BaseError, _super);
|
|
19
|
+
function BaseError() {
|
|
20
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
+
}
|
|
22
|
+
return BaseError;
|
|
23
|
+
}(Error));
|
|
24
|
+
exports.BaseError = BaseError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class ConflictError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class ConflictError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class ForbiddenError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class ForbiddenError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare abstract class HttpError extends Error {
|
|
2
|
-
abstract code: number;
|
|
3
|
-
abstract statusCode: number;
|
|
4
|
-
}
|
|
5
|
-
export declare class BaseError extends Error {
|
|
6
|
-
code: 500;
|
|
7
|
-
statusCode: 500;
|
|
8
|
-
}
|
|
1
|
+
export declare abstract class HttpError extends Error {
|
|
2
|
+
abstract code: number;
|
|
3
|
+
abstract statusCode: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class BaseError extends Error {
|
|
6
|
+
code: 500;
|
|
7
|
+
statusCode: 500;
|
|
8
|
+
}
|
package/dist/errors/HttpError.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.BaseError = exports.HttpError = void 0;
|
|
17
|
-
var HttpError = /** @class */ (function (_super) {
|
|
18
|
-
__extends(HttpError, _super);
|
|
19
|
-
function HttpError() {
|
|
20
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
}
|
|
22
|
-
return HttpError;
|
|
23
|
-
}(Error));
|
|
24
|
-
exports.HttpError = HttpError;
|
|
25
|
-
var BaseError = /** @class */ (function (_super) {
|
|
26
|
-
__extends(BaseError, _super);
|
|
27
|
-
function BaseError() {
|
|
28
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
29
|
-
}
|
|
30
|
-
return BaseError;
|
|
31
|
-
}(Error));
|
|
32
|
-
exports.BaseError = BaseError;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.BaseError = exports.HttpError = void 0;
|
|
17
|
+
var HttpError = /** @class */ (function (_super) {
|
|
18
|
+
__extends(HttpError, _super);
|
|
19
|
+
function HttpError() {
|
|
20
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
+
}
|
|
22
|
+
return HttpError;
|
|
23
|
+
}(Error));
|
|
24
|
+
exports.HttpError = HttpError;
|
|
25
|
+
var BaseError = /** @class */ (function (_super) {
|
|
26
|
+
__extends(BaseError, _super);
|
|
27
|
+
function BaseError() {
|
|
28
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
29
|
+
}
|
|
30
|
+
return BaseError;
|
|
31
|
+
}(Error));
|
|
32
|
+
exports.BaseError = BaseError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class NotFoundError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class NotFoundError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
var HttpError_1 = require("./HttpError");
|
|
17
|
-
var NotFoundError = /** @class */ (function (_super) {
|
|
18
|
-
__extends(NotFoundError, _super);
|
|
19
|
-
function NotFoundError() {
|
|
20
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
_this.code = 404;
|
|
22
|
-
_this.statusCode = 404;
|
|
23
|
-
_this.name = 'NotFoundError';
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
return NotFoundError;
|
|
27
|
-
}(HttpError_1.HttpError));
|
|
28
|
-
exports.default = NotFoundError;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var HttpError_1 = require("./HttpError");
|
|
17
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
18
|
+
__extends(NotFoundError, _super);
|
|
19
|
+
function NotFoundError() {
|
|
20
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
+
_this.code = 404;
|
|
22
|
+
_this.statusCode = 404;
|
|
23
|
+
_this.name = 'NotFoundError';
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
return NotFoundError;
|
|
27
|
+
}(HttpError_1.HttpError));
|
|
28
|
+
exports.default = NotFoundError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HttpError } from './HttpError';
|
|
2
|
-
export default class UnauthorizedError extends HttpError {
|
|
3
|
-
code: number;
|
|
4
|
-
statusCode: number;
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
1
|
+
import { HttpError } from './HttpError';
|
|
2
|
+
export default class UnauthorizedError extends HttpError {
|
|
3
|
+
code: number;
|
|
4
|
+
statusCode: number;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
var HttpError_1 = require("./HttpError");
|
|
17
|
-
var UnauthorizedError = /** @class */ (function (_super) {
|
|
18
|
-
__extends(UnauthorizedError, _super);
|
|
19
|
-
function UnauthorizedError() {
|
|
20
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
_this.code = 401;
|
|
22
|
-
_this.statusCode = 401;
|
|
23
|
-
_this.name = 'UnauthorizedError';
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
return UnauthorizedError;
|
|
27
|
-
}(HttpError_1.HttpError));
|
|
28
|
-
exports.default = UnauthorizedError;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
var HttpError_1 = require("./HttpError");
|
|
17
|
+
var UnauthorizedError = /** @class */ (function (_super) {
|
|
18
|
+
__extends(UnauthorizedError, _super);
|
|
19
|
+
function UnauthorizedError() {
|
|
20
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
+
_this.code = 401;
|
|
22
|
+
_this.statusCode = 401;
|
|
23
|
+
_this.name = 'UnauthorizedError';
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
return UnauthorizedError;
|
|
27
|
+
}(HttpError_1.HttpError));
|
|
28
|
+
exports.default = UnauthorizedError;
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import BadRequestError from './BadRequestError';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
export { BadRequestError, NotFoundError, UnauthorizedError, ForbiddenError, ConflictError };
|
|
1
|
+
import BadRequestError from './BadRequestError';
|
|
2
|
+
import ConflictError from './ConflictError';
|
|
3
|
+
import ForbiddenError from './ForbiddenError';
|
|
4
|
+
import NotFoundError from './NotFoundError';
|
|
5
|
+
import UnauthorizedError from './UnauthorizedError';
|
|
6
|
+
export { BadRequestError, NotFoundError, UnauthorizedError, ForbiddenError, ConflictError };
|
package/dist/errors/index.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
var BadRequestError_1 = __importDefault(require("./BadRequestError"));
|
|
8
|
-
exports.BadRequestError = BadRequestError_1.default;
|
|
9
|
-
var NotFoundError_1 = __importDefault(require("./NotFoundError"));
|
|
10
|
-
exports.NotFoundError = NotFoundError_1.default;
|
|
11
|
-
var UnauthorizedError_1 = __importDefault(require("./UnauthorizedError"));
|
|
12
|
-
exports.UnauthorizedError = UnauthorizedError_1.default;
|
|
13
|
-
var ForbiddenError_1 = __importDefault(require("./ForbiddenError"));
|
|
14
|
-
exports.ForbiddenError = ForbiddenError_1.default;
|
|
15
|
-
var ConflictError_1 = __importDefault(require("./ConflictError"));
|
|
16
|
-
exports.ConflictError = ConflictError_1.default;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UnauthorizedError = exports.NotFoundError = exports.BadRequestError = void 0;
|
|
7
|
+
var BadRequestError_1 = __importDefault(require("./BadRequestError"));
|
|
8
|
+
exports.BadRequestError = BadRequestError_1.default;
|
|
9
|
+
var NotFoundError_1 = __importDefault(require("./NotFoundError"));
|
|
10
|
+
exports.NotFoundError = NotFoundError_1.default;
|
|
11
|
+
var UnauthorizedError_1 = __importDefault(require("./UnauthorizedError"));
|
|
12
|
+
exports.UnauthorizedError = UnauthorizedError_1.default;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './wrappers';
|
|
2
|
-
export * from './errors';
|
|
3
|
-
export * from './validation';
|
|
4
|
-
export * from './types';
|
|
5
|
-
export * from './middleware';
|
|
6
|
-
export * from './logger
|
|
7
|
-
export * from './utils';
|
|
1
|
+
export * from './wrappers';
|
|
2
|
+
export * from './errors';
|
|
3
|
+
export * from './validation';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './middleware';
|
|
6
|
+
export * from './logger';
|
|
7
|
+
export * from './utils';
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./wrappers"), exports);
|
|
14
|
-
__exportStar(require("./errors"), exports);
|
|
15
|
-
__exportStar(require("./validation"), exports);
|
|
16
|
-
__exportStar(require("./types"), exports);
|
|
17
|
-
__exportStar(require("./middleware"), exports);
|
|
18
|
-
__exportStar(require("./logger/logger"), exports);
|
|
19
|
-
__exportStar(require("./utils"), exports);
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["lambda-utils"]=r():e["lambda-utils"]=r()}(global,(()=>(()=>{"use strict";var e={n:r=>{var t=r&&r.__esModule?()=>r.default:()=>r;return e.d(t,{a:t}),t},d:(r,t)=>{for(var a in t)e.o(t,a)&&!e.o(r,a)&&Object.defineProperty(r,a,{enumerable:!0,get:t[a]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{BadRequestError:()=>x,ConflictError:()=>N,ForbiddenError:()=>_,LambdaCache:()=>Q,NotFoundError:()=>T,SpytecJoi:()=>v,UnauthorizedError:()=>w,apiGatewayEventWrapper:()=>I,apiGatewayMiddlewares:()=>Z,apiGatewayMiddy:()=>K,buildProxyResult:()=>O,buildResponseBody:()=>S,defaultApiSchema:()=>A,getAuthorizerValidator:()=>f,getRequestContextValidator:()=>E,httpErrorHandler:()=>$(),httpResponseSerializer:()=>G(),iccidSchema:()=>b,imeiSchema:()=>g,json:()=>m,logger:()=>a,middy:()=>X,promiseWithCache:()=>Y,promiseWithTimeout:()=>ee,requestContextValidator:()=>C,resetLogger:()=>o,sqsEventWrapper:()=>R,urlEncoded:()=>y,validateEvent:()=>j,validatorMiddleware:()=>V,withRequest:()=>t.withRequest});const t=require("@spytecgps/sdk-logger");let a=(0,t.createLogger)();const o=e=>(a=(0,t.createLogger)({base:e}),a),s=require("dayjs");var n=e.n(s);const i=require("dayjs/plugin/timezone");var l=e.n(i);const c=require("dayjs/plugin/utc");var d=e.n(c);const u=require("joi"),p=require("qs");n().extend(d()),n().extend(l());const m=u.extend((e=>({type:"object",base:e.object(),messages:{"json.valid":"must be valid JSON"},coerce(e){try{return{value:JSON.parse(e)}}catch(e){return null}},validate:(e,r)=>e?{value:e}:{value:e,errors:r.error("json.valid")}}))),y=u.extend((e=>({type:"object",base:e.object(),coerce:e=>({value:p.parse(e)})}))),g=u.string().regex(/^\d{15,16}$/).message("Invalid IMEI"),b=u.string().regex(/^[0-9A-Za-z]{18,22}$/).message("Invalid ICCID"),v=u.extend((e=>({type:"imei",messages:"Invalid IMEI",base:e.string().regex(/^\d{15,16}$/)})),(e=>({type:"iccid",messages:"Invalid ICCID",base:e.string().regex(/^[0-9A-Za-z]{18,22}$/)})),(e=>({type:"urlEncodedObject",base:e.object(),coerce:e=>({value:p.parse(e)})})),(e=>({type:"jsonObject",base:e.object(),coerce(e){try{return{value:JSON.parse(e)}}catch(e){return null}},validate:(e,r)=>e?{value:e}:{value:e,errors:r.error("json.valid")}})),(e=>({type:"delimitedArray",base:e.array().default([]),coerce:e=>({value:e.split?e.split(","):e})})),(e=>({type:"queryStringParameters",messages:"Missing query parameters",base:e.object().required()})),(e=>({type:"date",base:e.date(),prepare(e,r){try{const r=n().tz(e,"UTC");if(r.isValid())return{value:r.toDate()}}catch(e){return r.error("any.invalid")}}})),(e=>({type:"jsonArray",base:e.array(),coerce(e){try{return{value:JSON.parse(e)}}catch(e){return{value:null}}},validate:(e,r)=>Array.isArray(e)?{value:e}:{value:e,errors:r.error("jsonArray.schema")}})),(e=>({type:"base64ThenUriEncodedObject",base:e.object(),coerce(e){try{const r=decodeURIComponent(Buffer.from(e,"base64").toString());return{value:JSON.parse(r)}}catch(e){return null}},validate:(e,r)=>e?{value:e}:{value:e,errors:r.error("json.valid")}})));class h extends Error{}class w extends h{code=401;statusCode=401;name="UnauthorizedError"}const f=({scope:e,type:r}={})=>u.object({clientId:u.number(),resources:m.object({}),scope:e?u.string().pattern(new RegExp(`${e}`)).error((()=>new w(`missing scope ${e}`))):u.optional(),type:r?u.any().valid(r).error((()=>new w(`missing user type ${r}`))):u.optional(),enterprise:u.boolean().default(!1),maintenanceModule:u.boolean().default(!1)}),C=u.object({authorizer:f()}),E=(e={})=>u.object({authorizer:f(e)});class x extends h{code=400;statusCode=400;name="BadRequestError"}const j=(e,r,t)=>{if(!r)return a.warn("skipping validation"),e;const{error:o,value:s}=r.validate(e,{allowUnknown:t?.allowUnknown||!0,errors:{label:"key",wrap:{label:!1}}});if(o)throw a.error({error:o},"Validation error"),o.isJoi?new x(o.message):o;return s},A=v.object({requestContext:E()}),q={"Content-Type":"application/json","Access-Control-Allow-Origin":"*","Access-Control-Allow-Credentials":!0},S=(e,r,t)=>({success:e<400,message:r,result:t||void 0}),O=({statusCode:e=200,message:r="ok",data:t,headers:a={},rawResult:o=!1,stringifyBody:s=!0})=>{const n=o?t:S(e,r,t),i=s?n&&JSON.stringify(n):t;return{headers:{...q,...a},statusCode:e,body:i}},I=async({event:e,context:r,schema:o,handler:s})=>{e&&r&&(0,t.withRequest)(e,r);try{const r=j(e,o),t=await s(r);return O(t)}catch(r){return a.error({err:r,event:(n=e,{resource:n.resource,httpMethod:n.httpMethod,queryStringParameters:n.queryStringParameters,pathParameters:n.pathParameters,body:n.body})},"apiGatewayWrapper - caught error"),O({statusCode:r.code||500,message:r.message||"Error"})}var n},R=async({event:e,context:r,schema:o,handler:s,singleHandler:n,mode:i="serial"})=>{e&&r&&(0,t.withRequest)(e,r);try{const r=j(e,o);await async function(e,r,t,a){if(!r&&!t)throw new Error("handler or singleHandler not defined");if(r)await r(e);else if(t){const r=e.Records;if("serial"===a)for(const e of r)await t(e);else"parallel"===a&&await Promise.all(r.map((e=>t(e))))}}(r,s,n,i)}catch(r){throw a.error({err:r,event:(l=e,(l.Records||[]).map((e=>({messageId:e.messageId,body:e.body,messageAttributes:e.messageAttributes}))))},"sqsEventWrapper - caught error"),r}var l};class N extends h{code=409;statusCode=409;name="ConflictError"}class _ extends h{code=403;statusCode=403;name="ForbiddenError"}class T extends h{code=404;statusCode=404;name="NotFoundError"}const z=require("@middy/core");var M=e.n(z);const P=require("@middy/http-error-handler");var $=e.n(P);const U=require("@middy/http-response-serializer");var G=e.n(U);const k="_X_AMZN_TRACE_ID",H="x-correlation-",J=`${H}id`,W=`${H}trace-id`,D=(()=>{const e={};return{before:async({event:r,context:t})=>{if(t&&(e.requestId=t?.awsRequestId,e.function=t.functionName),e.requestId||(e.requestId=r?.requestContext?.requestId),Object.prototype.hasOwnProperty.call(r,"headers")){const t=r;Object.keys(t).forEach((r=>{r.toLowerCase().startsWith(H)&&(e[r]=t[r])}))}process.env[k]&&(e[W]=process.env[k]),e[J]||(e[J]=t?.awsRequestId),e.contextUserId=r?.requestContext?.authorizer?.claims?.userId,e.contextUserEmail=r?.requestContext?.authorizer?.claims?.email,o(e)}}})(),B=require("@middy/input-output-logger"),L=e.n(B)()({logger:e=>{const r=e?.event?"event":"response";a.info(r,e)}}),V=({schema:e,allowUnknown:r=!0})=>({before:t=>{const{error:o,value:s}=e.validate(t.event,{allowUnknown:r,errors:{label:"key",wrap:{label:!1}}});if(o)throw a.error("Validation error",{error:o}),o.isJoi?new x(o.message):o;t.event=s}}),F=[D,L],Z=[G()({serializers:[{regex:/^application\/xml$/,serializer:({body:e})=>`<message>${e}</message>`},{regex:/^application\/json$/,serializer:({body:e})=>JSON.stringify(e)},{regex:/^text\/plain$/,serializer:({body:e})=>e}],default:"application/json"}),$()({logger:e=>a.error(e)}),{after:e=>{e.response=O(e.response)}}],X=e=>M()(e).use([...F]),K=e=>M()(e).use([...F,...Z]);class Q{collectionName;constructor(e){this.collectionName=e??`${process.env.AWS_LAMBDA_FUNCTION_NAME}-${process.env.AWS_LAMBDA_FUNCTION_VERSION}`,global.CACHE_STORAGE||(global.CACHE_STORAGE={}),global.CACHE_STORAGE[this.collectionName]||(global.CACHE_STORAGE[this.collectionName]=new Map)}set(e,r,t){const a=1e3*t+Date.now();global.CACHE_STORAGE[this.collectionName].set(e,{value:r,expire:a})}get(e){if(!e)throw new Error("key is required!");const r=global.CACHE_STORAGE[this.collectionName].get(e);return r?!r.expire||r.expire>Date.now()?r.value:this.remove(e):null}remove(e){global.CACHE_STORAGE[this.collectionName].get(e)&&global.CACHE_STORAGE[this.collectionName].delete(e)}}const Y=async(e,r,t,a)=>{let o=r.get(t);return o||(o=await e(),r.set(t,o,a)),o},ee=(e,r,t=new Error("Promise timed out"))=>{const a=new Promise(((e,a)=>{setTimeout((()=>{a(t)}),r)}));return Promise.race([e,a])};return r})()));
|
package/dist/logger/logger.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const isLocal: () => boolean;
|
|
2
|
-
export declare const isTest: () => boolean;
|
|
3
|
-
export declare const logger: import("winston").Logger;
|
|
1
|
+
export declare const isLocal: () => boolean;
|
|
2
|
+
export declare const isTest: () => boolean;
|
|
3
|
+
export declare const logger: import("winston").Logger;
|
package/dist/logger/logger.js
CHANGED
|
@@ -1,51 +1,57 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logger = exports.isTest = exports.isLocal = void 0;
|
|
4
|
-
var winston_1 = require("winston");
|
|
5
|
-
var winston_console_format_1 = require("winston-console-format");
|
|
6
|
-
var combine = winston_1.format.combine, errors = winston_1.format.errors, json = winston_1.format.json, timestamp = winston_1.format.timestamp, colorize = winston_1.format.colorize, padLevels = winston_1.format.padLevels;
|
|
7
|
-
exports.isLocal = function () { return !!process.env.IS_OFFLINE; };
|
|
8
|
-
exports.isTest = function () { return process.env.NODE_ENV == 'test'; };
|
|
9
|
-
var replaceError = function (
|
|
10
|
-
label
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
'
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = exports.isTest = exports.isLocal = void 0;
|
|
4
|
+
var winston_1 = require("winston");
|
|
5
|
+
var winston_console_format_1 = require("winston-console-format");
|
|
6
|
+
var combine = winston_1.format.combine, errors = winston_1.format.errors, json = winston_1.format.json, timestamp = winston_1.format.timestamp, colorize = winston_1.format.colorize, padLevels = winston_1.format.padLevels;
|
|
7
|
+
exports.isLocal = function () { return !!process.env.IS_OFFLINE; };
|
|
8
|
+
exports.isTest = function () { return process.env.NODE_ENV == 'test'; };
|
|
9
|
+
var replaceError = function (_a) {
|
|
10
|
+
var label = _a.label, level = _a.level, message = _a.message, stack = _a.stack;
|
|
11
|
+
return ({
|
|
12
|
+
label: label,
|
|
13
|
+
level: level,
|
|
14
|
+
message: message,
|
|
15
|
+
stack: stack,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
var replacer = function (_key, value) {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
return value instanceof Error ? replaceError(value) : value;
|
|
21
|
+
};
|
|
22
|
+
function getDevFormat() {
|
|
23
|
+
return combine(timestamp(), colorize({ all: true }), padLevels(), winston_console_format_1.consoleFormat({
|
|
24
|
+
showMeta: true,
|
|
25
|
+
metaStrip: [
|
|
26
|
+
'timestamp',
|
|
27
|
+
'service',
|
|
28
|
+
'requestId',
|
|
29
|
+
'x-correlation-id',
|
|
30
|
+
'function',
|
|
31
|
+
'contextUserId',
|
|
32
|
+
'contextUserEmail',
|
|
33
|
+
],
|
|
34
|
+
inspectOptions: {
|
|
35
|
+
depth: Infinity,
|
|
36
|
+
colors: true,
|
|
37
|
+
maxArrayLength: Infinity,
|
|
38
|
+
breakLength: 120,
|
|
39
|
+
compact: Infinity,
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
function getProductionFormat() {
|
|
44
|
+
return combine(errors({ stack: true }), timestamp(), json({ replacer: replacer }));
|
|
45
|
+
}
|
|
46
|
+
function getFormat() {
|
|
47
|
+
if (exports.isTest() || exports.isLocal()) {
|
|
48
|
+
return getDevFormat();
|
|
49
|
+
}
|
|
50
|
+
return getProductionFormat();
|
|
51
|
+
}
|
|
52
|
+
exports.logger = winston_1.createLogger({
|
|
53
|
+
level: exports.isTest() || exports.isLocal() ? 'info' : 'verbose',
|
|
54
|
+
defaultMeta: {},
|
|
55
|
+
format: getFormat(),
|
|
56
|
+
transports: [new winston_1.transports.Console()],
|
|
57
|
+
});
|