🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@fluyappgo/commons-backend

Package Overview
Dependencies
Maintainers
3
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluyappgo/commons-backend - npm Package Compare versions

Comparing version

to
1.0.151

7

build/classes/HttpResponse.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpResponse = void 0;
class HttpResponse {
constructor(code, data, metadata, message) {
var HttpResponse = /** @class */ (function () {
function HttpResponse(code, data, metadata, message) {
this.code = code;

@@ -11,3 +11,4 @@ this.data = data;

}
}
return HttpResponse;
}());
exports.HttpResponse = HttpResponse;

@@ -10,14 +10,17 @@ "use strict";

exports.FileDTO = void 0;
const class_validator_1 = require("class-validator");
class FileDTO {
}
__decorate([
class_validator_1.IsString()
], FileDTO.prototype, "Key", void 0);
__decorate([
class_validator_1.IsString()
], FileDTO.prototype, "ContentType", void 0);
__decorate([
class_validator_1.IsString()
], FileDTO.prototype, "folder", void 0);
var class_validator_1 = require("class-validator");
var FileDTO = /** @class */ (function () {
function FileDTO() {
}
__decorate([
class_validator_1.IsString()
], FileDTO.prototype, "Key", void 0);
__decorate([
class_validator_1.IsString()
], FileDTO.prototype, "ContentType", void 0);
__decorate([
class_validator_1.IsString()
], FileDTO.prototype, "folder", void 0);
return FileDTO;
}());
exports.FileDTO = FileDTO;

@@ -11,39 +11,80 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Listener = exports.shouldRestart = void 0;
const kafkajs_1 = require("kafkajs");
var kafkajs_1 = require("kafkajs");
function shouldRestart(error) {
const isNonRetriableError = error instanceof kafkajs_1.KafkaJSNonRetriableError;
const isNumberOfRetriesExceeded = error instanceof kafkajs_1.KafkaJSNumberOfRetriesExceeded;
var isNonRetriableError = error instanceof kafkajs_1.KafkaJSNonRetriableError;
var isNumberOfRetriesExceeded = error instanceof kafkajs_1.KafkaJSNumberOfRetriesExceeded;
return isNonRetriableError && !isNumberOfRetriesExceeded;
}
exports.shouldRestart = shouldRestart;
class Listener {
constructor(client) {
var Listener = /** @class */ (function () {
function Listener(client) {
this.client = client;
}
listen(fromBeginning) {
const topic = this.topic;
const consumer = this.client.consumer({ groupId: this.groupName });
consumer.connect().then(() => __awaiter(this, void 0, void 0, function* () {
yield consumer.connect();
yield consumer.subscribe({ topic, fromBeginning: fromBeginning });
yield consumer.run({
eachMessage: (payload) => {
const message = payload.message;
const parsedData = this.parseMessage(message);
this.onMessage(parsedData, message);
},
Listener.prototype.listen = function (fromBeginning) {
var _this = this;
var topic = this.topic;
var consumer = this.client.consumer({ groupId: this.groupName });
consumer.connect().then(function () { return __awaiter(_this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, consumer.connect()];
case 1:
_a.sent();
return [4 /*yield*/, consumer.subscribe({ topic: topic, fromBeginning: fromBeginning })];
case 2:
_a.sent();
return [4 /*yield*/, consumer.run({
eachMessage: function (payload) {
var message = payload.message;
var parsedData = _this.parseMessage(message);
_this.onMessage(parsedData, message);
},
})];
case 3:
_a.sent();
return [2 /*return*/];
}
});
})).catch((error) => {
}); }).catch(function (error) {
console.log('ERROORRR KAFKA: ', error);
});
}
parseMessage(msg) {
const data = msg.value || '{}';
};
Listener.prototype.parseMessage = function (msg) {
var data = msg.value || '{}';
return typeof data === 'string'
? JSON.parse(data)
: JSON.parse(data.toString('utf8'));
}
}
};
return Listener;
}());
exports.Listener = Listener;

@@ -11,35 +11,75 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Publisher = void 0;
class Publisher {
constructor(client) {
var Publisher = /** @class */ (function () {
function Publisher(client) {
this.client = client;
}
publish(data, keyKafka) {
const topic = this.topic;
return new Promise((resolve, reject) => {
const producer = this.client.producer();
Publisher.prototype.publish = function (data, keyKafka) {
var _this = this;
var topic = this.topic;
return new Promise(function (resolve, reject) {
var producer = _this.client.producer();
try {
(() => __awaiter(this, void 0, void 0, function* () {
yield producer.connect();
yield producer.send({
topic,
messages: [
{
key: String(keyKafka),
value: JSON.stringify(data)
},
],
(function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, producer.connect()];
case 1:
_a.sent();
return [4 /*yield*/, producer.send({
topic: topic,
messages: [
{
key: String(keyKafka),
value: JSON.stringify(data)
},
],
})];
case 2:
_a.sent();
resolve(topic + " done");
return [4 /*yield*/, producer.disconnect()];
case 3:
_a.sent();
return [2 /*return*/];
}
});
resolve(`${topic} done`);
yield producer.disconnect();
}))();
}); })();
}
catch (e) {
console.log(e);
reject(`${topic} ${e.message}`);
reject(topic + " " + e.message);
}
});
}
}
};
return Publisher;
}());
exports.Publisher = Publisher;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KafkaConnection = void 0;
const kafkajs_1 = require("kafkajs");
const KafkaConnection = (brokers, clientId) => {
const kafka = new kafkajs_1.Kafka({ clientId, brokers });
var kafkajs_1 = require("kafkajs");
var KafkaConnection = function (brokers, clientId) {
var kafka = new kafkajs_1.Kafka({ clientId: clientId, brokers: brokers });
return kafka;
};
exports.KafkaConnection = KafkaConnection;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationTokenMissingException = void 0;
class AuthenticationTokenMissingException extends Error {
constructor() {
super();
this.status = 500;
this.message = "Token is missing.";
var AuthenticationTokenMissingException = /** @class */ (function (_super) {
__extends(AuthenticationTokenMissingException, _super);
function AuthenticationTokenMissingException() {
var _this = _super.call(this) || this;
_this.status = 500;
_this.message = "Token is missing.";
return _this;
}
}
return AuthenticationTokenMissingException;
}(Error));
exports.AuthenticationTokenMissingException = AuthenticationTokenMissingException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpException = void 0;
class HttpException extends Error {
constructor(status, message) {
super(message);
this.status = status;
this.message = message;
var HttpException = /** @class */ (function (_super) {
__extends(HttpException, _super);
function HttpException(status, message) {
var _this = _super.call(this, message) || this;
_this.status = status;
_this.message = message;
return _this;
}
}
return HttpException;
}(Error));
exports.HttpException = HttpException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.MissingTokenException = void 0;
const HttpException_1 = require("./HttpException");
class MissingTokenException extends HttpException_1.HttpException {
constructor(message) {
super(401, message);
this.message = `code-mdb-500: ${message}`;
var HttpException_1 = require("./HttpException");
var MissingTokenException = /** @class */ (function (_super) {
__extends(MissingTokenException, _super);
function MissingTokenException(message) {
var _this = _super.call(this, 401, message) || this;
_this.message = "code-mdb-500: " + message;
return _this;
}
}
return MissingTokenException;
}(HttpException_1.HttpException));
exports.MissingTokenException = MissingTokenException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.MongoErrorException = void 0;
const HttpException_1 = require("./HttpException");
class MongoErrorException extends HttpException_1.HttpException {
constructor(message) {
super(500, message);
this.message = `code-mdb-500: ${message}`;
var HttpException_1 = require("./HttpException");
var MongoErrorException = /** @class */ (function (_super) {
__extends(MongoErrorException, _super);
function MongoErrorException(message) {
var _this = _super.call(this, 500, message) || this;
_this.message = "code-mdb-500: " + message;
return _this;
}
}
return MongoErrorException;
}(HttpException_1.HttpException));
exports.MongoErrorException = MongoErrorException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.MulterException = void 0;
const HttpException_1 = require("./HttpException");
class MulterException extends HttpException_1.HttpException {
constructor(message) {
super(500, message);
this.message = `code-vflu-500: Multer -> ${message}`;
var HttpException_1 = require("./HttpException");
var MulterException = /** @class */ (function (_super) {
__extends(MulterException, _super);
function MulterException(message) {
var _this = _super.call(this, 500, message) || this;
_this.message = "code-vflu-500: Multer -> " + message;
return _this;
}
}
return MulterException;
}(HttpException_1.HttpException));
exports.MulterException = MulterException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.QwizardException = void 0;
class QwizardException extends Error {
constructor(msg) {
super();
this.status = 500;
this.message = `code-qwzd-500: ${msg}`;
var QwizardException = /** @class */ (function (_super) {
__extends(QwizardException, _super);
function QwizardException(msg) {
var _this = _super.call(this) || this;
_this.status = 500;
_this.message = "code-qwzd-500: " + msg;
return _this;
}
}
return QwizardException;
}(Error));
exports.QwizardException = QwizardException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecordingServerException = void 0;
class RecordingServerException extends Error {
constructor(msg) {
super();
this.status = 500;
this.message = `Recording server error: ${msg}`;
var RecordingServerException = /** @class */ (function (_super) {
__extends(RecordingServerException, _super);
function RecordingServerException(msg) {
var _this = _super.call(this) || this;
_this.status = 500;
_this.message = "Recording server error: " + msg;
return _this;
}
}
return RecordingServerException;
}(Error));
exports.RecordingServerException = RecordingServerException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserNotFoundException = void 0;
const HttpException_1 = require("./HttpException");
class UserNotFoundException extends HttpException_1.HttpException {
constructor(message) {
super(404, message);
this.message = "code-mdb-404: user not found, " + message;
var HttpException_1 = require("./HttpException");
var UserNotFoundException = /** @class */ (function (_super) {
__extends(UserNotFoundException, _super);
function UserNotFoundException(message) {
var _this = _super.call(this, 404, message) || this;
_this.message = "code-mdb-404: user not found, " + message;
return _this;
}
}
return UserNotFoundException;
}(HttpException_1.HttpException));
exports.UserNotFoundException = UserNotFoundException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserWithThatEmailAlreadyExistsException = void 0;
const HttpException_1 = require("./HttpException");
class UserWithThatEmailAlreadyExistsException extends HttpException_1.HttpException {
constructor(message) {
super(500, message);
this.message = "code-vflu-500: This email already exist, " + message;
var HttpException_1 = require("./HttpException");
var UserWithThatEmailAlreadyExistsException = /** @class */ (function (_super) {
__extends(UserWithThatEmailAlreadyExistsException, _super);
function UserWithThatEmailAlreadyExistsException(message) {
var _this = _super.call(this, 500, message) || this;
_this.message = "code-vflu-500: This email already exist, " + message;
return _this;
}
}
return UserWithThatEmailAlreadyExistsException;
}(HttpException_1.HttpException));
exports.UserWithThatEmailAlreadyExistsException = UserWithThatEmailAlreadyExistsException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.WrongAnonymousAuthException = void 0;
class WrongAnonymousAuthException extends Error {
constructor() {
super();
this.status = 401;
this.message = "code-vflu-401: Anonymous token wrong, did not pass verification.";
var WrongAnonymousAuthException = /** @class */ (function (_super) {
__extends(WrongAnonymousAuthException, _super);
function WrongAnonymousAuthException() {
var _this = _super.call(this) || this;
_this.status = 401;
_this.message = "code-vflu-401: Anonymous token wrong, did not pass verification.";
return _this;
}
}
return WrongAnonymousAuthException;
}(Error));
exports.WrongAnonymousAuthException = WrongAnonymousAuthException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.WrongAuthException = void 0;
class WrongAuthException extends Error {
constructor() {
super();
this.status = 401;
this.message = "code-vflu-401: Anonymous token wrong, did not pass verification.";
var WrongAuthException = /** @class */ (function (_super) {
__extends(WrongAuthException, _super);
function WrongAuthException() {
var _this = _super.call(this) || this;
_this.status = 401;
_this.message = "code-vflu-401: Anonymous token wrong, did not pass verification.";
return _this;
}
}
return WrongAuthException;
}(Error));
exports.WrongAuthException = WrongAuthException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.WrongAuthenticationTokenException = void 0;
class WrongAuthenticationTokenException extends Error {
constructor() {
super();
this.status = 401;
this.message = "code-vflu-401: Token wrong, did not pass verification.";
var WrongAuthenticationTokenException = /** @class */ (function (_super) {
__extends(WrongAuthenticationTokenException, _super);
function WrongAuthenticationTokenException() {
var _this = _super.call(this) || this;
_this.status = 401;
_this.message = "code-vflu-401: Token wrong, did not pass verification.";
return _this;
}
}
return WrongAuthenticationTokenException;
}(Error));
exports.WrongAuthenticationTokenException = WrongAuthenticationTokenException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.WrongBusinessAuthException = void 0;
class WrongBusinessAuthException extends Error {
constructor(msg) {
super();
this.status = 401;
this.message = `code-vflu-401: Business token wrong, did not pass verification. ${msg}`;
var WrongBusinessAuthException = /** @class */ (function (_super) {
__extends(WrongBusinessAuthException, _super);
function WrongBusinessAuthException(msg) {
var _this = _super.call(this) || this;
_this.status = 401;
_this.message = "code-vflu-401: Business token wrong, did not pass verification. " + msg;
return _this;
}
}
return WrongBusinessAuthException;
}(Error));
exports.WrongBusinessAuthException = WrongBusinessAuthException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.WrongCredentialsException = void 0;
const HttpException_1 = require("./HttpException");
class WrongCredentialsException extends HttpException_1.HttpException {
constructor(message) {
super(401, message);
this.message = `code-vflu-401: ${message}`;
var HttpException_1 = require("./HttpException");
var WrongCredentialsException = /** @class */ (function (_super) {
__extends(WrongCredentialsException, _super);
function WrongCredentialsException(message) {
var _this = _super.call(this, 401, message) || this;
_this.message = "code-vflu-401: " + message;
return _this;
}
}
return WrongCredentialsException;
}(HttpException_1.HttpException));
exports.WrongCredentialsException = WrongCredentialsException;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.WrongRoomException = void 0;
const HttpException_1 = require("./HttpException");
class WrongRoomException extends HttpException_1.HttpException {
constructor(message) {
super(404, message);
this.message = "code-mdb-404: " + message;
var HttpException_1 = require("./HttpException");
var WrongRoomException = /** @class */ (function (_super) {
__extends(WrongRoomException, _super);
function WrongRoomException(message) {
var _this = _super.call(this, 404, message) || this;
_this.message = "code-mdb-404: " + message;
return _this;
}
}
return WrongRoomException;
}(HttpException_1.HttpException));
exports.WrongRoomException = WrongRoomException;

@@ -11,2 +11,29 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -17,14 +44,18 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.getChangedFields = exports.sanitizeField = exports.formatDateEs = exports.tenMinuteLimiter = exports.oneMinuteLimiter = exports.createTenMinuteLimiter = exports.createOneMinuteLimiter = exports.getClientIP = exports.getRateLimitMetadata = exports.getMailSubjectFromHTML = void 0;
const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
const getMailSubjectFromHTML = (html, defaultSubject) => __awaiter(void 0, void 0, void 0, function* () {
const titleRegex = /<title>(.*?)<\/title>/;
const match = html.match(titleRegex);
if (match && match[1]) {
const pageTitle = match[1];
return pageTitle;
}
else {
return defaultSubject;
}
});
var express_rate_limit_1 = __importDefault(require("express-rate-limit"));
var getMailSubjectFromHTML = function (html, defaultSubject) { return __awaiter(void 0, void 0, void 0, function () {
var titleRegex, match, pageTitle;
return __generator(this, function (_a) {
titleRegex = /<title>(.*?)<\/title>/;
match = html.match(titleRegex);
if (match && match[1]) {
pageTitle = match[1];
return [2 /*return*/, pageTitle];
}
else {
return [2 /*return*/, defaultSubject];
}
return [2 /*return*/];
});
}); };
exports.getMailSubjectFromHTML = getMailSubjectFromHTML;

@@ -40,3 +71,3 @@ /**

*/
const getRateLimitMetadata = (res) => {
var getRateLimitMetadata = function (res) {
var _a, _b, _c;

@@ -50,3 +81,3 @@ return {

exports.getRateLimitMetadata = getRateLimitMetadata;
const getClientIP = (req) => req.ip || req.headers["x-forwarded-for"] || req.connection.remoteAddress;
var getClientIP = function (req) { return req.ip || req.headers["x-forwarded-for"] || req.connection.remoteAddress; };
exports.getClientIP = getClientIP;

@@ -61,9 +92,12 @@ /**

*/
const createOneMinuteLimiter = (maxRequests = 10) => express_rate_limit_1.default({
windowMs: 1 * 60 * 1000,
max: maxRequests,
message: `Too many requests in 1 minute (max ${maxRequests}), please slow down.`,
headers: true,
keyGenerator: exports.getClientIP,
});
var createOneMinuteLimiter = function (maxRequests) {
if (maxRequests === void 0) { maxRequests = 10; }
return express_rate_limit_1.default({
windowMs: 1 * 60 * 1000,
max: maxRequests,
message: "Too many requests in 1 minute (max " + maxRequests + "), please slow down.",
headers: true,
keyGenerator: exports.getClientIP,
});
};
exports.createOneMinuteLimiter = createOneMinuteLimiter;

@@ -78,9 +112,12 @@ /**

*/
const createTenMinuteLimiter = (maxRequests = 50) => express_rate_limit_1.default({
windowMs: 10 * 60 * 1000,
max: maxRequests,
message: `Too many requests in 10 minutes (max ${maxRequests}), please slow down.`,
headers: true,
keyGenerator: exports.getClientIP,
});
var createTenMinuteLimiter = function (maxRequests) {
if (maxRequests === void 0) { maxRequests = 50; }
return express_rate_limit_1.default({
windowMs: 10 * 60 * 1000,
max: maxRequests,
message: "Too many requests in 10 minutes (max " + maxRequests + "), please slow down.",
headers: true,
keyGenerator: exports.getClientIP,
});
};
exports.createTenMinuteLimiter = createTenMinuteLimiter;

@@ -98,3 +135,3 @@ // For backward compatibility

*/
const formatDateEs = (date) => {
var formatDateEs = function (date) {
return date

@@ -120,3 +157,3 @@ .toLocaleString("es-ES", {

*/
const sanitizeField = (field) => (field ? field.replace(/\r?\n|\r/g, " ").trim() : "");
var sanitizeField = function (field) { return (field ? field.replace(/\r?\n|\r/g, " ").trim() : ""); };
exports.sanitizeField = sanitizeField;

@@ -141,7 +178,7 @@ /**

*/
const getChangedFields = (oldObj, newObj) => {
const changes = {};
Object.keys(newObj).forEach(key => {
const oldValue = oldObj[key];
const newValue = newObj[key];
var getChangedFields = function (oldObj, newObj) {
var changes = {};
Object.keys(newObj).forEach(function (key) {
var oldValue = oldObj[key];
var newValue = newObj[key];
// Skip if values are the same

@@ -151,6 +188,6 @@ if (oldValue === newValue)

// Convert values to strings for comparison and storage
const oldStringified = typeof oldValue === 'object' && oldValue !== null
var oldStringified = typeof oldValue === 'object' && oldValue !== null
? JSON.stringify(oldValue)
: String(oldValue !== null && oldValue !== void 0 ? oldValue : '');
const newStringified = typeof newValue === 'object' && newValue !== null
var newStringified = typeof newValue === 'object' && newValue !== null
? JSON.stringify(newValue)

@@ -157,0 +194,0 @@ : String(newValue);

@@ -7,3 +7,3 @@ "use strict";

exports.logger = void 0;
const pino_1 = __importDefault(require("pino"));
var pino_1 = __importDefault(require("pino"));
exports.logger = pino_1.default({

@@ -32,5 +32,5 @@ level: process.env.LOG_LEVEL || 'info',

},
timestamp: () => `,"time":"${new Date(Date.now()).toISOString()}"`,
timestamp: function () { return ",\"time\":\"" + new Date(Date.now()).toISOString() + "\""; },
formatters: {
level: (label) => {
level: function (label) {
return { level: label.toUpperCase() };

@@ -37,0 +37,0 @@ },

import { NextFunction, Response } from 'express';
export declare function authFBMiddleware(request: any, response: Response, next: NextFunction): Promise<void>;
export declare function authMiddleware(request: any, response: Response, next: NextFunction): Promise<void>;
export declare function midAuthMiddleware(request: any, response: Response, next: NextFunction): Promise<void>;
import { RequestWithUser, RequestWithUserFB } from '../interfaces';
export declare function authFBMiddleware(request: RequestWithUserFB, response: Response, next: NextFunction): Promise<void>;
export declare function authMiddleware(request: RequestWithUser, response: Response, next: NextFunction): Promise<void>;
export declare function midAuthMiddleware(request: RequestWithUser, response: Response, next: NextFunction): Promise<void>;

@@ -30,48 +30,78 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.midAuthMiddleware = exports.authMiddleware = exports.authFBMiddleware = void 0;
const jwt = __importStar(require("jsonwebtoken"));
const missingToken_exception_1 = require("../exceptions/missingToken.exception");
const wrongAuth_exception_1 = require("../exceptions/wrongAuth.exception");
const redis_1 = require("redis");
const RedisClient = redis_1.createClient({ url: `redis://${process.env.REDIS_HOST}:6379` });
var jwt = __importStar(require("jsonwebtoken"));
var missingToken_exception_1 = require("../exceptions/missingToken.exception");
var wrongAuth_exception_1 = require("../exceptions/wrongAuth.exception");
var redis = __importStar(require("redis"));
var promisify = require("util").promisify;
var RedisClient = redis.createClient({ host: process.env.REDIS_HOST, port: 6379 });
var hGetAsync = promisify(RedisClient.hget).bind(RedisClient);
var hGetAllAsync = promisify(RedisClient.hgetall).bind(RedisClient);
var hDelAsync = promisify(RedisClient.hdel).bind(RedisClient);
function authFBMiddleware(request, response, next) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
console.log("redis", RedisClient);
console.log("authorization", authorization);
if (authorization) {
const secret = process.env.JWT_KEY || ' ';
console.log("secret", secret);
try {
const verificationResponse = jwt.verify(authorization, secret);
const userJwt = verificationResponse;
console.log("auth 0", userJwt);
if (userJwt === null || userJwt === void 0 ? void 0 : userJwt.uuid) {
let userRaw = (yield RedisClient.hGet("user", userJwt === null || userJwt === void 0 ? void 0 : userJwt.uuid)) || "{ }";
let user = JSON.parse(userRaw);
console.log("auth 1");
if (user === null || user === void 0 ? void 0 : user.uuid) {
return __awaiter(this, void 0, void 0, function () {
var authorization, secret, verificationResponse, userJwt, userRaw, user, error_1;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
if (!authorization) return [3 /*break*/, 5];
secret = process.env.JWT_KEY || ' ';
_c.label = 1;
case 1:
_c.trys.push([1, 3, , 4]);
verificationResponse = jwt.verify(authorization, secret);
userJwt = verificationResponse;
return [4 /*yield*/, hGetAsync("user", userJwt.uuid)];
case 2:
userRaw = _c.sent();
user = JSON.parse(userRaw);
if (user) {
request.user = user;
next();
console.log("auth 2");
}
else {
console.log("auth 3");
next(new wrongAuth_exception_1.WrongAuthException());
}
}
else {
}
return [3 /*break*/, 4];
case 3:
error_1 = _c.sent();
next(new missingToken_exception_1.MissingTokenException("Error: " + error_1));
return [3 /*break*/, 4];
case 4: return [3 /*break*/, 6];
case 5:
next(new missingToken_exception_1.MissingTokenException('Error: no auth'));
_c.label = 6;
case 6: return [2 /*return*/];
}
catch (error) {
console.log("auth 4");
next(new missingToken_exception_1.MissingTokenException(`Error: ${error}`));
}
}
else {
console.log("auth 5");
next(new missingToken_exception_1.MissingTokenException('Error: no auth'));
}
});
});

@@ -82,24 +112,28 @@ }

var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
if (authorization) {
const secret = process.env.JWT_KEY || '';
try {
const verificationResponse = jwt.verify(authorization, secret);
const user = verificationResponse;
if (user) {
request.user = user;
next();
return __awaiter(this, void 0, void 0, function () {
var authorization, secret, verificationResponse, user;
return __generator(this, function (_c) {
authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
if (authorization) {
secret = process.env.JWT_KEY || '';
try {
verificationResponse = jwt.verify(authorization, secret);
user = verificationResponse;
if (user) {
request.user = user;
next();
}
else {
next(new wrongAuth_exception_1.WrongAuthException());
}
}
else {
next(new wrongAuth_exception_1.WrongAuthException());
catch (error) {
next(new missingToken_exception_1.MissingTokenException('2'));
}
}
catch (error) {
next(new missingToken_exception_1.MissingTokenException('2'));
else {
next(new missingToken_exception_1.MissingTokenException('3'));
}
}
else {
next(new missingToken_exception_1.MissingTokenException('3'));
}
return [2 /*return*/];
});
});

@@ -110,14 +144,26 @@ }

var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
if (authorization) {
const secret = process.env.JWT_KEY || '';
try {
const verificationResponse = jwt.verify(authorization, secret);
const user = verificationResponse;
if (user) {
request.user = user;
next();
return __awaiter(this, void 0, void 0, function () {
var authorization, secret, verificationResponse, user;
return __generator(this, function (_c) {
authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
if (authorization) {
secret = process.env.JWT_KEY || '';
try {
verificationResponse = jwt.verify(authorization, secret);
user = verificationResponse;
if (user) {
request.user = user;
next();
}
else {
request.user = {
_id: "",
email: "",
password: "",
lastName: ""
};
next();
}
}
else {
catch (error) {
request.user = {

@@ -132,3 +178,3 @@ _id: "",

}
catch (error) {
else {
request.user = {

@@ -142,14 +188,6 @@ _id: "",

}
}
else {
request.user = {
_id: "",
email: "",
password: "",
lastName: ""
};
next();
}
return [2 /*return*/];
});
});
}
exports.midAuthMiddleware = midAuthMiddleware;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorMiddleware = void 0;
const errorMiddleware = (error, request, response, next) => {
const status = error.status || 500;
const message = error.message || 'Something went wrong';
var errorMiddleware = function (error, request, response, next) {
var status = error.status || 500;
var message = error.message || 'Something went wrong';
response
.status(status)
.send({
status,
message,
status: status,
message: message,
});
};
exports.errorMiddleware = errorMiddleware;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validationMiddleware = void 0;
const class_transformer_1 = require("class-transformer");
const class_validator_1 = require("class-validator");
const exceptions_1 = require("../exceptions");
const validationMiddleware = (type, skipMissingProperties = false) => {
return (req, res, next) => {
class_validator_1.validate(class_transformer_1.plainToClass(type, req.body), { skipMissingProperties })
.then((errors) => {
var class_transformer_1 = require("class-transformer");
var class_validator_1 = require("class-validator");
var exceptions_1 = require("../exceptions");
var validationMiddleware = function (type, skipMissingProperties) {
if (skipMissingProperties === void 0) { skipMissingProperties = false; }
return function (req, res, next) {
class_validator_1.validate(class_transformer_1.plainToClass(type, req.body), { skipMissingProperties: skipMissingProperties })
.then(function (errors) {
if (errors.length > 0) {
const message = errors.map((error) => Object.values(error.constraints)).join(', ');
var message = errors.map(function (error) { return Object.values(error.constraints); }).join(', ');
next(new exceptions_1.HttpException(400, message));

@@ -14,0 +15,0 @@ }

{
"name": "@fluyappgo/commons-backend",
"version": "1.0.150",
"version": "1.0.151",
"description": "",

@@ -22,2 +22,3 @@ "main": "./build/index.js",

"@types/jsonwebtoken": "^8.5.6",
"@types/redis": "^2.8.28",
"@types/validator": "^13.7.1",

@@ -33,3 +34,3 @@ "del-cli": "^3.0.1",

"cookie-session": "^2.0.0",
"express": "^4.18.2",
"express": "^4.17.2",
"express-rate-limit": "^7.5.0",

@@ -42,4 +43,4 @@ "express-session": "^1.17.2",

"pino-pretty": "^13.0.0",
"redis": "^4.0.2"
"redis": "^3.1.2"
}
}