@nextage/nx-frame-be 1.0.1
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 +1 -0
- package/README.md.old +45 -0
- package/build/app.d.ts +0 -0
- package/build/app.js +1 -0
- package/build/aws/aws-cluster-manager.d.ts +28 -0
- package/build/aws/aws-cluster-manager.js +105 -0
- package/build/aws/aws-email-manager.d.ts +24 -0
- package/build/aws/aws-email-manager.js +57 -0
- package/build/aws/aws-queue-manager.d.ts +37 -0
- package/build/aws/aws-queue-manager.js +100 -0
- package/build/aws/aws.interfaces.d.ts +39 -0
- package/build/aws/aws.interfaces.js +2 -0
- package/build/aws/index.d.ts +4 -0
- package/build/aws/index.js +20 -0
- package/build/common/base/__test__/base.model.test.d.ts +1 -0
- package/build/common/base/__test__/base.model.test.js +283 -0
- package/build/common/base/base.controller.d.ts +124 -0
- package/build/common/base/base.controller.js +134 -0
- package/build/common/base/base.interfaces.d.ts +81 -0
- package/build/common/base/base.interfaces.js +2 -0
- package/build/common/base/base.model.d.ts +384 -0
- package/build/common/base/base.model.js +730 -0
- package/build/common/base/folded.model.d.ts +41 -0
- package/build/common/base/folded.model.js +215 -0
- package/build/common/base/mongo-utils.d.ts +122 -0
- package/build/common/base/mongo-utils.js +242 -0
- package/build/common/base/mongo.types.d.ts +20 -0
- package/build/common/base/mongo.types.js +2 -0
- package/build/common/base/sql-utils.d.ts +20 -0
- package/build/common/base/sql-utils.js +69 -0
- package/build/common/constants.d.ts +27 -0
- package/build/common/constants.js +70 -0
- package/build/common/crypto/crypto.classes.d.ts +100 -0
- package/build/common/crypto/crypto.classes.js +146 -0
- package/build/common/crypto/crypto.constants.d.ts +68 -0
- package/build/common/crypto/crypto.constants.js +57 -0
- package/build/common/crypto/crypto.error.d.ts +4 -0
- package/build/common/crypto/crypto.error.js +10 -0
- package/build/common/crypto/crypto.interfaces.d.ts +46 -0
- package/build/common/crypto/crypto.interfaces.js +2 -0
- package/build/common/crypto/crypto.utils.d.ts +139 -0
- package/build/common/crypto/crypto.utils.js +380 -0
- package/build/common/crypto/index.d.ts +3 -0
- package/build/common/crypto/index.js +19 -0
- package/build/common/enums.d.ts +61 -0
- package/build/common/enums.js +75 -0
- package/build/common/errors.d.ts +13 -0
- package/build/common/errors.js +24 -0
- package/build/common/express/express.interfaces.d.ts +20 -0
- package/build/common/express/express.interfaces.js +2 -0
- package/build/common/express/express.utils.d.ts +31 -0
- package/build/common/express/express.utils.js +85 -0
- package/build/common/express/index.d.ts +2 -0
- package/build/common/express/index.js +18 -0
- package/build/common/graphql/__test__/generator.schema.test.d.ts +1 -0
- package/build/common/graphql/__test__/generator.schema.test.js +391 -0
- package/build/common/graphql/directives.d.ts +18 -0
- package/build/common/graphql/directives.js +56 -0
- package/build/common/graphql/generator copy.d.ts +41 -0
- package/build/common/graphql/generator copy.js +385 -0
- package/build/common/graphql/generator.d.ts +42 -0
- package/build/common/graphql/generator.js +385 -0
- package/build/common/graphql/index.d.ts +4 -0
- package/build/common/graphql/index.js +21 -0
- package/build/common/graphql/interfaces.d.ts +67 -0
- package/build/common/graphql/interfaces.js +2 -0
- package/build/common/graphql/loader.d.ts +22 -0
- package/build/common/graphql/loader.js +186 -0
- package/build/common/graphql/scalars/index.d.ts +10 -0
- package/build/common/graphql/scalars/index.js +6 -0
- package/build/common/graphql/scalars/resolvers.d.ts +8 -0
- package/build/common/graphql/scalars/resolvers.js +71 -0
- package/build/common/graphql/scalars/schema.d.ts +1 -0
- package/build/common/graphql/scalars/schema.js +12 -0
- package/build/common/graphql/types/index.d.ts +3 -0
- package/build/common/graphql/types/index.js +6 -0
- package/build/common/graphql/types/schema.d.ts +1 -0
- package/build/common/graphql/types/schema.js +98 -0
- package/build/common/graphql/utils.d.ts +18 -0
- package/build/common/graphql/utils.js +40 -0
- package/build/common/grid-fs/gridfs-base.model.d.ts +53 -0
- package/build/common/grid-fs/gridfs-base.model.js +95 -0
- package/build/common/grid-fs/gridfs.interfaces.d.ts +41 -0
- package/build/common/grid-fs/gridfs.interfaces.js +2 -0
- package/build/common/index.d.ts +10 -0
- package/build/common/index.js +32 -0
- package/build/common/interfaces.d.ts +26 -0
- package/build/common/interfaces.js +10 -0
- package/build/common/manager/bulk-manager.d.ts +59 -0
- package/build/common/manager/bulk-manager.js +103 -0
- package/build/common/manager/crypto-manager.d.ts +88 -0
- package/build/common/manager/crypto-manager.js +200 -0
- package/build/common/manager/index.d.ts +5 -0
- package/build/common/manager/index.js +21 -0
- package/build/common/manager/pubsub-manager.d.ts +20 -0
- package/build/common/manager/pubsub-manager.js +38 -0
- package/build/common/manager/shutdown-manager.d.ts +27 -0
- package/build/common/manager/shutdown-manager.js +118 -0
- package/build/common/manager/socket-io-cli-manager.d.ts +53 -0
- package/build/common/manager/socket-io-cli-manager.js +91 -0
- package/build/common/manager/tunnel-manager.d.ts +28 -0
- package/build/common/manager/tunnel-manager.js +49 -0
- package/build/common/models/coded-entity.controller.d.ts +5 -0
- package/build/common/models/coded-entity.controller.js +9 -0
- package/build/common/models/coded-entity.model.d.ts +25 -0
- package/build/common/models/coded-entity.model.js +51 -0
- package/build/common/models/user.model.d.ts +56 -0
- package/build/common/models/user.model.js +72 -0
- package/build/common/types.d.ts +136 -0
- package/build/common/types.js +16 -0
- package/build/common/utils.d.ts +552 -0
- package/build/common/utils.js +1100 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +18 -0
- package/build/test/env.d.ts +0 -0
- package/build/test/env.js +5 -0
- package/build/test/setup.d.ts +6 -0
- package/build/test/setup.js +59 -0
- package/package.json +90 -0
|
@@ -0,0 +1,69 @@
|
|
|
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.loadSQLModel = exports.TABLE_SYNC_PROMISES = exports.codedEntitySQLSchema = void 0;
|
|
7
|
+
const sequelize_1 = __importDefault(require("sequelize"));
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
exports.codedEntitySQLSchema = {
|
|
10
|
+
code: { type: sequelize_1.default.STRING, allowNull: false, unique: true },
|
|
11
|
+
name: { type: sequelize_1.default.STRING }
|
|
12
|
+
};
|
|
13
|
+
exports.TABLE_SYNC_PROMISES = {};
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {*} modelName
|
|
17
|
+
* @param {*} schema
|
|
18
|
+
* @param {*} collection
|
|
19
|
+
*/
|
|
20
|
+
function loadSQLModel(modelName, modelDef, schema, tableName, schemaName, params = {}) {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
if (!constants_1.APP.sqlz && !params.sqlz)
|
|
23
|
+
return;
|
|
24
|
+
const model = modelDef;
|
|
25
|
+
const sqlParams = {
|
|
26
|
+
sequelize: (_a = params.sqlz) !== null && _a !== void 0 ? _a : constants_1.APP.sqlz,
|
|
27
|
+
schema: schemaName,
|
|
28
|
+
createdAt: (_b = params.createdAt) !== null && _b !== void 0 ? _b : false,
|
|
29
|
+
updatedAt: (_c = params.updatedAt) !== null && _c !== void 0 ? _c : false,
|
|
30
|
+
tableName: tableName,
|
|
31
|
+
modelName: modelName
|
|
32
|
+
};
|
|
33
|
+
model.init(schema, sqlParams);
|
|
34
|
+
if (params.createTable) {
|
|
35
|
+
if (params.requires) {
|
|
36
|
+
const promises = ((_d = params.requires) !== null && _d !== void 0 ? _d : []).map((d) => { var _a; return (_a = exports.TABLE_SYNC_PROMISES[d]) !== null && _a !== void 0 ? _a : false; });
|
|
37
|
+
Promise.all(promises).then(() => {
|
|
38
|
+
exports.TABLE_SYNC_PROMISES[modelName] = model.sync();
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
exports.TABLE_SYNC_PROMISES[modelName] = model.sync();
|
|
43
|
+
}
|
|
44
|
+
return model;
|
|
45
|
+
}
|
|
46
|
+
exports.loadSQLModel = loadSQLModel;
|
|
47
|
+
// /**
|
|
48
|
+
// *
|
|
49
|
+
// * @param {*} period
|
|
50
|
+
// * @param {*} year
|
|
51
|
+
// */
|
|
52
|
+
// export function toFilterDatePeriod(period, year) {
|
|
53
|
+
// let values = getDatePeriod(period, year);
|
|
54
|
+
// return values ? { $gte: values[0], $lt: values[1] } : {};
|
|
55
|
+
// }
|
|
56
|
+
// export function checkDBSQLItem(idKey, model, item, logger = APP.logger) {
|
|
57
|
+
// if (!idKey || !model || !item || !item[idKey]) return (cb) => cb();
|
|
58
|
+
// let select = {};
|
|
59
|
+
// select[idKey] = item[idKey];
|
|
60
|
+
// return (cb) => {
|
|
61
|
+
// model.findOneNative(select).then(res => {
|
|
62
|
+
// if (res) return cb();
|
|
63
|
+
// model.mgModel.create(item).then(res => {
|
|
64
|
+
// logger.info(`Created ${model.name} (${item[idKey]})`, logClassCtx(this));
|
|
65
|
+
// cb();
|
|
66
|
+
// });
|
|
67
|
+
// });
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AppData } from './types';
|
|
3
|
+
import { CryptoUtils } from './crypto';
|
|
4
|
+
import { CryptoManager } from './manager/crypto-manager';
|
|
5
|
+
export declare const APP: AppData;
|
|
6
|
+
export declare const FILE_CONTENT_TYPES: {
|
|
7
|
+
none: string;
|
|
8
|
+
txt: string;
|
|
9
|
+
xml: string;
|
|
10
|
+
csv: string;
|
|
11
|
+
xls: string;
|
|
12
|
+
xlsx: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const MIME_TYPES: {
|
|
15
|
+
types: string[];
|
|
16
|
+
extension: string;
|
|
17
|
+
}[];
|
|
18
|
+
export declare const REGEX: {
|
|
19
|
+
pwd: RegExp;
|
|
20
|
+
email: RegExp;
|
|
21
|
+
dataurl: RegExp;
|
|
22
|
+
};
|
|
23
|
+
export declare const BUFFER_NULL: Buffer;
|
|
24
|
+
export declare const EVENT_TYPE: {};
|
|
25
|
+
export declare const MODEL_CRUD_EVENT = "crudEvent";
|
|
26
|
+
export declare const cryptoManager: CryptoManager;
|
|
27
|
+
export declare const cryptoUtils: CryptoUtils;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { CryptoManager } from './crypto-manager';
|
|
3
|
+
// import { CryptoUtils } from './crypto-utils';
|
|
4
|
+
// import { PubSubManager } from './pubsub-manager';
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cryptoUtils = exports.cryptoManager = exports.MODEL_CRUD_EVENT = exports.EVENT_TYPE = exports.BUFFER_NULL = exports.REGEX = exports.MIME_TYPES = exports.FILE_CONTENT_TYPES = exports.APP = void 0;
|
|
7
|
+
const pubsub_manager_1 = require("./manager/pubsub-manager");
|
|
8
|
+
const shutdown_manager_1 = require("./manager/shutdown-manager");
|
|
9
|
+
const enums_1 = require("./enums");
|
|
10
|
+
const crypto_1 = require("./crypto");
|
|
11
|
+
const crypto_manager_1 = require("./manager/crypto-manager");
|
|
12
|
+
exports.APP = {
|
|
13
|
+
status: enums_1.AppStatus.INIT,
|
|
14
|
+
logger: console,
|
|
15
|
+
prodMode: process.env.NODE_ENV === enums_1.AppMode.PROD, // prodMode(),
|
|
16
|
+
appName: process.env.APP_NAME || 'nx',
|
|
17
|
+
mongoModels: {},
|
|
18
|
+
streams: [],
|
|
19
|
+
dataScr: process.env.SECRET,
|
|
20
|
+
nxPubSub: new pubsub_manager_1.PubSubManager(),
|
|
21
|
+
shutdownMng: new shutdown_manager_1.ShutdownManager(),
|
|
22
|
+
config: { endpoint: {}, email: {}, jwt: {}, aws: {}, mongo: {}, logging: {}, invite: {}, msg: {} }
|
|
23
|
+
};
|
|
24
|
+
exports.FILE_CONTENT_TYPES = {
|
|
25
|
+
none: '',
|
|
26
|
+
txt: 'text/plain',
|
|
27
|
+
xml: 'text/xml',
|
|
28
|
+
csv: 'text/csv',
|
|
29
|
+
xls: 'application/vnd.ms-excel',
|
|
30
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
31
|
+
};
|
|
32
|
+
exports.MIME_TYPES = [
|
|
33
|
+
{ types: ['text/rtf'], extension: 'rtf' },
|
|
34
|
+
{ types: ['text/csv'], extension: 'csv' },
|
|
35
|
+
{ types: ['text/plain'], extension: 'txt' },
|
|
36
|
+
{ types: ['application/xml'], extension: 'xml' },
|
|
37
|
+
{ types: ['application/json'], extension: 'json' },
|
|
38
|
+
{ types: ['application/pdf'], extension: 'pdf' },
|
|
39
|
+
{ types: ['application/msword'], extension: 'doc' },
|
|
40
|
+
{ types: ['application/vnd.oasis.opendocument.text'], extension: 'odt' },
|
|
41
|
+
{ types: ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'], extension: 'docx' },
|
|
42
|
+
{ types: ['application/vnd.ms-excel'], extension: 'xls' },
|
|
43
|
+
{ types: ['application/vnd.oasis.opendocument.spreadsheet'], extension: 'ods' },
|
|
44
|
+
{ types: ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'], extension: 'xlsx' },
|
|
45
|
+
{ types: ['application/vnd.ms-powerpoint'], extension: 'ppt' },
|
|
46
|
+
{ types: ['application/vnd.oasis.opendocument.presentation'], extension: 'odp' },
|
|
47
|
+
{ types: ['application/vnd.openxmlformats-officedocument.presentationml.presentation'], extension: 'pptx' },
|
|
48
|
+
{ types: ['image/gif'], extension: 'gif' },
|
|
49
|
+
{ types: ['image/png'], extension: 'png' },
|
|
50
|
+
{ types: ['image/jpeg'], extension: 'jpg' },
|
|
51
|
+
{ types: ['image/bmp', 'image/x-ms-bmp'], extension: 'bmp' },
|
|
52
|
+
{ types: ['audio/mp3', 'audio/mpeg'], extension: 'mp3' },
|
|
53
|
+
{ types: ['audio/mp4', 'audio/x-m4a'], extension: 'm4a' },
|
|
54
|
+
{ types: ['audio/wav', 'audio/wave', 'audio/x-wav'], extension: 'wav' },
|
|
55
|
+
{ types: ['video/mp4'], extension: 'mp4' },
|
|
56
|
+
{ types: ['video/mpeg'], extension: 'mpeg' },
|
|
57
|
+
{ types: ['video/x-matroska'], extension: 'mkv' },
|
|
58
|
+
{ types: ['application/zip'], extension: 'zip' }
|
|
59
|
+
];
|
|
60
|
+
exports.REGEX = {
|
|
61
|
+
pwd: /^(?!.*[ ]{2})(\s*(?:\S\s*){12,128})$/,
|
|
62
|
+
email: /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/,
|
|
63
|
+
dataurl: /^data:.+\/(.+);base64,(.*)$/
|
|
64
|
+
};
|
|
65
|
+
exports.BUFFER_NULL = Buffer.from([0x00]);
|
|
66
|
+
exports.EVENT_TYPE = {};
|
|
67
|
+
exports.MODEL_CRUD_EVENT = 'crudEvent';
|
|
68
|
+
// export const nxPubSub = new PubSubManager();
|
|
69
|
+
exports.cryptoManager = new crypto_manager_1.CryptoManager();
|
|
70
|
+
exports.cryptoUtils = new crypto_1.CryptoUtils();
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import crypto from 'crypto';
|
|
4
|
+
import { Stream } from 'stream';
|
|
5
|
+
import { NxObject } from '../interfaces';
|
|
6
|
+
import { CertKeys, KeyAdditionalFieldAttrs } from './crypto.interfaces';
|
|
7
|
+
import { KeyOptionsAttrs, SymKeyAttrs } from './crypto.interfaces';
|
|
8
|
+
import { BaseModel } from '../base/base.model';
|
|
9
|
+
/**
|
|
10
|
+
* SYMM/ASYMM KEY/KEYPAIR TYPE CLASSES
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* @class
|
|
14
|
+
* @param { string } publicKey String represent the public key
|
|
15
|
+
* @param { string } privateKey String represent the private key
|
|
16
|
+
*/
|
|
17
|
+
export declare class AsymmetricKeyPair {
|
|
18
|
+
publicKey: crypto.KeyObject;
|
|
19
|
+
privateKey: crypto.KeyObject;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param { CertKeys } certKeys Strings representing the public anb private key
|
|
23
|
+
*/
|
|
24
|
+
constructor({ publicKey, privateKey }: CertKeys);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @class
|
|
28
|
+
* @param { string } key Specified string Key
|
|
29
|
+
* @param { string } iv Specified string Initialization Vector
|
|
30
|
+
* @param { number } size Specified bit size for AES algorithm
|
|
31
|
+
*/
|
|
32
|
+
export declare class SymmetricKey {
|
|
33
|
+
key: string;
|
|
34
|
+
iv: string;
|
|
35
|
+
size: number;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param { string } key Specified string Key
|
|
39
|
+
* @param { string } iv Specified string Initialization Vector
|
|
40
|
+
* @param { number } size Specified bit size for AES algorithm
|
|
41
|
+
*/
|
|
42
|
+
constructor({ key, iv, size }: SymKeyAttrs);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @class
|
|
46
|
+
* @member model the mongoose model where to save data
|
|
47
|
+
* @member filter filter for identify the document to edit adding data
|
|
48
|
+
* @member path the path where to save data ot data structure for a new document
|
|
49
|
+
* @member additionalFields the fields to add to the data when need to
|
|
50
|
+
* @member chunksize size of the chunks for split private or public key into array of chunks, if not present full key is used
|
|
51
|
+
*/
|
|
52
|
+
export declare class KeyOptions {
|
|
53
|
+
key?: string;
|
|
54
|
+
model: BaseModel<any, any, any>;
|
|
55
|
+
path: string;
|
|
56
|
+
chunkSize: number;
|
|
57
|
+
filter?: NxObject;
|
|
58
|
+
additionalFields?: KeyAdditionalFieldAttrs[];
|
|
59
|
+
isChunked: boolean;
|
|
60
|
+
hasAdditionalFields: boolean;
|
|
61
|
+
hasFilter: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* @param { BaseModel } model the mongoose model where to save data
|
|
64
|
+
* @param { object } filter filter for identify the document to edit adding data
|
|
65
|
+
* @param { string } path the path where to save data ot data structure for a new document
|
|
66
|
+
* @param { KeyAdditionalField[] } addiyionalFields the fields to add to the data when need to
|
|
67
|
+
* @param { number } chunkSize size of the chunks for split private or public key into array of chunks, if not present full key is used
|
|
68
|
+
*/
|
|
69
|
+
constructor({ key, model, filter, path, additionalFields, chunkSize }: KeyOptionsAttrs);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @class
|
|
73
|
+
* @member publicKeyOptions Options for the publicKey
|
|
74
|
+
* @member privateKeyOptions Options for the privateKey
|
|
75
|
+
*/
|
|
76
|
+
export declare class RSAKeyPairOptions {
|
|
77
|
+
publicKeyOptions: KeyOptions;
|
|
78
|
+
privateKeyOptions: KeyOptions;
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @param { KeyOptions } publicKeyOptions
|
|
82
|
+
* @param { KeyOptions } privateKeyOptions
|
|
83
|
+
*/
|
|
84
|
+
constructor(publicKeyOptions: KeyOptions, privateKeyOptions: KeyOptions);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @class
|
|
88
|
+
* @member symKey :
|
|
89
|
+
* @member cypheredStream :
|
|
90
|
+
*/
|
|
91
|
+
export declare class KeyCypheredStreamPair {
|
|
92
|
+
symKey: SymmetricKey;
|
|
93
|
+
cypheredStream: Stream;
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @param { SymmetricKey } symKey
|
|
97
|
+
* @param { Stream } cypheredStream
|
|
98
|
+
*/
|
|
99
|
+
constructor(symKey: SymmetricKey, cypheredStream: Stream);
|
|
100
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyCypheredStreamPair = exports.RSAKeyPairOptions = exports.KeyOptions = exports.SymmetricKey = exports.AsymmetricKeyPair = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
/**
|
|
6
|
+
* SYMM/ASYMM KEY/KEYPAIR TYPE CLASSES
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @class
|
|
10
|
+
* @param { string } publicKey String represent the public key
|
|
11
|
+
* @param { string } privateKey String represent the private key
|
|
12
|
+
*/
|
|
13
|
+
class AsymmetricKeyPair {
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param { CertKeys } certKeys Strings representing the public anb private key
|
|
17
|
+
*/
|
|
18
|
+
constructor({ publicKey, privateKey }) {
|
|
19
|
+
this.publicKey = publicKey;
|
|
20
|
+
this.privateKey = privateKey;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AsymmetricKeyPair = AsymmetricKeyPair;
|
|
24
|
+
/**
|
|
25
|
+
* @class
|
|
26
|
+
* @param { string } key Specified string Key
|
|
27
|
+
* @param { string } iv Specified string Initialization Vector
|
|
28
|
+
* @param { number } size Specified bit size for AES algorithm
|
|
29
|
+
*/
|
|
30
|
+
class SymmetricKey {
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param { string } key Specified string Key
|
|
34
|
+
* @param { string } iv Specified string Initialization Vector
|
|
35
|
+
* @param { number } size Specified bit size for AES algorithm
|
|
36
|
+
*/
|
|
37
|
+
constructor({ key, iv, size }) {
|
|
38
|
+
this.key = key;
|
|
39
|
+
this.iv = iv;
|
|
40
|
+
this.size = size;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.SymmetricKey = SymmetricKey;
|
|
44
|
+
/**
|
|
45
|
+
* RSA TYPE CLASSES
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* @class
|
|
49
|
+
* @member path
|
|
50
|
+
* @member value
|
|
51
|
+
*/
|
|
52
|
+
class KeyAdditionalField {
|
|
53
|
+
constructor({ path, value }) {
|
|
54
|
+
this.path = path;
|
|
55
|
+
this.value = value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @class
|
|
60
|
+
* @member model the mongoose model where to save data
|
|
61
|
+
* @member filter filter for identify the document to edit adding data
|
|
62
|
+
* @member path the path where to save data ot data structure for a new document
|
|
63
|
+
* @member additionalFields the fields to add to the data when need to
|
|
64
|
+
* @member chunksize size of the chunks for split private or public key into array of chunks, if not present full key is used
|
|
65
|
+
*/
|
|
66
|
+
class KeyOptions {
|
|
67
|
+
/**
|
|
68
|
+
* @param { BaseModel } model the mongoose model where to save data
|
|
69
|
+
* @param { object } filter filter for identify the document to edit adding data
|
|
70
|
+
* @param { string } path the path where to save data ot data structure for a new document
|
|
71
|
+
* @param { KeyAdditionalField[] } addiyionalFields the fields to add to the data when need to
|
|
72
|
+
* @param { number } chunkSize size of the chunks for split private or public key into array of chunks, if not present full key is used
|
|
73
|
+
*/
|
|
74
|
+
constructor({ key, model, filter, path, additionalFields, chunkSize }) {
|
|
75
|
+
// Comodity Booleans
|
|
76
|
+
this.isChunked = false;
|
|
77
|
+
this.hasAdditionalFields = !!this.additionalFields;
|
|
78
|
+
this.hasFilter = !!this.filter;
|
|
79
|
+
if (!model && !key)
|
|
80
|
+
throw new Error("Error, model or key param not provided! model param is mandatory!");
|
|
81
|
+
if (!path && !key)
|
|
82
|
+
throw new Error("Error, path or key param not provided! path param is mandatory!");
|
|
83
|
+
this.key = key;
|
|
84
|
+
this.model = model;
|
|
85
|
+
this.filter = filter;
|
|
86
|
+
this.path = path;
|
|
87
|
+
this.additionalFields = additionalFields;
|
|
88
|
+
this.chunkSize = chunkSize;
|
|
89
|
+
// Comodity Booleans
|
|
90
|
+
this.isChunked = !!chunkSize;
|
|
91
|
+
this.hasAdditionalFields = !!additionalFields;
|
|
92
|
+
this.hasFilter = !!filter;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.KeyOptions = KeyOptions;
|
|
96
|
+
/**
|
|
97
|
+
* @class
|
|
98
|
+
* @member publicKeyOptions Options for the publicKey
|
|
99
|
+
* @member privateKeyOptions Options for the privateKey
|
|
100
|
+
*/
|
|
101
|
+
class RSAKeyPairOptions {
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
* @param { KeyOptions } publicKeyOptions
|
|
105
|
+
* @param { KeyOptions } privateKeyOptions
|
|
106
|
+
*/
|
|
107
|
+
constructor(publicKeyOptions, privateKeyOptions) {
|
|
108
|
+
try {
|
|
109
|
+
publicKeyOptions = new KeyOptions(publicKeyOptions);
|
|
110
|
+
privateKeyOptions = new KeyOptions(privateKeyOptions);
|
|
111
|
+
}
|
|
112
|
+
catch (ex) {
|
|
113
|
+
throw Error('publicKey options and/or privateKey options values are not instances or compatible with RSAKeyOptions');
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @member { KeyOptions }
|
|
117
|
+
*/
|
|
118
|
+
this.publicKeyOptions = publicKeyOptions;
|
|
119
|
+
/**
|
|
120
|
+
* @member { KeyOptions }
|
|
121
|
+
*/
|
|
122
|
+
this.privateKeyOptions = privateKeyOptions;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.RSAKeyPairOptions = RSAKeyPairOptions;
|
|
126
|
+
/**
|
|
127
|
+
* @class
|
|
128
|
+
* @member symKey :
|
|
129
|
+
* @member cypheredStream :
|
|
130
|
+
*/
|
|
131
|
+
class KeyCypheredStreamPair {
|
|
132
|
+
/**
|
|
133
|
+
*
|
|
134
|
+
* @param { SymmetricKey } symKey
|
|
135
|
+
* @param { Stream } cypheredStream
|
|
136
|
+
*/
|
|
137
|
+
constructor(symKey, cypheredStream) {
|
|
138
|
+
if (!(symKey instanceof SymmetricKey))
|
|
139
|
+
throw new Error('symKey need to be of SymmetricKey type.');
|
|
140
|
+
if (!(cypheredStream instanceof stream_1.Stream))
|
|
141
|
+
throw new Error('cypheredStream need to be of Stream type.');
|
|
142
|
+
this.symKey = symKey;
|
|
143
|
+
this.cypheredStream = cypheredStream;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.KeyCypheredStreamPair = KeyCypheredStreamPair;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { NxTypeObject } from '../interfaces';
|
|
2
|
+
import { KeyEncoding, KeySizeMap } from './crypto.interfaces';
|
|
3
|
+
export declare const CRYPTO_ASYM_BITSIZE = 4096;
|
|
4
|
+
export declare const CRYPTO_SYM_BITSIZE = 256;
|
|
5
|
+
export declare const CRYPTO_ASYM_BITSIZE_LIST: number[];
|
|
6
|
+
export declare const CRYPTO_PUB_KEY_ENCODING: KeyEncoding;
|
|
7
|
+
export declare const CRYPTO_PRIV_KEY_ENCODING: KeyEncoding;
|
|
8
|
+
export declare const CRYPTO_SYM_BITSIZE_MAP: NxTypeObject<KeySizeMap>;
|
|
9
|
+
export declare enum CRYPTO_ERR_CODES {
|
|
10
|
+
BITSIZE = "ERR_INVALID_BITSIZE",
|
|
11
|
+
ARG_TYPE = "ERR_INVALID_ARG_TYPE",
|
|
12
|
+
ARG_INVALID = "ERR_INVALID_ARG",
|
|
13
|
+
NULL_ARG = "ERR_NULL_ARGS",
|
|
14
|
+
ASYM_ENC = "ERR_ASYM_ENC_FAIL",
|
|
15
|
+
ASYM_DEC = "ERR_ASYM_DEC_FAIL",
|
|
16
|
+
SYM_ENC = "ERR_SYM_ENC_FAIL",
|
|
17
|
+
SYM_DEC = "ERR_SYM_DEC_FAIL",
|
|
18
|
+
ASYM_KEYGEN = "ERR_ASYM_KEYGEN_FAIL",
|
|
19
|
+
SYM_KEYGEN = "ERR_SYM_KEYGEN_FAIL",
|
|
20
|
+
NOT_FOUND = "ERR_NOT_FOUND",
|
|
21
|
+
CHUNK_SIZE = "ERR_CHUNK_SIZE"
|
|
22
|
+
}
|
|
23
|
+
export declare const CRYPTO_ERRORS: {
|
|
24
|
+
SYM_BITSIZE: {
|
|
25
|
+
message: string;
|
|
26
|
+
code: CRYPTO_ERR_CODES;
|
|
27
|
+
};
|
|
28
|
+
SYM_DATA_TYPE: {
|
|
29
|
+
message: string;
|
|
30
|
+
code: CRYPTO_ERR_CODES;
|
|
31
|
+
};
|
|
32
|
+
ASYM_BITSIZE: {
|
|
33
|
+
message: string;
|
|
34
|
+
code: CRYPTO_ERR_CODES;
|
|
35
|
+
};
|
|
36
|
+
ASYM_PUB_ARGS: {
|
|
37
|
+
message: string;
|
|
38
|
+
code: CRYPTO_ERR_CODES;
|
|
39
|
+
};
|
|
40
|
+
ASYM_PRIV_ARGS: {
|
|
41
|
+
message: string;
|
|
42
|
+
code: CRYPTO_ERR_CODES;
|
|
43
|
+
};
|
|
44
|
+
KEY_OPTS_ARGS: {
|
|
45
|
+
message: string;
|
|
46
|
+
code: CRYPTO_ERR_CODES;
|
|
47
|
+
};
|
|
48
|
+
KEY_OPTS_PROPS: {
|
|
49
|
+
message: string;
|
|
50
|
+
code: CRYPTO_ERR_CODES;
|
|
51
|
+
};
|
|
52
|
+
PRIV_KEY_NOT_FOUND: {
|
|
53
|
+
message: string;
|
|
54
|
+
code: CRYPTO_ERR_CODES;
|
|
55
|
+
};
|
|
56
|
+
ENC_SYM_NOT_FOUND: {
|
|
57
|
+
message: string;
|
|
58
|
+
code: CRYPTO_ERR_CODES;
|
|
59
|
+
};
|
|
60
|
+
GEN_KEY_PAIR: {
|
|
61
|
+
message: string;
|
|
62
|
+
code: CRYPTO_ERR_CODES;
|
|
63
|
+
};
|
|
64
|
+
CHUNK_SIZE: {
|
|
65
|
+
message: string;
|
|
66
|
+
code: CRYPTO_ERR_CODES;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CRYPTO_ERRORS = exports.CRYPTO_ERR_CODES = exports.CRYPTO_SYM_BITSIZE_MAP = exports.CRYPTO_PRIV_KEY_ENCODING = exports.CRYPTO_PUB_KEY_ENCODING = exports.CRYPTO_ASYM_BITSIZE_LIST = exports.CRYPTO_SYM_BITSIZE = exports.CRYPTO_ASYM_BITSIZE = void 0;
|
|
4
|
+
exports.CRYPTO_ASYM_BITSIZE = 4096;
|
|
5
|
+
exports.CRYPTO_SYM_BITSIZE = 256;
|
|
6
|
+
exports.CRYPTO_ASYM_BITSIZE_LIST = [1024, 2048, 4096];
|
|
7
|
+
exports.CRYPTO_PUB_KEY_ENCODING = { type: 'spki', format: 'pem' };
|
|
8
|
+
exports.CRYPTO_PRIV_KEY_ENCODING = { type: 'pkcs8', format: 'pem' };
|
|
9
|
+
exports.CRYPTO_SYM_BITSIZE_MAP = {
|
|
10
|
+
128: {
|
|
11
|
+
keySize: 128,
|
|
12
|
+
ivSize: 128,
|
|
13
|
+
saltSize: 256,
|
|
14
|
+
phraseSize: 256
|
|
15
|
+
},
|
|
16
|
+
192: {
|
|
17
|
+
keySize: 192,
|
|
18
|
+
ivSize: 128,
|
|
19
|
+
saltSize: 192,
|
|
20
|
+
phraseSize: 256
|
|
21
|
+
},
|
|
22
|
+
256: {
|
|
23
|
+
keySize: 256,
|
|
24
|
+
ivSize: 128,
|
|
25
|
+
saltSize: 128,
|
|
26
|
+
phraseSize: 256
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var CRYPTO_ERR_CODES;
|
|
30
|
+
(function (CRYPTO_ERR_CODES) {
|
|
31
|
+
CRYPTO_ERR_CODES["BITSIZE"] = "ERR_INVALID_BITSIZE";
|
|
32
|
+
CRYPTO_ERR_CODES["ARG_TYPE"] = "ERR_INVALID_ARG_TYPE";
|
|
33
|
+
CRYPTO_ERR_CODES["ARG_INVALID"] = "ERR_INVALID_ARG";
|
|
34
|
+
CRYPTO_ERR_CODES["NULL_ARG"] = "ERR_NULL_ARGS";
|
|
35
|
+
CRYPTO_ERR_CODES["ASYM_ENC"] = "ERR_ASYM_ENC_FAIL";
|
|
36
|
+
CRYPTO_ERR_CODES["ASYM_DEC"] = "ERR_ASYM_DEC_FAIL";
|
|
37
|
+
CRYPTO_ERR_CODES["SYM_ENC"] = "ERR_SYM_ENC_FAIL";
|
|
38
|
+
CRYPTO_ERR_CODES["SYM_DEC"] = "ERR_SYM_DEC_FAIL";
|
|
39
|
+
CRYPTO_ERR_CODES["ASYM_KEYGEN"] = "ERR_ASYM_KEYGEN_FAIL";
|
|
40
|
+
CRYPTO_ERR_CODES["SYM_KEYGEN"] = "ERR_SYM_KEYGEN_FAIL";
|
|
41
|
+
CRYPTO_ERR_CODES["NOT_FOUND"] = "ERR_NOT_FOUND";
|
|
42
|
+
CRYPTO_ERR_CODES["CHUNK_SIZE"] = "ERR_CHUNK_SIZE";
|
|
43
|
+
})(CRYPTO_ERR_CODES || (exports.CRYPTO_ERR_CODES = CRYPTO_ERR_CODES = {}));
|
|
44
|
+
;
|
|
45
|
+
exports.CRYPTO_ERRORS = {
|
|
46
|
+
SYM_BITSIZE: { message: 'AES bit size not valid. Only 128/192/256 bit allowed.', code: CRYPTO_ERR_CODES.BITSIZE },
|
|
47
|
+
SYM_DATA_TYPE: { message: 'Type not supported, only "Stream", "String" or string primitive allowed.', code: CRYPTO_ERR_CODES.ARG_TYPE },
|
|
48
|
+
ASYM_BITSIZE: { message: 'RSA modulus size is not valid. Only 1024/2048/4096 bit allowed.', code: CRYPTO_ERR_CODES.BITSIZE },
|
|
49
|
+
ASYM_PUB_ARGS: { message: 'Public RSA Key and/or data arguments not supplied.', code: CRYPTO_ERR_CODES.NULL_ARG },
|
|
50
|
+
ASYM_PRIV_ARGS: { message: 'Private RSA Key and/or Encrypted Data arguments not supplied.', code: CRYPTO_ERR_CODES.NULL_ARG },
|
|
51
|
+
KEY_OPTS_ARGS: { message: 'keyOptions arguments not supplied', code: CRYPTO_ERR_CODES.NULL_ARG },
|
|
52
|
+
KEY_OPTS_PROPS: { message: '"model" and/or "filter" and/or "path" arguments not supplied. These arguments are needed to retrive a key', code: CRYPTO_ERR_CODES.NULL_ARG },
|
|
53
|
+
PRIV_KEY_NOT_FOUND: { message: 'Private Key not found.', code: CRYPTO_ERR_CODES.NOT_FOUND },
|
|
54
|
+
ENC_SYM_NOT_FOUND: { message: 'Cyphered symmetric Key not found.', code: CRYPTO_ERR_CODES.NOT_FOUND },
|
|
55
|
+
GEN_KEY_PAIR: { message: 'Cannot generate keyPair with supplied parameters.', code: CRYPTO_ERR_CODES.ARG_INVALID },
|
|
56
|
+
CHUNK_SIZE: { message: 'Provided chunkSize is different from original one.', code: CRYPTO_ERR_CODES.CHUNK_SIZE }
|
|
57
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CryptoError = void 0;
|
|
4
|
+
class CryptoError extends Error {
|
|
5
|
+
constructor(message = 'Crypto Error', code) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.CryptoError = CryptoError;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import { NxObject } from '../interfaces';
|
|
4
|
+
import { BaseModel } from '../base/base.model';
|
|
5
|
+
export interface KeySizeMap {
|
|
6
|
+
keySize: number;
|
|
7
|
+
ivSize: number;
|
|
8
|
+
saltSize: number;
|
|
9
|
+
phraseSize: number;
|
|
10
|
+
}
|
|
11
|
+
export interface KeyEncoding {
|
|
12
|
+
type: string;
|
|
13
|
+
format: string;
|
|
14
|
+
}
|
|
15
|
+
export interface RSAKeyPair {
|
|
16
|
+
publicKey: string;
|
|
17
|
+
privateKey: string;
|
|
18
|
+
}
|
|
19
|
+
export interface CertKeys {
|
|
20
|
+
publicKey: crypto.KeyObject;
|
|
21
|
+
privateKey: crypto.KeyObject;
|
|
22
|
+
ca?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SymKeyAttrs {
|
|
25
|
+
key: string;
|
|
26
|
+
iv: string;
|
|
27
|
+
size: number;
|
|
28
|
+
}
|
|
29
|
+
export interface KeyOptionsAttrs {
|
|
30
|
+
key?: string;
|
|
31
|
+
model: BaseModel<any, any, any>;
|
|
32
|
+
path: string;
|
|
33
|
+
chunkSize: number;
|
|
34
|
+
filter?: NxObject;
|
|
35
|
+
additionalFields?: KeyAdditionalFieldAttrs[];
|
|
36
|
+
}
|
|
37
|
+
export interface KeyAdditionalFieldAttrs {
|
|
38
|
+
path: string;
|
|
39
|
+
value: any;
|
|
40
|
+
}
|
|
41
|
+
export interface BlindIndexOptions {
|
|
42
|
+
hasher?: any;
|
|
43
|
+
iterations?: number;
|
|
44
|
+
keySize?: number;
|
|
45
|
+
normalize?: boolean;
|
|
46
|
+
}
|