@culturefy/shared 1.0.57 → 1.0.58
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/build/cjs/index.js +6 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/models/config-mapping.model.js +41 -0
- package/build/cjs/models/config-mapping.model.js.map +1 -0
- package/build/cjs/repositories/index.js +16 -0
- package/build/cjs/repositories/index.js.map +1 -0
- package/build/cjs/repositories/multi-tenant.repository.js +266 -0
- package/build/cjs/repositories/multi-tenant.repository.js.map +1 -0
- package/build/cjs/repositories/tenant-base.repository.js +52 -0
- package/build/cjs/repositories/tenant-base.repository.js.map +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/models/config-mapping.model.js +36 -0
- package/build/esm/models/config-mapping.model.js.map +1 -0
- package/build/esm/repositories/index.js +3 -0
- package/build/esm/repositories/index.js.map +1 -0
- package/build/esm/repositories/multi-tenant.repository.js +259 -0
- package/build/esm/repositories/multi-tenant.repository.js.map +1 -0
- package/build/esm/repositories/tenant-base.repository.js +48 -0
- package/build/esm/repositories/tenant-base.repository.js.map +1 -0
- package/build/src/index.d.ts +1 -0
- package/build/src/index.js +1 -0
- package/build/src/index.js.map +1 -1
- package/build/src/models/config-mapping.model.d.ts +20 -0
- package/build/src/models/config-mapping.model.js +41 -0
- package/build/src/models/config-mapping.model.js.map +1 -0
- package/build/src/repositories/index.d.ts +2 -0
- package/build/src/repositories/index.js +6 -0
- package/build/src/repositories/index.js.map +1 -0
- package/build/src/repositories/multi-tenant.repository.d.ts +44 -0
- package/build/src/repositories/multi-tenant.repository.js +295 -0
- package/build/src/repositories/multi-tenant.repository.js.map +1 -0
- package/build/src/repositories/tenant-base.repository.d.ts +17 -0
- package/build/src/repositories/tenant-base.repository.js +141 -0
- package/build/src/repositories/tenant-base.repository.js.map +1 -0
- package/package.json +1 -1
package/build/cjs/index.js
CHANGED
|
@@ -37,4 +37,10 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
37
37
|
if (key in exports && exports[key] === _constants[key]) return;
|
|
38
38
|
exports[key] = _constants[key];
|
|
39
39
|
});
|
|
40
|
+
var _repositories = require("./repositories");
|
|
41
|
+
Object.keys(_repositories).forEach(function (key) {
|
|
42
|
+
if (key === "default" || key === "__esModule") return;
|
|
43
|
+
if (key in exports && exports[key] === _repositories[key]) return;
|
|
44
|
+
exports[key] = _repositories[key];
|
|
45
|
+
});
|
|
40
46
|
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_types","require","Object","keys","forEach","key","exports","_enums","_utils","_cache","_middlewares","_constants"],"sources":["../../src/index.ts"],"sourcesContent":["export * from './types';\nexport * from './enums';\nexport * from './utils';\nexport * from './utils/cache';\nexport * from './middlewares';\nexport * from './constants';\n"],"mappings":";;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAL,MAAA,CAAAK,GAAA;AAAA;AACA,IAAAE,MAAA,GAAAN,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAI,MAAA,EAAAH,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAE,MAAA,CAAAF,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAE,MAAA,CAAAF,GAAA;AAAA;AACA,IAAAG,MAAA,GAAAP,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAK,MAAA,EAAAJ,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAG,MAAA,CAAAH,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAG,MAAA,CAAAH,GAAA;AAAA;AACA,IAAAI,MAAA,GAAAR,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAM,MAAA,EAAAL,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAI,MAAA,CAAAJ,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAI,MAAA,CAAAJ,GAAA;AAAA;AACA,IAAAK,YAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,YAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,YAAA,CAAAL,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAK,YAAA,CAAAL,GAAA;AAAA;AACA,IAAAM,UAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,UAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,UAAA,CAAAN,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAM,UAAA,CAAAN,GAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_types","require","Object","keys","forEach","key","exports","_enums","_utils","_cache","_middlewares","_constants","_repositories"],"sources":["../../src/index.ts"],"sourcesContent":["export * from './types';\nexport * from './enums';\nexport * from './utils';\nexport * from './utils/cache';\nexport * from './middlewares';\nexport * from './constants';\nexport * from './repositories';\n"],"mappings":";;;AAAA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;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,YAAA,CAAAL,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAK,YAAA,CAAAL,GAAA;AAAA;AACA,IAAAM,UAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,UAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,UAAA,CAAAN,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAM,UAAA,CAAAN,GAAA;AAAA;AACA,IAAAO,aAAA,GAAAX,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAS,aAAA,EAAAR,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,aAAA,CAAAP,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAO,aAAA,CAAAP,GAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.ConfigMappingModel = exports.CONFIG_MAPPING_DOCUMENT_NAME = exports.CONFIG_MAPPING_COLLECTION_NAME = void 0;
|
|
5
|
+
var _mongoose = _interopRequireWildcard(require("mongoose"));
|
|
6
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
7
|
+
const CONFIG_MAPPING_DOCUMENT_NAME = exports.CONFIG_MAPPING_DOCUMENT_NAME = 'ConfigMapping';
|
|
8
|
+
const CONFIG_MAPPING_COLLECTION_NAME = exports.CONFIG_MAPPING_COLLECTION_NAME = 'configMappings';
|
|
9
|
+
const schema = new _mongoose.Schema({
|
|
10
|
+
_id: {
|
|
11
|
+
type: _mongoose.Schema.Types.ObjectId,
|
|
12
|
+
required: true,
|
|
13
|
+
unique: true,
|
|
14
|
+
auto: true
|
|
15
|
+
},
|
|
16
|
+
businessId: {
|
|
17
|
+
type: _mongoose.Schema.Types.ObjectId,
|
|
18
|
+
required: true
|
|
19
|
+
},
|
|
20
|
+
connectionString: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
domain: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: false
|
|
27
|
+
},
|
|
28
|
+
appId: {
|
|
29
|
+
type: String,
|
|
30
|
+
required: false
|
|
31
|
+
},
|
|
32
|
+
serviceDBType: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: false
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
timestamps: true,
|
|
38
|
+
collection: CONFIG_MAPPING_COLLECTION_NAME
|
|
39
|
+
});
|
|
40
|
+
const ConfigMappingModel = exports.ConfigMappingModel = _mongoose.default.models.ConfigMapping || (0, _mongoose.model)(CONFIG_MAPPING_DOCUMENT_NAME, schema);
|
|
41
|
+
//# sourceMappingURL=config-mapping.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-mapping.model.js","names":["_mongoose","_interopRequireWildcard","require","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","CONFIG_MAPPING_DOCUMENT_NAME","exports","CONFIG_MAPPING_COLLECTION_NAME","schema","Schema","_id","type","Types","ObjectId","required","unique","auto","businessId","connectionString","String","domain","appId","serviceDBType","timestamps","collection","ConfigMappingModel","mongoose","models","ConfigMapping","model"],"sources":["../../../src/models/config-mapping.model.ts"],"sourcesContent":["import mongoose, { model, Schema } from 'mongoose';\n\nexport const CONFIG_MAPPING_DOCUMENT_NAME = 'ConfigMapping';\nexport const CONFIG_MAPPING_COLLECTION_NAME = 'configMappings';\n\nexport type ServiceDbType = 'main' | 'chatDB';\n\nexport interface IConfigMapping {\n _id?: Schema.Types.ObjectId;\n businessId: Schema.Types.ObjectId;\n connectionString: string;\n domain?: string;\n appId?: string;\n serviceDBType?: ServiceDbType;\n}\n\nexport interface ICreateConfigMapping {\n businessId: string;\n connectionString: string;\n domain?: string;\n appId?: string;\n serviceDBType?: ServiceDbType;\n}\n\nconst schema = new Schema<IConfigMapping>(\n {\n _id: {\n type: Schema.Types.ObjectId,\n required: true,\n unique: true,\n auto: true,\n },\n businessId: {\n type: Schema.Types.ObjectId,\n required: true,\n },\n connectionString: {\n type: String,\n required: true,\n },\n domain: {\n type: String,\n required: false,\n },\n appId: {\n type: String,\n required: false,\n },\n serviceDBType: {\n type: String,\n required: false,\n },\n },\n {\n timestamps: true,\n collection: CONFIG_MAPPING_COLLECTION_NAME,\n },\n);\n\nexport const ConfigMappingModel =\n mongoose.models.ConfigMapping ||\n model<IConfigMapping>(CONFIG_MAPPING_DOCUMENT_NAME, schema);\n"],"mappings":";;;;AAAA,IAAAA,SAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAmD,SAAAD,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,Q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AAQ,EAAE;EACZ,CAAC;EACDO,KAAK,EAAE;IACLV,IAAI,EAAEQ,MAAM;IACZL,QAAQ,EAAE;EACZ,CAAC;EACDQ,aAAa,EAAE;IACbX,IAAI,EAAEQ,MAAM;IACZL,QAAQ,EAAE;EACZ;AACF,CAAC,EACD;EACES,UAAU,EAAE,IAAI;EAChBC,UAAU,EAAEjB;AACd,CACF,CAAC;AAEM,MAAMkB,kBAAkB,GAAAnB,OAAA,CAAAmB,kBAAA,GAC7BC,iBAAQ,CAACC,MAAM,CAACC,aAAa,IAC7B,IAAAC,eAAK,EAAiBxB,4BAA4B,EAAEG,MAAM,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
var _multiTenant = require("./multi-tenant.repository");
|
|
5
|
+
Object.keys(_multiTenant).forEach(function (key) {
|
|
6
|
+
if (key === "default" || key === "__esModule") return;
|
|
7
|
+
if (key in exports && exports[key] === _multiTenant[key]) return;
|
|
8
|
+
exports[key] = _multiTenant[key];
|
|
9
|
+
});
|
|
10
|
+
var _tenantBase = require("./tenant-base.repository");
|
|
11
|
+
Object.keys(_tenantBase).forEach(function (key) {
|
|
12
|
+
if (key === "default" || key === "__esModule") return;
|
|
13
|
+
if (key in exports && exports[key] === _tenantBase[key]) return;
|
|
14
|
+
exports[key] = _tenantBase[key];
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_multiTenant","require","Object","keys","forEach","key","exports","_tenantBase"],"sources":["../../../src/repositories/index.ts"],"sourcesContent":["export * from \"./multi-tenant.repository\";\nexport * from \"./tenant-base.repository\";\n"],"mappings":";;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,YAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,YAAA,CAAAK,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAL,YAAA,CAAAK,GAAA;AAAA;AACA,IAAAE,WAAA,GAAAN,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAI,WAAA,EAAAH,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAE,WAAA,CAAAF,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAE,WAAA,CAAAF,GAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.TenantModelRepository = exports.MultiTenantRepository = void 0;
|
|
5
|
+
exports.WithTenantDb = WithTenantDb;
|
|
6
|
+
var _mongoose = _interopRequireWildcard(require("mongoose"));
|
|
7
|
+
var crypto = _interopRequireWildcard(require("crypto"));
|
|
8
|
+
var _identity = require("@azure/identity");
|
|
9
|
+
var _keyvaultSecrets = require("@azure/keyvault-secrets");
|
|
10
|
+
var _enums = require("../enums");
|
|
11
|
+
var _cache = require("../utils/cache");
|
|
12
|
+
var _secrets = require("../utils/secrets");
|
|
13
|
+
var _configMapping = require("../models/config-mapping.model");
|
|
14
|
+
var _dec, _dec2, _dec3, _class, _MultiTenantRepository;
|
|
15
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
16
|
+
function _applyDecoratedDescriptor(i, e, r, n, l) { var a = {}; return Object.keys(n).forEach(function (i) { a[i] = n[i]; }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function (r, n) { return n(i, e, r) || r; }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a; }
|
|
17
|
+
const tenantDbCache = (0, _cache.createCache)("tenant-db", 600);
|
|
18
|
+
const tenantBridgeCache = (0, _cache.createCache)("tenant-bridge-db-connection-string", 1800);
|
|
19
|
+
const encryptionKeyCache = (0, _cache.createCache)("db-enc-key", 1800);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Decorator that ensures tenant DB is connected before the method runs.
|
|
23
|
+
*/
|
|
24
|
+
function WithTenantDb(_target, _propertyKey, descriptor) {
|
|
25
|
+
if (!descriptor.value) return;
|
|
26
|
+
const originalMethod = descriptor.value;
|
|
27
|
+
descriptor.value = async function (...args) {
|
|
28
|
+
await this.ensureClientConnection();
|
|
29
|
+
return originalMethod.apply(this, args);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
let MultiTenantRepository = exports.MultiTenantRepository = (_dec = (0, _cache.Cacheable)({
|
|
33
|
+
cache: tenantBridgeCache,
|
|
34
|
+
key: () => ["tenant-bridge"],
|
|
35
|
+
getContext: instance => instance.context
|
|
36
|
+
}), _dec2 = (0, _cache.Cacheable)({
|
|
37
|
+
cache: encryptionKeyCache,
|
|
38
|
+
key: () => ["key"],
|
|
39
|
+
getContext: instance => instance.context
|
|
40
|
+
}), _dec3 = (0, _cache.Cacheable)({
|
|
41
|
+
cache: tenantDbCache,
|
|
42
|
+
key: (businessId, appId, serviceDbType) => [businessId, appId, serviceDbType],
|
|
43
|
+
getContext: instance => instance.context
|
|
44
|
+
}), _class = (_MultiTenantRepository = class MultiTenantRepository {
|
|
45
|
+
constructor(context, businessId, appId, config, serviceDBType) {
|
|
46
|
+
this.context = void 0;
|
|
47
|
+
this.tenantBridgeConfig = void 0;
|
|
48
|
+
this.businessId = void 0;
|
|
49
|
+
this.appId = void 0;
|
|
50
|
+
this.serviceDBType = void 0;
|
|
51
|
+
this.dbConnectionEncryptionKey = void 0;
|
|
52
|
+
this.clientConnectionString = void 0;
|
|
53
|
+
this.connectionPromise = void 0;
|
|
54
|
+
this.context = context;
|
|
55
|
+
this.businessId = businessId;
|
|
56
|
+
this.appId = appId;
|
|
57
|
+
this.serviceDBType = serviceDBType != null ? serviceDBType : "main";
|
|
58
|
+
this.tenantBridgeConfig = {
|
|
59
|
+
tenantBridgeEnvKey: "TENANT_BRIDGE_DB_URI",
|
|
60
|
+
tenantBridgeSecretKey: _enums.AzureSecretKeysEnum.DB_CONNECTING_STRING_TENANT_BRIDGE,
|
|
61
|
+
...config
|
|
62
|
+
};
|
|
63
|
+
this.connectionPromise = this.ensureClientConnection();
|
|
64
|
+
}
|
|
65
|
+
getEncryptionIv() {
|
|
66
|
+
const iv = process.env.DB_CONNECTION_STRING_ENCRYPTION_IV;
|
|
67
|
+
if (!iv) {
|
|
68
|
+
return Buffer.alloc(16, 0);
|
|
69
|
+
}
|
|
70
|
+
return this.normalizeFixedSize(iv, "IV");
|
|
71
|
+
}
|
|
72
|
+
normalizeFixedSize(value, label) {
|
|
73
|
+
const utf8Value = Buffer.from(value, "utf8");
|
|
74
|
+
if (utf8Value.length === 16) {
|
|
75
|
+
return utf8Value;
|
|
76
|
+
}
|
|
77
|
+
const base64Value = Buffer.from(value, "base64");
|
|
78
|
+
if (base64Value.length === 16) {
|
|
79
|
+
return base64Value;
|
|
80
|
+
}
|
|
81
|
+
const hexValue = Buffer.from(value, "hex");
|
|
82
|
+
if (hexValue.length === 16) {
|
|
83
|
+
return hexValue;
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`${label} must be 16 bytes for aes-128-cbc (got ${utf8Value.length})`);
|
|
86
|
+
}
|
|
87
|
+
async getOrCreateCachedConnection(connectionString) {
|
|
88
|
+
const existing = MultiTenantRepository.connections.get(connectionString);
|
|
89
|
+
if (existing && existing.connection.readyState === 1) {
|
|
90
|
+
return existing;
|
|
91
|
+
}
|
|
92
|
+
this.context.info(`Initializing database connection... ${connectionString}`);
|
|
93
|
+
const instance = new _mongoose.default.Mongoose();
|
|
94
|
+
try {
|
|
95
|
+
await instance.connect(connectionString, {
|
|
96
|
+
serverSelectionTimeoutMS: 10000,
|
|
97
|
+
connectTimeoutMS: 10000,
|
|
98
|
+
socketTimeoutMS: 45000
|
|
99
|
+
});
|
|
100
|
+
this.context.info(`✅ MongoDB connected successfully ${connectionString}`);
|
|
101
|
+
MultiTenantRepository.connections.set(connectionString, instance);
|
|
102
|
+
return instance;
|
|
103
|
+
} catch (err) {
|
|
104
|
+
this.context.error(`❌ MongoDB connection error for ${connectionString}`, {
|
|
105
|
+
message: err.message,
|
|
106
|
+
name: err.name,
|
|
107
|
+
code: err.code,
|
|
108
|
+
stack: err.stack
|
|
109
|
+
});
|
|
110
|
+
throw new Error(`Failed to connect to MongoDB: ${err.message}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
toObjectId(id, fieldName) {
|
|
114
|
+
if (!_mongoose.Types.ObjectId.isValid(id)) {
|
|
115
|
+
throw new Error(`Invalid ${fieldName}`);
|
|
116
|
+
}
|
|
117
|
+
return new _mongoose.Types.ObjectId(id);
|
|
118
|
+
}
|
|
119
|
+
async getTenantBridgeSrvDbConnectionString() {
|
|
120
|
+
const envKey = this.tenantBridgeConfig.tenantBridgeEnvKey;
|
|
121
|
+
const localUri = envKey ? process.env[envKey] : undefined;
|
|
122
|
+
if (localUri) {
|
|
123
|
+
return localUri;
|
|
124
|
+
}
|
|
125
|
+
const vault = process.env.AZURE_KEY_VAULT_NAME || "";
|
|
126
|
+
const secretKey = this.tenantBridgeConfig.tenantBridgeSecretKey || _enums.AzureSecretKeysEnum.DB_CONNECTING_STRING_TENANT_BRIDGE;
|
|
127
|
+
const dbUrl = await (0, _secrets.getAzureVaultSecretByKey)(this.context, vault, secretKey);
|
|
128
|
+
if (!dbUrl) {
|
|
129
|
+
throw new Error("TenantBridge database connection string not found");
|
|
130
|
+
}
|
|
131
|
+
return dbUrl;
|
|
132
|
+
}
|
|
133
|
+
async getDbConnectionEncryptionKey() {
|
|
134
|
+
var _secret$value;
|
|
135
|
+
if (this.dbConnectionEncryptionKey) {
|
|
136
|
+
return this.dbConnectionEncryptionKey;
|
|
137
|
+
}
|
|
138
|
+
const envKey = process.env.DB_CONNECTION_STRING_ENCRYPTION_KEY;
|
|
139
|
+
if (envKey) {
|
|
140
|
+
this.dbConnectionEncryptionKey = envKey;
|
|
141
|
+
return envKey;
|
|
142
|
+
}
|
|
143
|
+
const vault = process.env.AZURE_KEY_VAULT_NAME || "";
|
|
144
|
+
if (!vault) {
|
|
145
|
+
throw new Error("AZURE_KEY_VAULT_NAME is required to fetch encryption key");
|
|
146
|
+
}
|
|
147
|
+
const vaultUrl = `https://${vault}.vault.azure.net`;
|
|
148
|
+
const credential = new _identity.DefaultAzureCredential();
|
|
149
|
+
const client = new _keyvaultSecrets.SecretClient(vaultUrl, credential);
|
|
150
|
+
const secret = await client.getSecret("DB-CONNECTION-STRING-ENCRYPTION-KEY");
|
|
151
|
+
const key = (_secret$value = secret.value) != null ? _secret$value : "";
|
|
152
|
+
if (!key) {
|
|
153
|
+
throw new Error("DB connection string encryption key not found");
|
|
154
|
+
}
|
|
155
|
+
this.dbConnectionEncryptionKey = key;
|
|
156
|
+
return key;
|
|
157
|
+
}
|
|
158
|
+
async decryptConnectionString(encryptedValue) {
|
|
159
|
+
const key = await this.getDbConnectionEncryptionKey();
|
|
160
|
+
const keyBuffer = this.normalizeEncryptionKey(key);
|
|
161
|
+
const ivBuffer = this.getEncryptionIv();
|
|
162
|
+
const decipher = crypto.createDecipheriv("aes-128-cbc", keyBuffer, ivBuffer);
|
|
163
|
+
let decrypted = decipher.update(encryptedValue, "base64", "utf8");
|
|
164
|
+
decrypted += decipher.final("utf8");
|
|
165
|
+
return decrypted;
|
|
166
|
+
}
|
|
167
|
+
normalizeEncryptionKey(key) {
|
|
168
|
+
const utf8Key = Buffer.from(key, "utf8");
|
|
169
|
+
if (utf8Key.length === 16) {
|
|
170
|
+
return utf8Key;
|
|
171
|
+
}
|
|
172
|
+
const base64Key = Buffer.from(key, "base64");
|
|
173
|
+
if (base64Key.length === 16) {
|
|
174
|
+
return base64Key;
|
|
175
|
+
}
|
|
176
|
+
const hexKey = Buffer.from(key, "hex");
|
|
177
|
+
if (hexKey.length === 16) {
|
|
178
|
+
return hexKey;
|
|
179
|
+
}
|
|
180
|
+
throw new Error(`DB connection string encryption key must be 16 bytes for aes-128-cbc (got ${utf8Key.length})`);
|
|
181
|
+
}
|
|
182
|
+
async getClientDbConnectionString(businessId, appId, serviceDBType) {
|
|
183
|
+
const resolvedServiceDbType = serviceDBType != null ? serviceDBType : "main";
|
|
184
|
+
const tenantBridgeUrl = await this.getTenantBridgeSrvDbConnectionString();
|
|
185
|
+
const connection = await this.getOrCreateCachedConnection(tenantBridgeUrl);
|
|
186
|
+
const ConfigMapping = this.getModel(connection, _configMapping.CONFIG_MAPPING_DOCUMENT_NAME, _configMapping.ConfigMappingModel.schema, _configMapping.CONFIG_MAPPING_COLLECTION_NAME);
|
|
187
|
+
const filter = {
|
|
188
|
+
businessId: this.toObjectId(businessId, "businessId")
|
|
189
|
+
};
|
|
190
|
+
if (appId) {
|
|
191
|
+
filter.appId = appId;
|
|
192
|
+
}
|
|
193
|
+
filter.serviceDBType = resolvedServiceDbType;
|
|
194
|
+
const configMapping = await ConfigMapping.findOne(filter).lean().exec();
|
|
195
|
+
if (!(configMapping != null && configMapping.connectionString)) {
|
|
196
|
+
throw new Error("Config mapping not found for this business");
|
|
197
|
+
}
|
|
198
|
+
const decryptedConnectionString = await this.decryptConnectionString(configMapping.connectionString);
|
|
199
|
+
this.context.info(`Resolved tenant DB connection string from bridge: ${decryptedConnectionString}`);
|
|
200
|
+
return decryptedConnectionString;
|
|
201
|
+
}
|
|
202
|
+
getConnection() {
|
|
203
|
+
if (!this.clientConnectionString) return undefined;
|
|
204
|
+
return MultiTenantRepository.connections.get(this.clientConnectionString);
|
|
205
|
+
}
|
|
206
|
+
async ensureClientConnection() {
|
|
207
|
+
if (this.connectionPromise) {
|
|
208
|
+
return this.connectionPromise;
|
|
209
|
+
}
|
|
210
|
+
if (this.clientConnectionString) {
|
|
211
|
+
const existing = this.getConnection();
|
|
212
|
+
if (existing && existing.connection.readyState === 1) {
|
|
213
|
+
return existing;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const clientDbUrl = await this.getClientDbConnectionString(this.businessId, this.appId, this.serviceDBType);
|
|
217
|
+
this.clientConnectionString = clientDbUrl;
|
|
218
|
+
this.connectionPromise = this.getOrCreateCachedConnection(clientDbUrl);
|
|
219
|
+
return this.connectionPromise;
|
|
220
|
+
}
|
|
221
|
+
async disconnectByConnectionString(connectionString) {
|
|
222
|
+
const existing = MultiTenantRepository.connections.get(connectionString);
|
|
223
|
+
if (!existing) return;
|
|
224
|
+
try {
|
|
225
|
+
await existing.disconnect();
|
|
226
|
+
this.context.info(`✅ Disconnected from database: ${connectionString}`);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
this.context.error(`❌ Error disconnecting from database: ${connectionString}`, error);
|
|
229
|
+
} finally {
|
|
230
|
+
MultiTenantRepository.connections.delete(connectionString);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async disconnectClient() {
|
|
234
|
+
const clientDbUrl = await this.getClientDbConnectionString(this.businessId, this.appId);
|
|
235
|
+
await this.disconnectByConnectionString(clientDbUrl);
|
|
236
|
+
this.clientConnectionString = undefined;
|
|
237
|
+
this.connectionPromise = undefined;
|
|
238
|
+
}
|
|
239
|
+
getTenantModel(modelName, schema, collectionName) {
|
|
240
|
+
const connection = this.getConnection();
|
|
241
|
+
if (!connection) {
|
|
242
|
+
throw new Error("database connection not established");
|
|
243
|
+
}
|
|
244
|
+
return this.getModel(connection, modelName, schema, collectionName);
|
|
245
|
+
}
|
|
246
|
+
model(model, collectionName) {
|
|
247
|
+
return this.getTenantModel(model.modelName, model.schema, collectionName);
|
|
248
|
+
}
|
|
249
|
+
getModel(connection, modelName, schema, collectionName) {
|
|
250
|
+
if (connection.models[modelName]) {
|
|
251
|
+
return connection.models[modelName];
|
|
252
|
+
}
|
|
253
|
+
return connection.model(modelName, schema, collectionName);
|
|
254
|
+
}
|
|
255
|
+
}, _MultiTenantRepository.connections = new Map(), _MultiTenantRepository), _applyDecoratedDescriptor(_class.prototype, "getTenantBridgeSrvDbConnectionString", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "getTenantBridgeSrvDbConnectionString"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "getDbConnectionEncryptionKey", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "getDbConnectionEncryptionKey"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "getClientDbConnectionString", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "getClientDbConnectionString"), _class.prototype), _class);
|
|
256
|
+
class TenantModelRepository extends MultiTenantRepository {
|
|
257
|
+
constructor(...args) {
|
|
258
|
+
super(...args);
|
|
259
|
+
this.modelDef = void 0;
|
|
260
|
+
}
|
|
261
|
+
get dbModel() {
|
|
262
|
+
return this.model(this.modelDef);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
exports.TenantModelRepository = TenantModelRepository;
|
|
266
|
+
//# sourceMappingURL=multi-tenant.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-tenant.repository.js","names":["_mongoose","_interopRequireWildcard","require","crypto","_identity","_keyvaultSecrets","_enums","_cache","_secrets","_configMapping","_dec","_dec2","_dec3","_class","_MultiTenantRepository","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_applyDecoratedDescriptor","l","a","keys","forEach","enumerable","configurable","initializer","writable","slice","reverse","reduce","value","tenantDbCache","createCache","tenantBridgeCache","encryptionKeyCache","WithTenantDb","_target","_propertyKey","descriptor","originalMethod","args","ensureClientConnection","apply","MultiTenantRepository","exports","Cacheable","cache","key","getContext","instance","context","businessId","appId","serviceDbType","constructor","config","serviceDBType","tenantBridgeConfig","dbConnectionEncryptionKey","clientConnectionString","connectionPromise","tenantBridgeEnvKey","tenantBridgeSecretKey","AzureSecretKeysEnum","DB_CONNECTING_STRING_TENANT_BRIDGE","getEncryptionIv","iv","process","env","DB_CONNECTION_STRING_ENCRYPTION_IV","Buffer","alloc","normalizeFixedSize","label","utf8Value","from","length","base64Value","hexValue","Error","getOrCreateCachedConnection","connectionString","existing","connections","connection","readyState","info","mongoose","Mongoose","connect","serverSelectionTimeoutMS","connectTimeoutMS","socketTimeoutMS","err","error","message","name","code","stack","toObjectId","id","fieldName","Types","ObjectId","isValid","getTenantBridgeSrvDbConnectionString","envKey","localUri","undefined","vault","AZURE_KEY_VAULT_NAME","secretKey","dbUrl","getAzureVaultSecretByKey","getDbConnectionEncryptionKey","_secret$value","DB_CONNECTION_STRING_ENCRYPTION_KEY","vaultUrl","credential","DefaultAzureCredential","client","SecretClient","secret","getSecret","decryptConnectionString","encryptedValue","keyBuffer","normalizeEncryptionKey","ivBuffer","decipher","createDecipheriv","decrypted","update","final","utf8Key","base64Key","hexKey","getClientDbConnectionString","resolvedServiceDbType","tenantBridgeUrl","ConfigMapping","getModel","CONFIG_MAPPING_DOCUMENT_NAME","ConfigMappingModel","schema","CONFIG_MAPPING_COLLECTION_NAME","filter","configMapping","findOne","lean","exec","decryptedConnectionString","getConnection","clientDbUrl","disconnectByConnectionString","disconnect","delete","disconnectClient","getTenantModel","modelName","collectionName","model","models","Map","prototype","TenantModelRepository","modelDef","dbModel"],"sources":["../../../src/repositories/multi-tenant.repository.ts"],"sourcesContent":["import mongoose, { Model, Schema, Types } from \"mongoose\";\nimport * as crypto from \"crypto\";\nimport { InvocationContext } from \"@azure/functions\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\nimport { SecretClient } from \"@azure/keyvault-secrets\";\nimport { AzureSecretKeysEnum } from \"../enums\";\nimport { Cacheable, createCache } from \"../utils/cache\";\nimport { getAzureVaultSecretByKey } from \"../utils/secrets\";\nimport {\n CONFIG_MAPPING_COLLECTION_NAME,\n CONFIG_MAPPING_DOCUMENT_NAME,\n ConfigMappingModel,\n IConfigMapping,\n} from \"../models/config-mapping.model\";\n\ntype ConnectionMap = Map<string, mongoose.Mongoose>;\n\ntype TenantBridgeConfig = {\n tenantBridgeEnvKey?: string;\n tenantBridgeSecretKey?: AzureSecretKeysEnum;\n};\n\nconst tenantDbCache = createCache(\"tenant-db\", 600);\nconst tenantBridgeCache = createCache(\"tenant-bridge-db-connection-string\", 1800);\nconst encryptionKeyCache = createCache(\"db-enc-key\", 1800);\n\n/**\n * Decorator that ensures tenant DB is connected before the method runs.\n */\nexport function WithTenantDb(\n _target: any,\n _propertyKey: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any>>,\n): void {\n if (!descriptor.value) return;\n const originalMethod = descriptor.value;\n descriptor.value = async function (\n this: MultiTenantRepository,\n ...args: any[]\n ) {\n await this.ensureClientConnection();\n return originalMethod.apply(this, args);\n };\n}\n\nexport class MultiTenantRepository {\n private static connections: ConnectionMap = new Map();\n private readonly context: InvocationContext;\n private readonly tenantBridgeConfig: TenantBridgeConfig;\n private readonly businessId: string;\n private readonly appId?: string;\n private readonly serviceDBType?: string;\n private dbConnectionEncryptionKey?: string;\n private clientConnectionString?: string;\n private connectionPromise?: Promise<mongoose.Mongoose>;\n\n constructor(\n context: InvocationContext,\n businessId: string,\n appId?: string,\n config?: TenantBridgeConfig,\n serviceDBType?: string,\n ) {\n this.context = context;\n this.businessId = businessId;\n this.appId = appId;\n this.serviceDBType = serviceDBType ?? \"main\";\n this.tenantBridgeConfig = {\n tenantBridgeEnvKey: \"TENANT_BRIDGE_DB_URI\",\n tenantBridgeSecretKey: AzureSecretKeysEnum.DB_CONNECTING_STRING_TENANT_BRIDGE,\n ...config,\n };\n\n this.connectionPromise = this.ensureClientConnection();\n }\n\n private getEncryptionIv(): Buffer {\n const iv = process.env.DB_CONNECTION_STRING_ENCRYPTION_IV;\n if (!iv) {\n return Buffer.alloc(16, 0);\n }\n return this.normalizeFixedSize(iv, \"IV\");\n }\n\n private normalizeFixedSize(value: string, label: string): Buffer {\n const utf8Value = Buffer.from(value, \"utf8\");\n if (utf8Value.length === 16) {\n return utf8Value;\n }\n\n const base64Value = Buffer.from(value, \"base64\");\n if (base64Value.length === 16) {\n return base64Value;\n }\n\n const hexValue = Buffer.from(value, \"hex\");\n if (hexValue.length === 16) {\n return hexValue;\n }\n\n throw new Error(\n `${label} must be 16 bytes for aes-128-cbc (got ${utf8Value.length})`,\n );\n }\n\n private async getOrCreateCachedConnection(\n connectionString: string,\n ): Promise<mongoose.Mongoose> {\n const existing = MultiTenantRepository.connections.get(connectionString);\n if (existing && existing.connection.readyState === 1) {\n return existing;\n }\n\n this.context.info(`Initializing database connection... ${connectionString}`);\n const instance = new mongoose.Mongoose();\n\n try {\n await instance.connect(connectionString, {\n serverSelectionTimeoutMS: 10000,\n connectTimeoutMS: 10000,\n socketTimeoutMS: 45000,\n });\n this.context.info(`✅ MongoDB connected successfully ${connectionString}`);\n MultiTenantRepository.connections.set(connectionString, instance);\n return instance;\n } catch (err: any) {\n this.context.error(\n `❌ MongoDB connection error for ${connectionString}`,\n {\n message: err.message,\n name: err.name,\n code: err.code,\n stack: err.stack,\n },\n );\n throw new Error(`Failed to connect to MongoDB: ${err.message}`);\n }\n }\n\n private toObjectId(id: string, fieldName: string): Types.ObjectId {\n if (!Types.ObjectId.isValid(id)) {\n throw new Error(`Invalid ${fieldName}`);\n }\n return new Types.ObjectId(id);\n }\n\n @Cacheable({\n cache: tenantBridgeCache,\n key: () => [\"tenant-bridge\"],\n getContext: (instance: unknown) =>\n (instance as MultiTenantRepository).context,\n })\n async getTenantBridgeSrvDbConnectionString(): Promise<string> {\n const envKey = this.tenantBridgeConfig.tenantBridgeEnvKey;\n const localUri =\n (envKey ? process.env[envKey] : undefined);\n\n if (localUri) {\n return localUri;\n }\n\n const vault = process.env.AZURE_KEY_VAULT_NAME || \"\";\n const secretKey =\n this.tenantBridgeConfig.tenantBridgeSecretKey ||\n AzureSecretKeysEnum.DB_CONNECTING_STRING_TENANT_BRIDGE;\n\n const dbUrl = await getAzureVaultSecretByKey(\n this.context,\n vault,\n secretKey,\n );\n if (!dbUrl) {\n throw new Error(\"TenantBridge database connection string not found\");\n }\n return dbUrl;\n }\n\n @Cacheable({\n cache: encryptionKeyCache,\n key: () => [\"key\"],\n getContext: (instance: unknown) =>\n (instance as MultiTenantRepository).context,\n })\n private async getDbConnectionEncryptionKey(): Promise<string> {\n if (this.dbConnectionEncryptionKey) {\n return this.dbConnectionEncryptionKey;\n }\n\n const envKey = process.env.DB_CONNECTION_STRING_ENCRYPTION_KEY;\n if (envKey) {\n this.dbConnectionEncryptionKey = envKey;\n return envKey;\n }\n\n const vault = process.env.AZURE_KEY_VAULT_NAME || \"\";\n if (!vault) {\n throw new Error(\"AZURE_KEY_VAULT_NAME is required to fetch encryption key\");\n }\n const vaultUrl = `https://${vault}.vault.azure.net`;\n const credential = new DefaultAzureCredential();\n const client = new SecretClient(vaultUrl, credential);\n const secret = await client.getSecret(\"DB-CONNECTION-STRING-ENCRYPTION-KEY\");\n const key = secret.value ?? \"\";\n if (!key) {\n throw new Error(\"DB connection string encryption key not found\");\n }\n this.dbConnectionEncryptionKey = key;\n return key;\n }\n\n private async decryptConnectionString(encryptedValue: string): Promise<string> {\n const key = await this.getDbConnectionEncryptionKey();\n const keyBuffer = this.normalizeEncryptionKey(key);\n\n const ivBuffer = this.getEncryptionIv();\n const decipher = crypto.createDecipheriv(\"aes-128-cbc\", keyBuffer, ivBuffer);\n let decrypted = decipher.update(encryptedValue, \"base64\", \"utf8\");\n decrypted += decipher.final(\"utf8\");\n return decrypted;\n }\n\n private normalizeEncryptionKey(key: string): Buffer {\n const utf8Key = Buffer.from(key, \"utf8\");\n if (utf8Key.length === 16) {\n return utf8Key;\n }\n\n const base64Key = Buffer.from(key, \"base64\");\n if (base64Key.length === 16) {\n return base64Key;\n }\n\n const hexKey = Buffer.from(key, \"hex\");\n if (hexKey.length === 16) {\n return hexKey;\n }\n\n throw new Error(\n `DB connection string encryption key must be 16 bytes for aes-128-cbc (got ${utf8Key.length})`,\n );\n }\n\n @Cacheable({\n cache: tenantDbCache,\n key: (businessId: string, appId?: string, serviceDbType?: string) => [\n businessId,\n appId,\n serviceDbType,\n ],\n getContext: (instance: unknown) =>\n (instance as MultiTenantRepository).context,\n })\n async getClientDbConnectionString(\n businessId: string,\n appId?: string,\n serviceDBType?: string,\n ): Promise<string> {\n const resolvedServiceDbType = serviceDBType ?? \"main\";\n const tenantBridgeUrl = await this.getTenantBridgeSrvDbConnectionString();\n const connection = await this.getOrCreateCachedConnection(tenantBridgeUrl);\n\n const ConfigMapping = this.getModel(\n connection,\n CONFIG_MAPPING_DOCUMENT_NAME,\n ConfigMappingModel.schema,\n CONFIG_MAPPING_COLLECTION_NAME,\n ) as Model<IConfigMapping>;\n\n const filter: Record<string, unknown> = {\n businessId: this.toObjectId(businessId, \"businessId\"),\n };\n if (appId) {\n filter.appId = appId;\n }\n filter.serviceDBType = resolvedServiceDbType;\n\n const configMapping =\n (await ConfigMapping.findOne(filter).lean().exec()) as\n | IConfigMapping\n | null;\n if (!configMapping?.connectionString) {\n throw new Error(\"Config mapping not found for this business\");\n }\n const decryptedConnectionString = await this.decryptConnectionString(\n configMapping.connectionString,\n );\n this.context.info(\n `Resolved tenant DB connection string from bridge: ${decryptedConnectionString}`,\n );\n return decryptedConnectionString;\n }\n\n protected getConnection(): mongoose.Mongoose | undefined {\n if (!this.clientConnectionString) return undefined;\n return MultiTenantRepository.connections.get(this.clientConnectionString);\n }\n\n protected async ensureClientConnection(): Promise<mongoose.Mongoose> {\n if (this.connectionPromise) {\n return this.connectionPromise;\n }\n\n if (this.clientConnectionString) {\n const existing = this.getConnection();\n if (existing && existing.connection.readyState === 1) {\n return existing;\n }\n }\n\n const clientDbUrl = await this.getClientDbConnectionString(\n this.businessId,\n this.appId,\n this.serviceDBType,\n );\n this.clientConnectionString = clientDbUrl;\n this.connectionPromise = this.getOrCreateCachedConnection(clientDbUrl);\n return this.connectionPromise;\n }\n\n async disconnectByConnectionString(connectionString: string): Promise<void> {\n const existing = MultiTenantRepository.connections.get(connectionString);\n if (!existing) return;\n try {\n await existing.disconnect();\n this.context.info(`✅ Disconnected from database: ${connectionString}`);\n } catch (error) {\n this.context.error(`❌ Error disconnecting from database: ${connectionString}`, error);\n } finally {\n MultiTenantRepository.connections.delete(connectionString);\n }\n }\n\n async disconnectClient(): Promise<void> {\n const clientDbUrl = await this.getClientDbConnectionString(\n this.businessId,\n this.appId,\n );\n await this.disconnectByConnectionString(clientDbUrl);\n this.clientConnectionString = undefined;\n this.connectionPromise = undefined;\n }\n\n protected getTenantModel(\n modelName: string,\n schema: Schema<any>,\n collectionName?: string,\n ): Model<any> {\n const connection = this.getConnection();\n if (!connection) {\n throw new Error(\"database connection not established\");\n }\n return this.getModel(connection, modelName, schema, collectionName);\n }\n\n protected model<T>(model: Model<T>, collectionName?: string): Model<T> {\n return this.getTenantModel(\n model.modelName,\n model.schema,\n collectionName,\n ) as Model<T>;\n }\n\n protected getModel(\n connection: mongoose.Mongoose,\n modelName: string,\n schema: Schema<any>,\n collectionName?: string,\n ): Model<any> {\n if (connection.models[modelName]) {\n return connection.models[modelName] as Model<any>;\n }\n return connection.model(modelName, schema, collectionName);\n }\n}\n\nexport abstract class TenantModelRepository<T> extends MultiTenantRepository {\n protected abstract readonly modelDef: Model<T>;\n\n protected get dbModel():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AAC6E,KAAK,CAACF,SAAS,EAAEf,MAAM,EAAEgB,cAAc,CAAC;EAC5D;AACF,CAAC,EAAAlK,sBAAA,CAvUgBqF,WAAW,GAAkB,IAAIgF,GAAG,CAAC,CAAC,EAAArK,sBAAA,GAAAoB,yBAAA,CAAArB,MAAA,CAAAuK,SAAA,2CAAA1K,IAAA,GAAAqB,MAAA,CAAAE,wBAAA,CAAApB,MAAA,CAAAuK,SAAA,2CAAAvK,MAAA,CAAAuK,SAAA,GAAAlJ,yBAAA,CAAArB,MAAA,CAAAuK,SAAA,mCAAAzK,KAAA,GAAAoB,MAAA,CAAAE,wBAAA,CAAApB,MAAA,CAAAuK,SAAA,mCAAAvK,MAAA,CAAAuK,SAAA,GAAAlJ,yBAAA,CAAArB,MAAA,CAAAuK,SAAA,kCAAAxK,KAAA,GAAAmB,MAAA,CAAAE,wBAAA,CAAApB,MAAA,CAAAuK,SAAA,kCAAAvK,MAAA,CAAAuK,SAAA,GAAAvK,MAAA;AAyUhD,MAAewK,qBAAqB,SAAY1H,qBAAqB,CAAC;EAAAW,YAAA,GAAAd,IAAA;IAAA,SAAAA,IAAA;IAAA,KAC/C8H,QAAQ;EAAA;EAEpC,IAAcC,OAAOA,CAAA,EAAa;IAChC,OAAO,IAAI,CAACN,KAAK,CAAC,IAAI,CAACK,QAAQ,CAAC;EAClC;AACF;AAAC1H,OAAA,CAAAyH,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.TenantBaseRepository = void 0;
|
|
5
|
+
var _multiTenant = require("./multi-tenant.repository");
|
|
6
|
+
var _class;
|
|
7
|
+
function _applyDecoratedDescriptor(i, e, r, n, l) { var a = {}; return Object.keys(n).forEach(function (i) { a[i] = n[i]; }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function (r, n) { return n(i, e, r) || r; }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a; }
|
|
8
|
+
let TenantBaseRepository = exports.TenantBaseRepository = (_class = class TenantBaseRepository extends _multiTenant.TenantModelRepository {
|
|
9
|
+
constructor(...args) {
|
|
10
|
+
super(...args);
|
|
11
|
+
this.modelDef = void 0;
|
|
12
|
+
}
|
|
13
|
+
async aggregate(pipeline) {
|
|
14
|
+
return this.dbModel.aggregate(pipeline).exec();
|
|
15
|
+
}
|
|
16
|
+
async create(body) {
|
|
17
|
+
return this.dbModel.create(body);
|
|
18
|
+
}
|
|
19
|
+
async createMany(body) {
|
|
20
|
+
return this.dbModel.insertMany(body);
|
|
21
|
+
}
|
|
22
|
+
async count(query = {}) {
|
|
23
|
+
return this.dbModel.countDocuments(query).exec();
|
|
24
|
+
}
|
|
25
|
+
async findById(id, projection = {}, options = {}) {
|
|
26
|
+
return this.dbModel.findById(id, projection, options).exec();
|
|
27
|
+
}
|
|
28
|
+
async findOne(query, projection = {}, options = {}) {
|
|
29
|
+
return this.dbModel.findOne(query, projection, options).exec();
|
|
30
|
+
}
|
|
31
|
+
async find(query = {}, projection = {}, options = {}) {
|
|
32
|
+
return this.dbModel.find(query, projection, options).exec();
|
|
33
|
+
}
|
|
34
|
+
async updateById(id, body, options = {
|
|
35
|
+
new: true
|
|
36
|
+
}) {
|
|
37
|
+
return this.dbModel.findByIdAndUpdate(id, body, options).exec();
|
|
38
|
+
}
|
|
39
|
+
async updateOne(query, body, options = {}) {
|
|
40
|
+
return this.dbModel.updateOne(query, body, options).exec();
|
|
41
|
+
}
|
|
42
|
+
async updateMany(query, body, options = {}) {
|
|
43
|
+
return this.dbModel.updateMany(query, body, options).exec();
|
|
44
|
+
}
|
|
45
|
+
async deleteById(id) {
|
|
46
|
+
return this.dbModel.findByIdAndDelete(id).exec();
|
|
47
|
+
}
|
|
48
|
+
async deleteMany(query = {}) {
|
|
49
|
+
return this.dbModel.deleteMany(query).exec();
|
|
50
|
+
}
|
|
51
|
+
}, _applyDecoratedDescriptor(_class.prototype, "aggregate", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "aggregate"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "create", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "create"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "createMany", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "createMany"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "count", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "count"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "findById", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "findById"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "findOne", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "findOne"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "find", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "find"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "updateById", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "updateById"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "updateOne", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "updateOne"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "updateMany", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "updateMany"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "deleteById", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "deleteById"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "deleteMany", [_multiTenant.WithTenantDb], Object.getOwnPropertyDescriptor(_class.prototype, "deleteMany"), _class.prototype), _class);
|
|
52
|
+
//# sourceMappingURL=tenant-base.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-base.repository.js","names":["_multiTenant","require","_class","_applyDecoratedDescriptor","i","e","r","n","l","a","Object","keys","forEach","enumerable","configurable","initializer","writable","slice","reverse","reduce","value","call","defineProperty","TenantBaseRepository","exports","TenantModelRepository","constructor","args","modelDef","aggregate","pipeline","dbModel","exec","create","body","createMany","insertMany","count","query","countDocuments","findById","id","projection","options","findOne","find","updateById","new","findByIdAndUpdate","updateOne","updateMany","deleteById","findByIdAndDelete","deleteMany","prototype","WithTenantDb","getOwnPropertyDescriptor"],"sources":["../../../src/repositories/tenant-base.repository.ts"],"sourcesContent":["import {\n FilterQuery,\n Model,\n PipelineStage,\n ProjectionType,\n QueryOptions,\n UpdateQuery,\n} from \"mongoose\";\nimport { TenantModelRepository, WithTenantDb } from \"./multi-tenant.repository\";\n\nexport abstract class TenantBaseRepository<T> extends TenantModelRepository<T> {\n protected abstract readonly modelDef: Model<T>;\n\n @WithTenantDb\n async aggregate(\n pipeline: PipelineStage[],\n ): Promise<any[]> {\n return this.dbModel.aggregate(pipeline).exec();\n }\n\n @WithTenantDb\n async create(body: T): Promise<T> {\n return this.dbModel.create(body);\n }\n\n @WithTenantDb\n async createMany(body: T[]): Promise<T[]> {\n return this.dbModel.insertMany(body);\n }\n\n @WithTenantDb\n async count(query: FilterQuery<T> = {}): Promise<number> {\n return this.dbModel.countDocuments(query).exec();\n }\n\n @WithTenantDb\n async findById(\n id: string,\n projection: ProjectionType<T> = {},\n options: QueryOptions<T> = {},\n ): Promise<T | null> {\n return this.dbModel.findById(id, projection, options).exec();\n }\n\n @WithTenantDb\n async findOne(\n query: FilterQuery<T>,\n projection: ProjectionType<T> = {},\n options: QueryOptions<T> = {},\n ): Promise<T | null> {\n return this.dbModel.findOne(query, projection, options).exec();\n }\n\n @WithTenantDb\n async find(\n query: FilterQuery<T> = {},\n projection: ProjectionType<T> = {},\n options: QueryOptions<T> = {},\n ): Promise<T[]> {\n return this.dbModel.find(query, projection, options).exec();\n }\n\n @WithTenantDb\n async updateById(\n id: string,\n body: UpdateQuery<T>,\n options: any = { new: true },\n ): Promise<T | null> {\n return this.dbModel.findByIdAndUpdate(id, body, options).exec() as Promise<\n T | null\n >;\n }\n\n @WithTenantDb\n async updateOne(\n query: FilterQuery<T>,\n body: UpdateQuery<T>,\n options: any = {},\n ): Promise<any> {\n return this.dbModel.updateOne(query, body, options).exec();\n }\n\n @WithTenantDb\n async updateMany(\n query: FilterQuery<T>,\n body: UpdateQuery<T>,\n options: any = {},\n ): Promise<any> {\n return this.dbModel.updateMany(query, body, options).exec();\n }\n\n @WithTenantDb\n async deleteById(id: string): Promise<T | null> {\n return this.dbModel.findByIdAndDelete(id).exec();\n }\n\n @WithTenantDb\n async deleteMany(query: FilterQuery<T> = {}): Promise<any> {\n return this.dbModel.deleteMany(query).exec();\n }\n}\n"],"mappings":";;;;AAQA,IAAAA,YAAA,GAAAC,OAAA;AAAgF,IAAAC,MAAA;AAAA,SAAAC,0BAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,cAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,EAAAK,OAAA,WAAAR,CAAA,IAAAK,CAAA,CAAAL,CAAA,IAAAG,CAAA,CAAAH,CAAA,OAAAK,CAAA,CAAAI,UAAA,KAAAJ,CAAA,CAAAI,UAAA,EAAAJ,CAAA,CAAAK,YAAA,KAAAL,CAAA,CAAAK,YAAA,cAAAL,CAAA,IAAAA,CAAA,CAAAM,WAAA,MAAAN,CAAA,CAAAO,QAAA,QAAAP,CAAA,GAAAH,CAAA,CAAAW,KAAA,GAAAC,OAAA,GAAAC,MAAA,WAAAb,CAAA,EAAAC,CAAA,WAAAA,CAAA,CAAAH,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAA,CAAA,KAAAG,CAAA,GAAAD,CAAA,eAAAC,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A,GAAAnD,yBAAA,CAAAD,MAAA,CAAAoD,SAAA,gBAWZC,yBAAY,GAAA7C,MAAA,CAAA8C,wBAAA,CAAAtD,MAAA,CAAAoD,SAAA,gBAAApD,MAAA,CAAAoD,SAAA,GAAAnD,yBAAA,CAAAD,MAAA,CAAAoD,SAAA,iBASZC,yBAAY,GAAA7C,MAAA,CAAA8C,wBAAA,CAAAtD,MAAA,CAAAoD,SAAA,iBAAApD,MAAA,CAAAoD,SAAA,GAAAnD,yBAAA,CAAAD,MAAA,CAAAoD,SAAA,iBASZC,yBAAY,GAAA7C,MAAA,CAAA8C,wBAAA,CAAAtD,MAAA,CAAAoD,SAAA,iBAAApD,MAAA,CAAAoD,SAAA,GAAAnD,yBAAA,CAAAD,MAAA,CAAAoD,SAAA,iBAKZC,yBAAY,GAAA7C,MAAA,CAAA8C,wBAAA,CAAAtD,MAAA,CAAAoD,SAAA,iBAAApD,MAAA,CAAAoD,SAAA,GAAApD,MAAA","ignoreList":[]}
|
package/build/esm/index.js
CHANGED
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from './types';\nexport * from './enums';\nexport * from './utils';\nexport * from './utils/cache';\nexport * from './middlewares';\nexport * from './constants';\n"],"mappings":"AAAA,cAAc,SAAS;AACvB,cAAc,SAAS;AACvB,cAAc,SAAS;AACvB,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from './types';\nexport * from './enums';\nexport * from './utils';\nexport * from './utils/cache';\nexport * from './middlewares';\nexport * from './constants';\nexport * from './repositories';\n"],"mappings":"AAAA,cAAc,SAAS;AACvB,cAAc,SAAS;AACvB,cAAc,SAAS;AACvB,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,aAAa;AAC3B,cAAc,gBAAgB","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import mongoose, { model, Schema } from 'mongoose';
|
|
2
|
+
export const CONFIG_MAPPING_DOCUMENT_NAME = 'ConfigMapping';
|
|
3
|
+
export const CONFIG_MAPPING_COLLECTION_NAME = 'configMappings';
|
|
4
|
+
const schema = new Schema({
|
|
5
|
+
_id: {
|
|
6
|
+
type: Schema.Types.ObjectId,
|
|
7
|
+
required: true,
|
|
8
|
+
unique: true,
|
|
9
|
+
auto: true
|
|
10
|
+
},
|
|
11
|
+
businessId: {
|
|
12
|
+
type: Schema.Types.ObjectId,
|
|
13
|
+
required: true
|
|
14
|
+
},
|
|
15
|
+
connectionString: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: true
|
|
18
|
+
},
|
|
19
|
+
domain: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: false
|
|
22
|
+
},
|
|
23
|
+
appId: {
|
|
24
|
+
type: String,
|
|
25
|
+
required: false
|
|
26
|
+
},
|
|
27
|
+
serviceDBType: {
|
|
28
|
+
type: String,
|
|
29
|
+
required: false
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
timestamps: true,
|
|
33
|
+
collection: CONFIG_MAPPING_COLLECTION_NAME
|
|
34
|
+
});
|
|
35
|
+
export const ConfigMappingModel = mongoose.models.ConfigMapping || model(CONFIG_MAPPING_DOCUMENT_NAME, schema);
|
|
36
|
+
//# sourceMappingURL=config-mapping.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-mapping.model.js","names":["mongoose","model","Schema","CONFIG_MAPPING_DOCUMENT_NAME","CONFIG_MAPPING_COLLECTION_NAME","schema","_id","type","Types","ObjectId","required","unique","auto","businessId","connectionString","String","domain","appId","serviceDBType","timestamps","collection","ConfigMappingModel","models","ConfigMapping"],"sources":["../../../src/models/config-mapping.model.ts"],"sourcesContent":["import mongoose, { model, Schema } from 'mongoose';\n\nexport const CONFIG_MAPPING_DOCUMENT_NAME = 'ConfigMapping';\nexport const CONFIG_MAPPING_COLLECTION_NAME = 'configMappings';\n\nexport type ServiceDbType = 'main' | 'chatDB';\n\nexport interface IConfigMapping {\n _id?: Schema.Types.ObjectId;\n businessId: Schema.Types.ObjectId;\n connectionString: string;\n domain?: string;\n appId?: string;\n serviceDBType?: ServiceDbType;\n}\n\nexport interface ICreateConfigMapping {\n businessId: string;\n connectionString: string;\n domain?: string;\n appId?: string;\n serviceDBType?: ServiceDbType;\n}\n\nconst schema = new Schema<IConfigMapping>(\n {\n _id: {\n type: Schema.Types.ObjectId,\n required: true,\n unique: true,\n auto: true,\n },\n businessId: {\n type: Schema.Types.ObjectId,\n required: true,\n },\n connectionString: {\n type: String,\n required: true,\n },\n domain: {\n type: String,\n required: false,\n },\n appId: {\n type: String,\n required: false,\n },\n serviceDBType: {\n type: String,\n required: false,\n },\n },\n {\n timestamps: true,\n collection: CONFIG_MAPPING_COLLECTION_NAME,\n },\n);\n\nexport const ConfigMappingModel =\n mongoose.models.ConfigMapping ||\n model<IConfigMapping>(CONFIG_MAPPING_DOCUMENT_NAME, schema);\n"],"mappings":"AAAA,OAAOA,QAAQ,IAAIC,KAAK,EAAEC,MAAM,QAAQ,UAAU;AAElD,OAAO,MAAMC,4BAA4B,GAAG,eAAe;AAC3D,OAAO,MAAMC,8BAA8B,GAAG,gBAAgB;AAqB9D,MAAMC,MAAM,GAAG,IAAIH,MAAM,CACvB;EACEI,GAAG,EAAE;IACHC,IAAI,EAAEL,MAAM,CAACM,KAAK,CAACC,QAAQ;IAC3BC,QAAQ,EAAE,IAAI;IACdC,MAAM,EAAE,IAAI;IACZC,IAAI,EAAE;EACR,CAAC;EACDC,UAAU,EAAE;IACVN,IAAI,EAAEL,MAAM,CAACM,KAAK,CAACC,QAAQ;IAC3BC,QAAQ,EAAE;EACZ,CAAC;EACDI,gBAAgB,EAAE;IAChBP,IAAI,EAAEQ,MAAM;IACZL,QAAQ,EAAE;EACZ,CAAC;EACDM,MAAM,EAAE;IACNT,IAAI,EAAEQ,MAAM;IACZL,QAAQ,EAAE;EACZ,CAAC;EACDO,KAAK,EAAE;IACLV,IAAI,EAAEQ,MAAM;IACZL,QAAQ,EAAE;EACZ,CAAC;EACDQ,aAAa,EAAE;IACbX,IAAI,EAAEQ,MAAM;IACZL,QAAQ,EAAE;EACZ;AACF,CAAC,EACD;EACES,UAAU,EAAE,IAAI;EAChBC,UAAU,EAAEhB;AACd,CACF,CAAC;AAED,OAAO,MAAMiB,kBAAkB,GAC7BrB,QAAQ,CAACsB,MAAM,CAACC,aAAa,IAC7BtB,KAAK,CAAiBE,4BAA4B,EAAEE,MAAM,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/repositories/index.ts"],"sourcesContent":["export * from \"./multi-tenant.repository\";\nexport * from \"./tenant-base.repository\";\n"],"mappings":"AAAA,cAAc,2BAA2B;AACzC,cAAc,0BAA0B","ignoreList":[]}
|