@forzalabs/remora 1.0.11 → 1.0.14

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.
@@ -1,48 +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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const Affirm_1 = __importDefault(require("../core/Affirm"));
16
- const DatabaseEngine_1 = __importDefault(require("../database/DatabaseEngine"));
17
- const UserManager_1 = __importDefault(require("../engines/UserManager"));
18
- const Settings_1 = __importDefault(require("../helper/Settings"));
19
- const bcryptjs_1 = __importDefault(require("bcryptjs"));
20
- const JWTManager_1 = __importDefault(require("./JWTManager"));
21
- class AdminManagerClass {
22
- constructor() {
23
- this.COLLECTION = Settings_1.default.db.collections.users;
24
- this.rootSignIn = (password) => __awaiter(this, void 0, void 0, function* () {
25
- (0, Affirm_1.default)(password, 'Invalid password');
26
- const rootUser = yield DatabaseEngine_1.default.findOne(this.COLLECTION, { isRoot: true });
27
- (0, Affirm_1.default)(rootUser, 'Incorrect system configuration: root user not found');
28
- const isSame = yield bcryptjs_1.default.compare(password, rootUser.rootPasswordHash);
29
- if (!isSame)
30
- throw new Error('Invalid credentials');
31
- rootUser.lastLogin = new Date().toJSON();
32
- yield UserManager_1.default.update(rootUser);
33
- const adminSecret = process.env.ADMIN_JWT_SECRET;
34
- (0, Affirm_1.default)(adminSecret, 'Wrong system config: missing admin jwt secret');
35
- const payload = {
36
- apiKeyId: rootUser._id,
37
- installationId: process.env.INSTALLATION_ID,
38
- name: rootUser.name,
39
- scopes: { consumers: ['*'], projects: ['*'] },
40
- isAdmin: true
41
- };
42
- const token = JWTManager_1.default.issue(adminSecret, payload, 8);
43
- return token;
44
- });
45
- }
46
- }
47
- const AdminManager = new AdminManagerClass();
48
- exports.default = AdminManager;
@@ -1,45 +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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const Affirm_1 = __importDefault(require("../core/Affirm"));
16
- const DatabaseEngine_1 = __importDefault(require("../database/DatabaseEngine"));
17
- const Helper_1 = __importDefault(require("../helper/Helper"));
18
- const Settings_1 = __importDefault(require("../helper/Settings"));
19
- const JWTManager_1 = __importDefault(require("./JWTManager"));
20
- class ApiKeysManagerClass {
21
- constructor() {
22
- this.COLLECTION = Settings_1.default.db.collections.apiKeys;
23
- this.create = (name, scopes) => __awaiter(this, void 0, void 0, function* () {
24
- (0, Affirm_1.default)(name, 'Invalid name');
25
- const apiKeyId = Helper_1.default.uuid();
26
- const apiSecret = JWTManager_1.default.sign(apiKeyId, name, scopes);
27
- const newApiKey = {
28
- _id: apiKeyId,
29
- _signature: '',
30
- createdAt: new Date().toJSON(),
31
- isActive: true,
32
- name: name,
33
- scopes: scopes,
34
- value: apiSecret
35
- };
36
- return yield DatabaseEngine_1.default.upsert(this.COLLECTION, newApiKey._id, newApiKey);
37
- });
38
- this.get = (apiKeyId) => __awaiter(this, void 0, void 0, function* () {
39
- (0, Affirm_1.default)(apiKeyId, 'Invalid api key id');
40
- return yield DatabaseEngine_1.default.get(this.COLLECTION, apiKeyId);
41
- });
42
- }
43
- }
44
- const ApiKeysManager = new ApiKeysManagerClass();
45
- exports.default = ApiKeysManager;
@@ -1,56 +0,0 @@
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
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
7
- const Affirm_1 = __importDefault(require("../core/Affirm"));
8
- //
9
- class JWTManagerClass {
10
- constructor() {
11
- // ATTENTION!! ⚠️ ATTENTION!! ⚠️ ATTENTION!! ⚠️ ATTENTION!! ⚠️ ATTENTION!! ⚠️ ATTENTION!!⚠️ ATTENTION!!
12
- // ATTENTION!! The remoteSecretKey is saved in CLEAR text because we are studying a way to not make it visible to the customer. ATTENTION!!
13
- // ATTENTION!! ⚠️ ATTENTION!! ⚠️ ATTENTION!! ⚠️ ATTENTION!! ⚠️ ATTENTION!! ⚠️ ATTENTION!!⚠️ ATTENTION!!
14
- this.remoraSecretKey = 'violetevergardenisaworkofart';
15
- this.issue = (secret, payload, expirationHours) => {
16
- return jsonwebtoken_1.default.sign(payload, secret, { expiresIn: `${expirationHours}h` });
17
- };
18
- this.sign = (apiKeyId, name, scopes) => {
19
- (0, Affirm_1.default)(apiKeyId, 'Invalid api key id');
20
- (0, Affirm_1.default)(name, 'Invalid name');
21
- (0, Affirm_1.default)(scopes, 'Invalid scopes');
22
- const JWT_SECRET = process.env.JWT_SECRET;
23
- const INSTALLATION_ID = process.env.INSTALLATION_ID;
24
- (0, Affirm_1.default)(JWT_SECRET, 'Invalid JWT SECRET');
25
- (0, Affirm_1.default)(INSTALLATION_ID, 'Invalid INSTALLATION ID');
26
- const payload = {
27
- apiKeyId: apiKeyId,
28
- installationId: INSTALLATION_ID,
29
- name: name,
30
- scopes: scopes
31
- };
32
- return jsonwebtoken_1.default.sign(payload, JWT_SECRET, { expiresIn: '365000d' });
33
- };
34
- this.verify = (token) => {
35
- (0, Affirm_1.default)(token, 'Invalid token');
36
- const JWT_SECRET = process.env.JWT_SECRET;
37
- (0, Affirm_1.default)(JWT_SECRET, 'Invalid JWT SECRET');
38
- return jsonwebtoken_1.default.verify(token, JWT_SECRET);
39
- };
40
- this.verifyAdmin = (token) => {
41
- (0, Affirm_1.default)(token, 'Invalid token');
42
- const ADMIN_JWT_SECRET = process.env.ADMIN_JWT_SECRET;
43
- (0, Affirm_1.default)(ADMIN_JWT_SECRET, 'Invalid ADMIN JWT SECRET');
44
- return jsonwebtoken_1.default.verify(token, ADMIN_JWT_SECRET);
45
- };
46
- this.verifyCLI = (token) => {
47
- (0, Affirm_1.default)(token, 'Invalid token');
48
- // ⚠️ ATTENTION!! The remoteSecretKey is saved in clear text because we are studying a way to not make it visible to the customer. ATTENTION!!
49
- const REMORA_KEY_SECRET = process.env.REMORA_KEY_SECRET;
50
- (0, Affirm_1.default)(REMORA_KEY_SECRET, 'Invalid CLI JWT SECRET');
51
- return jsonwebtoken_1.default.verify(token, REMORA_KEY_SECRET);
52
- };
53
- }
54
- }
55
- const JWTManager = new JWTManagerClass();
56
- exports.default = JWTManager;
@@ -1,80 +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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const AdminManager_1 = __importDefault(require("../auth/AdminManager"));
16
- const Affirm_1 = __importDefault(require("../core/Affirm"));
17
- const UserManager_1 = __importDefault(require("../engines/UserManager"));
18
- const Helper_1 = __importDefault(require("../helper/Helper"));
19
- const DatabaseEngine_1 = __importDefault(require("./DatabaseEngine"));
20
- const DatabaseStructure_1 = __importDefault(require("./DatabaseStructure"));
21
- const bcryptjs_1 = __importDefault(require("bcryptjs"));
22
- class DatabaseInitializerClass {
23
- constructor() {
24
- this.initialize = () => __awaiter(this, void 0, void 0, function* () {
25
- try {
26
- yield DatabaseEngine_1.default.connect();
27
- yield this.createCollections();
28
- yield this.primeCollections();
29
- }
30
- catch (error) {
31
- console.error('Error initializing database:', error);
32
- throw error;
33
- }
34
- });
35
- this.createCollections = () => __awaiter(this, void 0, void 0, function* () {
36
- const db = DatabaseEngine_1.default.db();
37
- // Get list of existing collections
38
- const collections = yield db.listCollections().toArray();
39
- const existingCollections = collections.map(col => col.name);
40
- // Check and create required collections from SETTINGS
41
- for (const collection of DatabaseStructure_1.default.collections) {
42
- const name = collection.name;
43
- if (!existingCollections.includes(name)) {
44
- console.log(`Creating collection: ${name}`);
45
- yield db.createCollection(name);
46
- for (const index of collection.indexes) {
47
- console.log(`Setting up index ${JSON.stringify(index)}`);
48
- yield db.collection(name).createIndex(index);
49
- }
50
- }
51
- }
52
- console.log('Collections creation completed');
53
- });
54
- this.primeCollections = () => __awaiter(this, void 0, void 0, function* () {
55
- // Create the default user of the system
56
- (0, Affirm_1.default)(process.env.ROOT_TEMP_PASSWORD, 'Wrong system config: missing root user temp password');
57
- const rootUser = yield DatabaseEngine_1.default.findOne(AdminManager_1.default.COLLECTION, { isRoot: true });
58
- if (!rootUser) {
59
- const salt = yield bcryptjs_1.default.genSalt(10);
60
- const passHash = yield bcryptjs_1.default.hash(process.env.ROOT_TEMP_PASSWORD, salt);
61
- const newRootUser = {
62
- _id: Helper_1.default.uuid(),
63
- _signature: '',
64
- auth: { oid: null, provider: 'password' },
65
- email: 'root@remora.com',
66
- lastLogin: new Date().toJSON(),
67
- name: 'Root',
68
- roles: ['root'],
69
- isRoot: true,
70
- rootPasswordHash: passHash
71
- };
72
- console.log('Creating the default root user');
73
- yield UserManager_1.default.update(newRootUser);
74
- }
75
- console.log('Collections priming completed');
76
- });
77
- }
78
- }
79
- const DatabaseInitializer = new DatabaseInitializerClass();
80
- exports.default = DatabaseInitializer;
@@ -1,58 +0,0 @@
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
- const Constants_1 = __importDefault(require("../../Constants"));
7
- const Algo_1 = __importDefault(require("../../core/Algo"));
8
- const DSTE_1 = __importDefault(require("../../core/dste/DSTE"));
9
- class FileExporterClass {
10
- constructor() {
11
- this.prepareBatch = (batch, options) => {
12
- switch (options.recordProjection.format) {
13
- case 'JSON': {
14
- const jsonRecords = batch.map(x => x.toJSON());
15
- return this._splitIntoChunks(jsonRecords, '\n');
16
- }
17
- case 'CSV': {
18
- const csvRecords = batch.map(x => x.toCSV(options.recordProjection.delimiter));
19
- return this._splitIntoChunks(csvRecords, '\n');
20
- }
21
- }
22
- };
23
- this._splitIntoChunks = (records, separator) => {
24
- if (records.length === 0)
25
- return [''];
26
- const sampleRecord = records[0];
27
- const sampleLength = sampleRecord.length + separator.length; // Include separator in calculation
28
- const recordsPerChunk = Math.floor(Constants_1.default.defaults.STRING_MAX_CHARACTERS_LENGTH / sampleLength);
29
- // Ensure at least 1 record per chunk
30
- const chunkSize = Math.max(1, recordsPerChunk);
31
- const chunks = [];
32
- for (let i = 0; i < records.length; i += chunkSize) {
33
- const chunk = records.slice(i, i + chunkSize);
34
- chunks.push(chunk.join(separator) + separator);
35
- }
36
- return chunks;
37
- };
38
- this._extension = (output) => {
39
- return output.format === 'CSV'
40
- ? 'csv'
41
- : output.format === 'JSON'
42
- ? 'jsonl'
43
- : 'txt';
44
- };
45
- this._composeFileName = (consumer, output, extension, executionId) => {
46
- if (output.exportName && output.exportName.trim().length > 0) {
47
- // Ensure no extension duplication
48
- const sanitized = output.exportName.replace(/\.[^.]+$/, '');
49
- return `${sanitized}.${extension}`;
50
- }
51
- const baseTs = Algo_1.default.replaceAll(DSTE_1.default.now().toISOString().split('.')[0], ':', '-');
52
- const suffix = executionId ? `_${executionId}` : '';
53
- return `${consumer.name}_${baseTs}${suffix}.${extension}`;
54
- };
55
- }
56
- }
57
- const FileExporter = new FileExporterClass();
58
- exports.default = FileExporter;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });