@credo-ts/tenants 0.4.1-alpha.157
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/LICENSE +202 -0
- package/README.md +31 -0
- package/build/TenantAgent.d.ts +8 -0
- package/build/TenantAgent.js +25 -0
- package/build/TenantAgent.js.map +1 -0
- package/build/TenantsApi.d.ts +25 -0
- package/build/TenantsApi.js +116 -0
- package/build/TenantsApi.js.map +1 -0
- package/build/TenantsApiOptions.d.ts +14 -0
- package/build/TenantsApiOptions.js +3 -0
- package/build/TenantsApiOptions.js.map +1 -0
- package/build/TenantsModule.d.ts +19 -0
- package/build/TenantsModule.js +47 -0
- package/build/TenantsModule.js.map +1 -0
- package/build/TenantsModuleConfig.d.ts +31 -0
- package/build/TenantsModuleConfig.js +20 -0
- package/build/TenantsModuleConfig.js.map +1 -0
- package/build/context/TenantAgentContextProvider.d.ts +40 -0
- package/build/context/TenantAgentContextProvider.js +173 -0
- package/build/context/TenantAgentContextProvider.js.map +1 -0
- package/build/context/TenantSessionCoordinator.d.ts +53 -0
- package/build/context/TenantSessionCoordinator.js +179 -0
- package/build/context/TenantSessionCoordinator.js.map +1 -0
- package/build/context/TenantSessionMutex.d.ts +29 -0
- package/build/context/TenantSessionMutex.js +84 -0
- package/build/context/TenantSessionMutex.js.map +1 -0
- package/build/context/types.d.ts +0 -0
- package/build/context/types.js +2 -0
- package/build/context/types.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +24 -0
- package/build/index.js.map +1 -0
- package/build/models/TenantConfig.d.ts +4 -0
- package/build/models/TenantConfig.js +3 -0
- package/build/models/TenantConfig.js.map +1 -0
- package/build/repository/TenantRecord.d.ts +33 -0
- package/build/repository/TenantRecord.js +32 -0
- package/build/repository/TenantRecord.js.map +1 -0
- package/build/repository/TenantRepository.d.ts +7 -0
- package/build/repository/TenantRepository.js +32 -0
- package/build/repository/TenantRepository.js.map +1 -0
- package/build/repository/TenantRoutingRecord.d.ts +26 -0
- package/build/repository/TenantRoutingRecord.js +24 -0
- package/build/repository/TenantRoutingRecord.js.map +1 -0
- package/build/repository/TenantRoutingRepository.d.ts +7 -0
- package/build/repository/TenantRoutingRepository.js +34 -0
- package/build/repository/TenantRoutingRepository.js.map +1 -0
- package/build/repository/index.d.ts +4 -0
- package/build/repository/index.js +21 -0
- package/build/repository/index.js.map +1 -0
- package/build/services/TenantRecordService.d.ts +17 -0
- package/build/services/TenantRecordService.js +78 -0
- package/build/services/TenantRecordService.js.map +1 -0
- package/build/services/index.d.ts +1 -0
- package/build/services/index.js +18 -0
- package/build/services/index.js.map +1 -0
- package/build/updates/0.4-0.5/index.d.ts +2 -0
- package/build/updates/0.4-0.5/index.js +9 -0
- package/build/updates/0.4-0.5/index.js.map +1 -0
- package/build/updates/0.4-0.5/tenantRecord.d.ts +10 -0
- package/build/updates/0.4-0.5/tenantRecord.js +27 -0
- package/build/updates/0.4-0.5/tenantRecord.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TenantConfig } from '../models/TenantConfig';
|
|
2
|
+
import type { RecordTags, TagsBase, VersionString } from '@credo-ts/core';
|
|
3
|
+
import { BaseRecord } from '@credo-ts/core';
|
|
4
|
+
export type TenantRecordTags = RecordTags<TenantRecord>;
|
|
5
|
+
export interface TenantRecordProps {
|
|
6
|
+
id?: string;
|
|
7
|
+
createdAt?: Date;
|
|
8
|
+
config: TenantConfig;
|
|
9
|
+
tags?: TagsBase;
|
|
10
|
+
storageVersion: VersionString;
|
|
11
|
+
}
|
|
12
|
+
export type DefaultTenantRecordTags = {
|
|
13
|
+
label: string;
|
|
14
|
+
storageVersion: VersionString;
|
|
15
|
+
};
|
|
16
|
+
export declare class TenantRecord extends BaseRecord<DefaultTenantRecordTags> {
|
|
17
|
+
static readonly type = "TenantRecord";
|
|
18
|
+
readonly type = "TenantRecord";
|
|
19
|
+
config: TenantConfig;
|
|
20
|
+
/**
|
|
21
|
+
* The storage version that is used by this tenant. Can be used to know if the tenant is ready to be used
|
|
22
|
+
* with the current version of the application.
|
|
23
|
+
*
|
|
24
|
+
* @default 0.4 from 0.5 onwards we set the storage version on creation, so if no value
|
|
25
|
+
* is stored, it means the storage version is 0.4 (when multi-tenancy was introduced)
|
|
26
|
+
*/
|
|
27
|
+
storageVersion: VersionString;
|
|
28
|
+
constructor(props: TenantRecordProps);
|
|
29
|
+
getTags(): {
|
|
30
|
+
label: string;
|
|
31
|
+
storageVersion: VersionString;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TenantRecord = void 0;
|
|
4
|
+
const core_1 = require("@credo-ts/core");
|
|
5
|
+
class TenantRecord extends core_1.BaseRecord {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
super();
|
|
9
|
+
this.type = TenantRecord.type;
|
|
10
|
+
/**
|
|
11
|
+
* The storage version that is used by this tenant. Can be used to know if the tenant is ready to be used
|
|
12
|
+
* with the current version of the application.
|
|
13
|
+
*
|
|
14
|
+
* @default 0.4 from 0.5 onwards we set the storage version on creation, so if no value
|
|
15
|
+
* is stored, it means the storage version is 0.4 (when multi-tenancy was introduced)
|
|
16
|
+
*/
|
|
17
|
+
this.storageVersion = '0.4';
|
|
18
|
+
if (props) {
|
|
19
|
+
this.id = (_a = props.id) !== null && _a !== void 0 ? _a : core_1.utils.uuid();
|
|
20
|
+
this.createdAt = (_b = props.createdAt) !== null && _b !== void 0 ? _b : new Date();
|
|
21
|
+
this._tags = (_c = props.tags) !== null && _c !== void 0 ? _c : {};
|
|
22
|
+
this.config = props.config;
|
|
23
|
+
this.storageVersion = props.storageVersion;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
getTags() {
|
|
27
|
+
return Object.assign(Object.assign({}, this._tags), { label: this.config.label, storageVersion: this.storageVersion });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.TenantRecord = TenantRecord;
|
|
31
|
+
TenantRecord.type = 'TenantRecord';
|
|
32
|
+
//# sourceMappingURL=TenantRecord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantRecord.js","sourceRoot":"","sources":["../../src/repository/TenantRecord.ts"],"names":[],"mappings":";;;AAGA,yCAAkD;AAiBlD,MAAa,YAAa,SAAQ,iBAAmC;IAenE,YAAmB,KAAwB;;QACzC,KAAK,EAAE,CAAA;QAdO,SAAI,GAAG,YAAY,CAAC,IAAI,CAAA;QAIxC;;;;;;WAMG;QACI,mBAAc,GAAkB,KAAK,CAAA;QAK1C,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,EAAE,GAAG,MAAA,KAAK,CAAC,EAAE,mCAAI,YAAK,CAAC,IAAI,EAAE,CAAA;YAClC,IAAI,CAAC,SAAS,GAAG,MAAA,KAAK,CAAC,SAAS,mCAAI,IAAI,IAAI,EAAE,CAAA;YAC9C,IAAI,CAAC,KAAK,GAAG,MAAA,KAAK,CAAC,IAAI,mCAAI,EAAE,CAAA;YAC7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;YAC1B,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;SAC3C;IACH,CAAC;IAEM,OAAO;QACZ,uCACK,IAAI,CAAC,KAAK,KACb,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EACxB,cAAc,EAAE,IAAI,CAAC,cAAc,IACpC;IACH,CAAC;;AAjCH,oCAkCC;AAjCwB,iBAAI,GAAG,cAAc,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentContext } from '@credo-ts/core';
|
|
2
|
+
import { Repository, StorageService, EventEmitter } from '@credo-ts/core';
|
|
3
|
+
import { TenantRecord } from './TenantRecord';
|
|
4
|
+
export declare class TenantRepository extends Repository<TenantRecord> {
|
|
5
|
+
constructor(storageService: StorageService<TenantRecord>, eventEmitter: EventEmitter);
|
|
6
|
+
findByLabel(agentContext: AgentContext, label: string): Promise<TenantRecord[]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TenantRepository = void 0;
|
|
16
|
+
const core_1 = require("@credo-ts/core");
|
|
17
|
+
const TenantRecord_1 = require("./TenantRecord");
|
|
18
|
+
let TenantRepository = class TenantRepository extends core_1.Repository {
|
|
19
|
+
constructor(storageService, eventEmitter) {
|
|
20
|
+
super(TenantRecord_1.TenantRecord, storageService, eventEmitter);
|
|
21
|
+
}
|
|
22
|
+
async findByLabel(agentContext, label) {
|
|
23
|
+
return this.findByQuery(agentContext, { label });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
TenantRepository = __decorate([
|
|
27
|
+
(0, core_1.injectable)(),
|
|
28
|
+
__param(0, (0, core_1.inject)(core_1.InjectionSymbols.StorageService)),
|
|
29
|
+
__metadata("design:paramtypes", [Object, core_1.EventEmitter])
|
|
30
|
+
], TenantRepository);
|
|
31
|
+
exports.TenantRepository = TenantRepository;
|
|
32
|
+
//# sourceMappingURL=TenantRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantRepository.js","sourceRoot":"","sources":["../../src/repository/TenantRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yCAA+G;AAE/G,iDAA6C;AAGtC,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,iBAAwB;IAC5D,YAC2C,cAA4C,EACrF,YAA0B;QAE1B,KAAK,CAAC,2BAAY,EAAE,cAAc,EAAE,YAAY,CAAC,CAAA;IACnD,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,YAA0B,EAAE,KAAa;QAChE,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAClD,CAAC;CACF,CAAA;AAXY,gBAAgB;IAD5B,IAAA,iBAAU,GAAE;IAGR,WAAA,IAAA,aAAM,EAAC,uBAAgB,CAAC,cAAc,CAAC,CAAA;6CAC1B,mBAAY;GAHjB,gBAAgB,CAW5B;AAXY,4CAAgB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RecordTags, TagsBase } from '@credo-ts/core';
|
|
2
|
+
import { BaseRecord } from '@credo-ts/core';
|
|
3
|
+
export type TenantRoutingRecordTags = RecordTags<TenantRoutingRecord>;
|
|
4
|
+
type DefaultTenantRoutingRecordTags = {
|
|
5
|
+
tenantId: string;
|
|
6
|
+
recipientKeyFingerprint: string;
|
|
7
|
+
};
|
|
8
|
+
export interface TenantRoutingRecordProps {
|
|
9
|
+
id?: string;
|
|
10
|
+
createdAt?: Date;
|
|
11
|
+
tags?: TagsBase;
|
|
12
|
+
tenantId: string;
|
|
13
|
+
recipientKeyFingerprint: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class TenantRoutingRecord extends BaseRecord<DefaultTenantRoutingRecordTags> {
|
|
16
|
+
static readonly type = "TenantRoutingRecord";
|
|
17
|
+
readonly type = "TenantRoutingRecord";
|
|
18
|
+
tenantId: string;
|
|
19
|
+
recipientKeyFingerprint: string;
|
|
20
|
+
constructor(props: TenantRoutingRecordProps);
|
|
21
|
+
getTags(): {
|
|
22
|
+
tenantId: string;
|
|
23
|
+
recipientKeyFingerprint: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TenantRoutingRecord = void 0;
|
|
4
|
+
const core_1 = require("@credo-ts/core");
|
|
5
|
+
class TenantRoutingRecord extends core_1.BaseRecord {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
super();
|
|
9
|
+
this.type = TenantRoutingRecord.type;
|
|
10
|
+
if (props) {
|
|
11
|
+
this.id = (_a = props.id) !== null && _a !== void 0 ? _a : core_1.utils.uuid();
|
|
12
|
+
this.createdAt = (_b = props.createdAt) !== null && _b !== void 0 ? _b : new Date();
|
|
13
|
+
this._tags = (_c = props.tags) !== null && _c !== void 0 ? _c : {};
|
|
14
|
+
this.tenantId = props.tenantId;
|
|
15
|
+
this.recipientKeyFingerprint = props.recipientKeyFingerprint;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
getTags() {
|
|
19
|
+
return Object.assign(Object.assign({}, this._tags), { tenantId: this.tenantId, recipientKeyFingerprint: this.recipientKeyFingerprint });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.TenantRoutingRecord = TenantRoutingRecord;
|
|
23
|
+
TenantRoutingRecord.type = 'TenantRoutingRecord';
|
|
24
|
+
//# sourceMappingURL=TenantRoutingRecord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantRoutingRecord.js","sourceRoot":"","sources":["../../src/repository/TenantRoutingRecord.ts"],"names":[],"mappings":";;;AAEA,yCAAkD;AAkBlD,MAAa,mBAAoB,SAAQ,iBAA0C;IAOjF,YAAmB,KAA+B;;QAChD,KAAK,EAAE,CAAA;QANO,SAAI,GAAG,mBAAmB,CAAC,IAAI,CAAA;QAQ7C,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,EAAE,GAAG,MAAA,KAAK,CAAC,EAAE,mCAAI,YAAK,CAAC,IAAI,EAAE,CAAA;YAClC,IAAI,CAAC,SAAS,GAAG,MAAA,KAAK,CAAC,SAAS,mCAAI,IAAI,IAAI,EAAE,CAAA;YAC9C,IAAI,CAAC,KAAK,GAAG,MAAA,KAAK,CAAC,IAAI,mCAAI,EAAE,CAAA;YAC7B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;YAC9B,IAAI,CAAC,uBAAuB,GAAG,KAAK,CAAC,uBAAuB,CAAA;SAC7D;IACH,CAAC;IAEM,OAAO;QACZ,uCACK,IAAI,CAAC,KAAK,KACb,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,uBAAuB,EAAE,IAAI,CAAC,uBAAuB,IACtD;IACH,CAAC;;AAzBH,kDA0BC;AAzBwB,wBAAI,GAAG,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentContext, Key } from '@credo-ts/core';
|
|
2
|
+
import { Repository, StorageService, EventEmitter } from '@credo-ts/core';
|
|
3
|
+
import { TenantRoutingRecord } from './TenantRoutingRecord';
|
|
4
|
+
export declare class TenantRoutingRepository extends Repository<TenantRoutingRecord> {
|
|
5
|
+
constructor(storageService: StorageService<TenantRoutingRecord>, eventEmitter: EventEmitter);
|
|
6
|
+
findByRecipientKey(agentContext: AgentContext, key: Key): Promise<TenantRoutingRecord | null>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TenantRoutingRepository = void 0;
|
|
16
|
+
const core_1 = require("@credo-ts/core");
|
|
17
|
+
const TenantRoutingRecord_1 = require("./TenantRoutingRecord");
|
|
18
|
+
let TenantRoutingRepository = class TenantRoutingRepository extends core_1.Repository {
|
|
19
|
+
constructor(storageService, eventEmitter) {
|
|
20
|
+
super(TenantRoutingRecord_1.TenantRoutingRecord, storageService, eventEmitter);
|
|
21
|
+
}
|
|
22
|
+
findByRecipientKey(agentContext, key) {
|
|
23
|
+
return this.findSingleByQuery(agentContext, {
|
|
24
|
+
recipientKeyFingerprint: key.fingerprint,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
TenantRoutingRepository = __decorate([
|
|
29
|
+
(0, core_1.injectable)(),
|
|
30
|
+
__param(0, (0, core_1.inject)(core_1.InjectionSymbols.StorageService)),
|
|
31
|
+
__metadata("design:paramtypes", [Object, core_1.EventEmitter])
|
|
32
|
+
], TenantRoutingRepository);
|
|
33
|
+
exports.TenantRoutingRepository = TenantRoutingRepository;
|
|
34
|
+
//# sourceMappingURL=TenantRoutingRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantRoutingRepository.js","sourceRoot":"","sources":["../../src/repository/TenantRoutingRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yCAA+G;AAE/G,+DAA2D;AAGpD,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,iBAA+B;IAC1E,YAC2C,cAAmD,EAC5F,YAA0B;QAE1B,KAAK,CAAC,yCAAmB,EAAE,cAAc,EAAE,YAAY,CAAC,CAAA;IAC1D,CAAC;IAEM,kBAAkB,CAAC,YAA0B,EAAE,GAAQ;QAC5D,OAAO,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE;YAC1C,uBAAuB,EAAE,GAAG,CAAC,WAAW;SACzC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAbY,uBAAuB;IADnC,IAAA,iBAAU,GAAE;IAGR,WAAA,IAAA,aAAM,EAAC,uBAAgB,CAAC,cAAc,CAAC,CAAA;6CAC1B,mBAAY;GAHjB,uBAAuB,CAanC;AAbY,0DAAuB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TenantRecord"), exports);
|
|
18
|
+
__exportStar(require("./TenantRepository"), exports);
|
|
19
|
+
__exportStar(require("./TenantRoutingRecord"), exports);
|
|
20
|
+
__exportStar(require("./TenantRoutingRepository"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/repository/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,qDAAkC;AAClC,wDAAqC;AACrC,4DAAyC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TenantConfig } from '../models/TenantConfig';
|
|
2
|
+
import type { AgentContext, Key, Query } from '@credo-ts/core';
|
|
3
|
+
import { TenantRepository, TenantRecord, TenantRoutingRepository, TenantRoutingRecord } from '../repository';
|
|
4
|
+
export declare class TenantRecordService {
|
|
5
|
+
private tenantRepository;
|
|
6
|
+
private tenantRoutingRepository;
|
|
7
|
+
constructor(tenantRepository: TenantRepository, tenantRoutingRepository: TenantRoutingRepository);
|
|
8
|
+
createTenant(agentContext: AgentContext, config: Omit<TenantConfig, 'walletConfig'>): Promise<TenantRecord>;
|
|
9
|
+
getTenantById(agentContext: AgentContext, tenantId: string): Promise<TenantRecord>;
|
|
10
|
+
findTenantsByLabel(agentContext: AgentContext, label: string): Promise<TenantRecord[]>;
|
|
11
|
+
getAllTenants(agentContext: AgentContext): Promise<TenantRecord[]>;
|
|
12
|
+
deleteTenantById(agentContext: AgentContext, tenantId: string): Promise<void>;
|
|
13
|
+
updateTenant(agentContext: AgentContext, tenantRecord: TenantRecord): Promise<void>;
|
|
14
|
+
findTenantsByQuery(agentContext: AgentContext, query: Query<TenantRecord>): Promise<TenantRecord[]>;
|
|
15
|
+
findTenantRoutingRecordByRecipientKey(agentContext: AgentContext, recipientKey: Key): Promise<TenantRoutingRecord | null>;
|
|
16
|
+
addTenantRoutingRecord(agentContext: AgentContext, tenantId: string, recipientKey: Key): Promise<TenantRoutingRecord>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TenantRecordService = void 0;
|
|
13
|
+
const core_1 = require("@credo-ts/core");
|
|
14
|
+
const repository_1 = require("../repository");
|
|
15
|
+
let TenantRecordService = class TenantRecordService {
|
|
16
|
+
constructor(tenantRepository, tenantRoutingRepository) {
|
|
17
|
+
this.tenantRepository = tenantRepository;
|
|
18
|
+
this.tenantRoutingRepository = tenantRoutingRepository;
|
|
19
|
+
}
|
|
20
|
+
async createTenant(agentContext, config) {
|
|
21
|
+
const tenantId = core_1.utils.uuid();
|
|
22
|
+
const walletId = `tenant-${tenantId}`;
|
|
23
|
+
const walletKey = await agentContext.wallet.generateWalletKey();
|
|
24
|
+
const tenantRecord = new repository_1.TenantRecord({
|
|
25
|
+
id: tenantId,
|
|
26
|
+
config: Object.assign(Object.assign({}, config), { walletConfig: {
|
|
27
|
+
id: walletId,
|
|
28
|
+
key: walletKey,
|
|
29
|
+
keyDerivationMethod: core_1.KeyDerivationMethod.Raw,
|
|
30
|
+
} }),
|
|
31
|
+
storageVersion: core_1.UpdateAssistant.frameworkStorageVersion,
|
|
32
|
+
});
|
|
33
|
+
await this.tenantRepository.save(agentContext, tenantRecord);
|
|
34
|
+
return tenantRecord;
|
|
35
|
+
}
|
|
36
|
+
async getTenantById(agentContext, tenantId) {
|
|
37
|
+
return this.tenantRepository.getById(agentContext, tenantId);
|
|
38
|
+
}
|
|
39
|
+
async findTenantsByLabel(agentContext, label) {
|
|
40
|
+
return this.tenantRepository.findByLabel(agentContext, label);
|
|
41
|
+
}
|
|
42
|
+
async getAllTenants(agentContext) {
|
|
43
|
+
return this.tenantRepository.getAll(agentContext);
|
|
44
|
+
}
|
|
45
|
+
async deleteTenantById(agentContext, tenantId) {
|
|
46
|
+
const tenantRecord = await this.getTenantById(agentContext, tenantId);
|
|
47
|
+
const tenantRoutingRecords = await this.tenantRoutingRepository.findByQuery(agentContext, {
|
|
48
|
+
tenantId: tenantRecord.id,
|
|
49
|
+
});
|
|
50
|
+
// Delete all tenant routing records
|
|
51
|
+
await Promise.all(tenantRoutingRecords.map((tenantRoutingRecord) => this.tenantRoutingRepository.delete(agentContext, tenantRoutingRecord)));
|
|
52
|
+
// Delete tenant record
|
|
53
|
+
await this.tenantRepository.delete(agentContext, tenantRecord);
|
|
54
|
+
}
|
|
55
|
+
async updateTenant(agentContext, tenantRecord) {
|
|
56
|
+
return this.tenantRepository.update(agentContext, tenantRecord);
|
|
57
|
+
}
|
|
58
|
+
async findTenantsByQuery(agentContext, query) {
|
|
59
|
+
return this.tenantRepository.findByQuery(agentContext, query);
|
|
60
|
+
}
|
|
61
|
+
async findTenantRoutingRecordByRecipientKey(agentContext, recipientKey) {
|
|
62
|
+
return this.tenantRoutingRepository.findByRecipientKey(agentContext, recipientKey);
|
|
63
|
+
}
|
|
64
|
+
async addTenantRoutingRecord(agentContext, tenantId, recipientKey) {
|
|
65
|
+
const tenantRoutingRecord = new repository_1.TenantRoutingRecord({
|
|
66
|
+
tenantId,
|
|
67
|
+
recipientKeyFingerprint: recipientKey.fingerprint,
|
|
68
|
+
});
|
|
69
|
+
await this.tenantRoutingRepository.save(agentContext, tenantRoutingRecord);
|
|
70
|
+
return tenantRoutingRecord;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
TenantRecordService = __decorate([
|
|
74
|
+
(0, core_1.injectable)(),
|
|
75
|
+
__metadata("design:paramtypes", [repository_1.TenantRepository, repository_1.TenantRoutingRepository])
|
|
76
|
+
], TenantRecordService);
|
|
77
|
+
exports.TenantRecordService = TenantRecordService;
|
|
78
|
+
//# sourceMappingURL=TenantRecordService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantRecordService.js","sourceRoot":"","sources":["../../src/services/TenantRecordService.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TenantRecordService';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TenantRecordService"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateTenantsModuleV0_4ToV0_5 = void 0;
|
|
4
|
+
const tenantRecord_1 = require("./tenantRecord");
|
|
5
|
+
async function updateTenantsModuleV0_4ToV0_5(agent) {
|
|
6
|
+
await (0, tenantRecord_1.migrateTenantRecordToV0_5)(agent);
|
|
7
|
+
}
|
|
8
|
+
exports.updateTenantsModuleV0_4ToV0_5 = updateTenantsModuleV0_4ToV0_5;
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/updates/0.4-0.5/index.ts"],"names":[],"mappings":";;;AAEA,iDAA0D;AAEnD,KAAK,UAAU,6BAA6B,CAA0B,KAAY;IACvF,MAAM,IAAA,wCAAyB,EAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAFD,sEAEC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BaseAgent } from '@credo-ts/core';
|
|
2
|
+
/**
|
|
3
|
+
* Migrates the {@link TenantRecord} to 0.5 compatible format. It fetches all tenant records from
|
|
4
|
+
* storage and applies the needed updates to the records. After a record has been transformed, it is updated
|
|
5
|
+
* in storage and the next record will be transformed.
|
|
6
|
+
*
|
|
7
|
+
* The following transformations are applied:
|
|
8
|
+
* - Re-save record to store new `label` tag
|
|
9
|
+
*/
|
|
10
|
+
export declare function migrateTenantRecordToV0_5<Agent extends BaseAgent>(agent: Agent): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrateTenantRecordToV0_5 = void 0;
|
|
4
|
+
const repository_1 = require("../../repository");
|
|
5
|
+
/**
|
|
6
|
+
* Migrates the {@link TenantRecord} to 0.5 compatible format. It fetches all tenant records from
|
|
7
|
+
* storage and applies the needed updates to the records. After a record has been transformed, it is updated
|
|
8
|
+
* in storage and the next record will be transformed.
|
|
9
|
+
*
|
|
10
|
+
* The following transformations are applied:
|
|
11
|
+
* - Re-save record to store new `label` tag
|
|
12
|
+
*/
|
|
13
|
+
async function migrateTenantRecordToV0_5(agent) {
|
|
14
|
+
agent.config.logger.info('Migrating tenant records to storage version 0.5');
|
|
15
|
+
const tenantRepository = agent.dependencyManager.resolve(repository_1.TenantRepository);
|
|
16
|
+
agent.config.logger.debug(`Fetching all tenant records from storage`);
|
|
17
|
+
const tenantRecords = await tenantRepository.getAll(agent.context);
|
|
18
|
+
agent.config.logger.debug(`Found a total of ${tenantRecords.length} tenant records to update.`);
|
|
19
|
+
for (const tenantRecord of tenantRecords) {
|
|
20
|
+
agent.config.logger.debug(`Migrating tenant record with id ${tenantRecord.id} to storage version 0.5`);
|
|
21
|
+
// NOTE: Record only has change in tags, we need to re-save the record
|
|
22
|
+
await tenantRepository.update(agent.context, tenantRecord);
|
|
23
|
+
agent.config.logger.debug(`Successfully migrated tenant record with id ${tenantRecord.id} to storage version 0.5`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.migrateTenantRecordToV0_5 = migrateTenantRecordToV0_5;
|
|
27
|
+
//# sourceMappingURL=tenantRecord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantRecord.js","sourceRoot":"","sources":["../../../src/updates/0.4-0.5/tenantRecord.ts"],"names":[],"mappings":";;;AAEA,iDAAmD;AAEnD;;;;;;;GAOG;AACI,KAAK,UAAU,yBAAyB,CAA0B,KAAY;IACnF,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAA;IAC3E,MAAM,gBAAgB,GAAG,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,6BAAgB,CAAC,CAAA;IAE1E,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAA;IACrE,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAElE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,aAAa,CAAC,MAAM,4BAA4B,CAAC,CAAA;IAC/F,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;QACxC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,YAAY,CAAC,EAAE,yBAAyB,CAAC,CAAA;QAEtG,sEAAsE;QACtE,MAAM,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;QAE1D,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,+CAA+C,YAAY,CAAC,EAAE,yBAAyB,CAAC,CAAA;KACnH;AACH,CAAC;AAhBD,8DAgBC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@credo-ts/tenants",
|
|
3
|
+
"main": "build/index",
|
|
4
|
+
"types": "build/index",
|
|
5
|
+
"version": "0.4.1-alpha.157+b83c5173",
|
|
6
|
+
"files": [
|
|
7
|
+
"build"
|
|
8
|
+
],
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/openwallet-foundation/credo-ts/tree/main/packages/tenants",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/openwallet-foundation/credo-ts",
|
|
17
|
+
"directory": "packages/tenants"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "yarn run clean && yarn run compile",
|
|
21
|
+
"clean": "rimraf ./build",
|
|
22
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
23
|
+
"prepublishOnly": "yarn run build",
|
|
24
|
+
"test": "jest"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@credo-ts/core": "0.4.1-alpha.157+b83c5173",
|
|
28
|
+
"async-mutex": "^0.4.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@credo-ts/node": "0.4.1-alpha.157+b83c5173",
|
|
32
|
+
"reflect-metadata": "^0.1.13",
|
|
33
|
+
"rimraf": "^4.4.0",
|
|
34
|
+
"typescript": "~4.9.5"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "b83c5173070594448d92f801331b3a31c7ac8049"
|
|
37
|
+
}
|