@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/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spytecgps/lambda-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2-rc1",
|
|
4
4
|
"description": "Lambda Utils",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
+
"lint": "eslint \"./src/**\"",
|
|
9
|
+
"lint-fix": "eslint \"./src/**\" --fix",
|
|
10
|
+
"test": "jest --ci --runInBand --reporters=default --reporters=jest-junit --collectCoverage=true",
|
|
8
11
|
"version": "npm run format && git add -A src",
|
|
9
|
-
"preversion": "npm test",
|
|
10
12
|
"postversion": "git push && git push --tags",
|
|
13
|
+
"prepublishOnly": "npm run lint",
|
|
11
14
|
"prepare": "npm run build",
|
|
12
|
-
"build": "
|
|
13
|
-
"
|
|
14
|
-
"format": "prettier --write \"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"version-publish": "npm version patch && npm publish",
|
|
18
|
-
"copydistfolder": "./scripts/copyDistFolder.sh"
|
|
15
|
+
"build-dev": "webpack --mode=development",
|
|
16
|
+
"build": "webpack --mode=production",
|
|
17
|
+
"format": "prettier --write \"**/*.ts\"",
|
|
18
|
+
"copydistfolder": "./scripts/copyDistFolder.sh",
|
|
19
|
+
"version-publish": "npm version patch && npm publish"
|
|
19
20
|
},
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
|
@@ -28,41 +29,40 @@
|
|
|
28
29
|
},
|
|
29
30
|
"homepage": "https://github.com/spytecgps/lambda-utils#readme",
|
|
30
31
|
"dependencies": {
|
|
32
|
+
"@spytecgps/sdk-logger": "^2.0.0-rc8",
|
|
31
33
|
"@middy/core": "^2.5.7",
|
|
32
34
|
"@middy/http-error-handler": "^2.5.7",
|
|
33
35
|
"@middy/http-response-serializer": "^2.5.7",
|
|
34
36
|
"@middy/input-output-logger": "^2.5.7",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"logform": "^2.4.0",
|
|
39
|
-
"qs": "^6.10.1",
|
|
40
|
-
"winston": "^3.7.2",
|
|
41
|
-
"winston-console-format": "^1.0.8"
|
|
37
|
+
"dayjs": "^1.11.11",
|
|
38
|
+
"joi": "^17.13.0",
|
|
39
|
+
"qs": "^6.10.1"
|
|
42
40
|
},
|
|
43
41
|
"devDependencies": {
|
|
44
42
|
"@types/aws-lambda": "^8.10.76",
|
|
45
|
-
"@types/jest": "^
|
|
43
|
+
"@types/jest": "^29.5.12",
|
|
46
44
|
"@types/joi": "^17.2.3",
|
|
47
|
-
"@
|
|
48
|
-
"@typescript-eslint/
|
|
45
|
+
"@types/node": "^16",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
47
|
+
"@typescript-eslint/parser": "^5.42.1",
|
|
49
48
|
"aws-sdk": "^2.919.0",
|
|
50
|
-
"eslint": "^
|
|
51
|
-
"eslint-config-
|
|
52
|
-
"eslint-
|
|
53
|
-
"eslint-plugin-
|
|
54
|
-
"eslint-plugin-
|
|
55
|
-
"
|
|
56
|
-
"jest": "^
|
|
57
|
-
"
|
|
58
|
-
"prettier": "^
|
|
59
|
-
"ts-jest": "^
|
|
60
|
-
"ts-loader": "^
|
|
61
|
-
"typescript": "^
|
|
62
|
-
"webpack": "^
|
|
63
|
-
"webpack-cli": "^
|
|
49
|
+
"eslint": "^8.27.0",
|
|
50
|
+
"eslint-config-prettier": "^8.5.0",
|
|
51
|
+
"eslint-plugin-import": "^2.26.0",
|
|
52
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
53
|
+
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
54
|
+
"jest": "^29.7.0",
|
|
55
|
+
"jest-junit": "^16",
|
|
56
|
+
"prettier": "^2.8.8",
|
|
57
|
+
"prettier-eslint": "^16.3.0",
|
|
58
|
+
"ts-jest": "^29.0.3",
|
|
59
|
+
"ts-loader": "^9.5.1",
|
|
60
|
+
"typescript": "^4.9.5",
|
|
61
|
+
"webpack": "^5.72.0",
|
|
62
|
+
"webpack-cli": "^4.9.2",
|
|
63
|
+
"webpack-node-externals": "^3.0.0"
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
66
66
|
"dist/**/*"
|
|
67
67
|
]
|
|
68
|
-
}
|
|
68
|
+
}
|
|
@@ -1,28 +0,0 @@
|
|
|
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 ForbiddenError = /** @class */ (function (_super) {
|
|
18
|
-
__extends(ForbiddenError, _super);
|
|
19
|
-
function ForbiddenError() {
|
|
20
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
_this.code = 403;
|
|
22
|
-
_this.statusCode = 403;
|
|
23
|
-
_this.name = 'ForbiddenError';
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
return ForbiddenError;
|
|
27
|
-
}(HttpError_1.HttpError));
|
|
28
|
-
exports.default = ForbiddenError;
|
package/dist/utils/cache.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LambdaCache = void 0;
|
|
4
|
-
var LambdaCache = /** @class */ (function () {
|
|
5
|
-
/**
|
|
6
|
-
* @param {String} collectionName (not required) - The collection key used to store the cache values.
|
|
7
|
-
* If not provide default collection name uses :
|
|
8
|
-
* ${process.env.AWS_LAMBDA_FUNCTION_NAME}-${process.env.AWS_LAMBDA_FUNCTION_VERSION}
|
|
9
|
-
* */
|
|
10
|
-
function LambdaCache(collectionName) {
|
|
11
|
-
this.collectionName = collectionName !== null && collectionName !== void 0 ? collectionName : process.env.AWS_LAMBDA_FUNCTION_NAME + "-" + process.env.AWS_LAMBDA_FUNCTION_VERSION;
|
|
12
|
-
if (!global['CACHE_STORAGE']) {
|
|
13
|
-
global['CACHE_STORAGE'] = {};
|
|
14
|
-
}
|
|
15
|
-
if (!global['CACHE_STORAGE'][this.collectionName]) {
|
|
16
|
-
global['CACHE_STORAGE'][this.collectionName] = new Map();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* @param {String} key (required) - cache key
|
|
21
|
-
* @param {Object} value (required) - cache value
|
|
22
|
-
* @param {Number} expire (required) - cache expiration time (seconds)
|
|
23
|
-
* */
|
|
24
|
-
LambdaCache.prototype.set = function (key, value, ttl) {
|
|
25
|
-
var expire = 1000 * ttl + Date.now();
|
|
26
|
-
global['CACHE_STORAGE'][this.collectionName].set(key, { value: value, expire: expire });
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* @param {String} key (required) - cache key to get
|
|
30
|
-
* */
|
|
31
|
-
LambdaCache.prototype.get = function (key) {
|
|
32
|
-
if (!key) {
|
|
33
|
-
throw new Error('key is required!');
|
|
34
|
-
}
|
|
35
|
-
var record = global['CACHE_STORAGE'][this.collectionName].get(key);
|
|
36
|
-
if (!record) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
if (!record.expire || record.expire > Date.now()) {
|
|
40
|
-
return record.value;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
return this.remove(key);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* @param {String} key (required) - cache key to remove
|
|
48
|
-
* */
|
|
49
|
-
LambdaCache.prototype.remove = function (key) {
|
|
50
|
-
var record = global['CACHE_STORAGE'][this.collectionName].get(key);
|
|
51
|
-
if (!record) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
global['CACHE_STORAGE'][this.collectionName].delete(key);
|
|
55
|
-
};
|
|
56
|
-
return LambdaCache;
|
|
57
|
-
}());
|
|
58
|
-
exports.LambdaCache = LambdaCache;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.promiseWithCache = void 0;
|
|
40
|
-
exports.promiseWithCache = function (promise, cacheInstance, cacheKey, ttl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
-
var instance;
|
|
42
|
-
return __generator(this, function (_a) {
|
|
43
|
-
switch (_a.label) {
|
|
44
|
-
case 0:
|
|
45
|
-
instance = cacheInstance.get(cacheKey);
|
|
46
|
-
if (!!instance) return [3 /*break*/, 2];
|
|
47
|
-
return [4 /*yield*/, promise()];
|
|
48
|
-
case 1:
|
|
49
|
-
instance = _a.sent();
|
|
50
|
-
cacheInstance.set(cacheKey, instance, ttl);
|
|
51
|
-
_a.label = 2;
|
|
52
|
-
case 2: return [2 /*return*/, instance];
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}); };
|
package/dist/utils/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
exports.LambdaCache = void 0;
|
|
14
|
-
var cache_1 = require("./cache");
|
|
15
|
-
Object.defineProperty(exports, "LambdaCache", { enumerable: true, get: function () { return cache_1.LambdaCache; } });
|
|
16
|
-
__exportStar(require("./cacheWrapper"), exports);
|
|
17
|
-
__exportStar(require("./timeOut"), exports);
|
package/dist/utils/timeOut.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.promiseWithTimeout = void 0;
|
|
4
|
-
exports.promiseWithTimeout = function (promise, ms, timeoutError) {
|
|
5
|
-
if (timeoutError === void 0) { timeoutError = new Error('Promise timed out'); }
|
|
6
|
-
// create a promise that rejects in milliseconds
|
|
7
|
-
var timeout = new Promise(function (_, reject) {
|
|
8
|
-
setTimeout(function () {
|
|
9
|
-
reject(timeoutError);
|
|
10
|
-
}, ms);
|
|
11
|
-
});
|
|
12
|
-
// returns a race between timeout and the passed promise
|
|
13
|
-
return Promise.race([promise, timeout]);
|
|
14
|
-
//Adding comment to test
|
|
15
|
-
};
|