@credo-ts/tenants 0.6.1-pr-2091-20241119140918 → 0.6.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/build/TenantAgent.d.mts +12 -0
- package/build/TenantAgent.d.mts.map +1 -0
- package/build/TenantAgent.mjs +23 -0
- package/build/TenantAgent.mjs.map +1 -0
- package/build/TenantsApi.d.mts +37 -0
- package/build/TenantsApi.d.mts.map +1 -0
- package/build/TenantsApi.mjs +107 -0
- package/build/TenantsApi.mjs.map +1 -0
- package/build/TenantsApiOptions.d.mts +19 -0
- package/build/TenantsApiOptions.d.mts.map +1 -0
- package/build/TenantsModule.d.mts +23 -0
- package/build/TenantsModule.d.mts.map +1 -0
- package/build/TenantsModule.mjs +40 -0
- package/build/TenantsModule.mjs.map +1 -0
- package/build/TenantsModuleConfig.d.mts +35 -0
- package/build/TenantsModuleConfig.d.mts.map +1 -0
- package/build/TenantsModuleConfig.mjs +18 -0
- package/build/TenantsModuleConfig.mjs.map +1 -0
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs +10 -0
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs +7 -0
- package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateParam.mjs +9 -0
- package/build/context/TenantAgentContextProvider.d.mts +52 -0
- package/build/context/TenantAgentContextProvider.d.mts.map +1 -0
- package/build/context/TenantAgentContextProvider.mjs +149 -0
- package/build/context/TenantAgentContextProvider.mjs.map +1 -0
- package/build/context/TenantSessionCoordinator.d.mts +71 -0
- package/build/context/TenantSessionCoordinator.d.mts.map +1 -0
- package/build/context/TenantSessionCoordinator.mjs +186 -0
- package/build/context/TenantSessionCoordinator.mjs.map +1 -0
- package/build/context/TenantSessionMutex.mjs +66 -0
- package/build/context/TenantSessionMutex.mjs.map +1 -0
- package/build/index.d.mts +10 -0
- package/build/index.mjs +9 -0
- package/build/models/TenantConfig.d.mts +7 -0
- package/build/models/TenantConfig.d.mts.map +1 -0
- package/build/repository/TenantRecord.d.mts +36 -0
- package/build/repository/TenantRecord.d.mts.map +1 -0
- package/build/repository/TenantRecord.mjs +29 -0
- package/build/repository/TenantRecord.mjs.map +1 -0
- package/build/repository/TenantRepository.d.mts +11 -0
- package/build/repository/TenantRepository.d.mts.map +1 -0
- package/build/repository/TenantRepository.mjs +25 -0
- package/build/repository/TenantRepository.mjs.map +1 -0
- package/build/repository/TenantRoutingRecord.d.mts +28 -0
- package/build/repository/TenantRoutingRecord.d.mts.map +1 -0
- package/build/repository/TenantRoutingRecord.mjs +28 -0
- package/build/repository/TenantRoutingRecord.mjs.map +1 -0
- package/build/repository/TenantRoutingRepository.d.mts +11 -0
- package/build/repository/TenantRoutingRepository.d.mts.map +1 -0
- package/build/repository/TenantRoutingRepository.mjs +25 -0
- package/build/repository/TenantRoutingRepository.mjs.map +1 -0
- package/build/repository/index.d.mts +4 -0
- package/build/repository/index.mjs +4 -0
- package/build/services/TenantRecordService.d.mts +26 -0
- package/build/services/TenantRecordService.d.mts.map +1 -0
- package/build/services/TenantRecordService.mjs +63 -0
- package/build/services/TenantRecordService.mjs.map +1 -0
- package/build/services/index.d.mts +1 -0
- package/build/services/index.mjs +1 -0
- package/build/updates/0.4-0.5/index.d.mts +7 -0
- package/build/updates/0.4-0.5/index.d.mts.map +1 -0
- package/build/updates/0.4-0.5/index.mjs +10 -0
- package/build/updates/0.4-0.5/index.mjs.map +1 -0
- package/build/updates/0.4-0.5/tenantRecord.mjs +28 -0
- package/build/updates/0.4-0.5/tenantRecord.mjs.map +1 -0
- package/package.json +15 -14
- package/build/TenantAgent.d.ts +0 -8
- package/build/TenantAgent.js +0 -25
- package/build/TenantAgent.js.map +0 -1
- package/build/TenantsApi.d.ts +0 -25
- package/build/TenantsApi.js +0 -117
- package/build/TenantsApi.js.map +0 -1
- package/build/TenantsApiOptions.d.ts +0 -14
- package/build/TenantsApiOptions.js +0 -3
- package/build/TenantsApiOptions.js.map +0 -1
- package/build/TenantsModule.d.ts +0 -19
- package/build/TenantsModule.js +0 -47
- package/build/TenantsModule.js.map +0 -1
- package/build/TenantsModuleConfig.d.ts +0 -31
- package/build/TenantsModuleConfig.js +0 -20
- package/build/TenantsModuleConfig.js.map +0 -1
- package/build/context/TenantAgentContextProvider.d.ts +0 -40
- package/build/context/TenantAgentContextProvider.js +0 -175
- package/build/context/TenantAgentContextProvider.js.map +0 -1
- package/build/context/TenantSessionCoordinator.d.ts +0 -54
- package/build/context/TenantSessionCoordinator.js +0 -195
- package/build/context/TenantSessionCoordinator.js.map +0 -1
- package/build/context/TenantSessionMutex.d.ts +0 -29
- package/build/context/TenantSessionMutex.js +0 -84
- package/build/context/TenantSessionMutex.js.map +0 -1
- package/build/context/types.d.ts +0 -0
- package/build/context/types.js +0 -2
- package/build/context/types.js.map +0 -1
- package/build/index.d.ts +0 -5
- package/build/index.js +0 -24
- package/build/index.js.map +0 -1
- package/build/models/TenantConfig.d.ts +0 -4
- package/build/models/TenantConfig.js +0 -3
- package/build/models/TenantConfig.js.map +0 -1
- package/build/repository/TenantRecord.d.ts +0 -33
- package/build/repository/TenantRecord.js +0 -32
- package/build/repository/TenantRecord.js.map +0 -1
- package/build/repository/TenantRepository.d.ts +0 -7
- package/build/repository/TenantRepository.js +0 -32
- package/build/repository/TenantRepository.js.map +0 -1
- package/build/repository/TenantRoutingRecord.d.ts +0 -26
- package/build/repository/TenantRoutingRecord.js +0 -24
- package/build/repository/TenantRoutingRecord.js.map +0 -1
- package/build/repository/TenantRoutingRepository.d.ts +0 -7
- package/build/repository/TenantRoutingRepository.js +0 -34
- package/build/repository/TenantRoutingRepository.js.map +0 -1
- package/build/repository/index.d.ts +0 -4
- package/build/repository/index.js +0 -21
- package/build/repository/index.js.map +0 -1
- package/build/services/TenantRecordService.d.ts +0 -17
- package/build/services/TenantRecordService.js +0 -78
- package/build/services/TenantRecordService.js.map +0 -1
- package/build/services/index.d.ts +0 -1
- package/build/services/index.js +0 -18
- package/build/services/index.js.map +0 -1
- package/build/updates/0.4-0.5/index.d.ts +0 -2
- package/build/updates/0.4-0.5/index.js +0 -8
- package/build/updates/0.4-0.5/index.js.map +0 -1
- package/build/updates/0.4-0.5/tenantRecord.d.ts +0 -10
- package/build/updates/0.4-0.5/tenantRecord.js +0 -26
- package/build/updates/0.4-0.5/tenantRecord.js.map +0 -1
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TenantSessionMutex = void 0;
|
|
4
|
-
const core_1 = require("@credo-ts/core");
|
|
5
|
-
const async_mutex_1 = require("async-mutex");
|
|
6
|
-
/**
|
|
7
|
-
* Keep track of the total number of tenant sessions currently active. This doesn't actually manage the tenant sessions itself, or have anything to do with
|
|
8
|
-
* the agent context. It merely counts the current number of sessions, and provides a mutex to lock new sessions from being created once the maximum number
|
|
9
|
-
* of sessions has been created. Session that can't be required withing the specified sessionsAcquireTimeout will throw an error.
|
|
10
|
-
*/
|
|
11
|
-
class TenantSessionMutex {
|
|
12
|
-
constructor(logger, maxSessions = Infinity, sessionAcquireTimeout) {
|
|
13
|
-
this._currentSessions = 0;
|
|
14
|
-
this.maxSessions = Infinity;
|
|
15
|
-
this.logger = logger;
|
|
16
|
-
this.maxSessions = maxSessions;
|
|
17
|
-
// Session mutex, it can take at most sessionAcquireTimeout to acquire a session, otherwise it will fail with the error below
|
|
18
|
-
this.sessionMutex = (0, async_mutex_1.withTimeout)(new async_mutex_1.Mutex(), sessionAcquireTimeout, new core_1.CredoError(`Failed to acquire an agent context session within ${sessionAcquireTimeout}ms`));
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Getter to retrieve the total number of current sessions.
|
|
22
|
-
*/
|
|
23
|
-
get currentSessions() {
|
|
24
|
-
return this._currentSessions;
|
|
25
|
-
}
|
|
26
|
-
set currentSessions(value) {
|
|
27
|
-
this._currentSessions = value;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Wait to acquire a session. Will use the session semaphore to keep total number of sessions limited.
|
|
31
|
-
* For each session that is acquired using this method, the sessions MUST be closed by calling `releaseSession`.
|
|
32
|
-
* Failing to do so can lead to deadlocks over time.
|
|
33
|
-
*/
|
|
34
|
-
async acquireSession() {
|
|
35
|
-
// TODO: We should update this to be weighted
|
|
36
|
-
// This will allow to weight sessions for contexts that already exist lower than sessions
|
|
37
|
-
// for contexts that need to be created (new injection container, wallet session etc..)
|
|
38
|
-
// E.g. opening a context could weigh 5, adding sessions to it would be 1 for each
|
|
39
|
-
this.logger.debug('Acquiring tenant session');
|
|
40
|
-
// If we're out of sessions, wait for one to be released.
|
|
41
|
-
if (this.sessionMutex.isLocked()) {
|
|
42
|
-
this.logger.debug('Session mutex is locked, waiting for it to unlock');
|
|
43
|
-
// FIXME: waitForUnlock doesn't work with withTimeout but provides a better API (would rather not acquire and lock)
|
|
44
|
-
// await this.sessionMutex.waitForUnlock()
|
|
45
|
-
// Workaround https://github.com/MatrixAI/js-async-locks/pull/3/files#diff-4ee6a7d91cb8428765713bc3045e1dda5d43214030657a9c04804e96d68778bfR46-R61
|
|
46
|
-
await this.sessionMutex.acquire();
|
|
47
|
-
if (this.currentSessions < this.maxSessions) {
|
|
48
|
-
this.sessionMutex.release();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
this.logger.debug(`Increasing current session count to ${this.currentSessions + 1} (max: ${this.maxSessions})`);
|
|
52
|
-
// We have waited for the session to unlock,
|
|
53
|
-
this.currentSessions++;
|
|
54
|
-
// If we reached the limit we should lock the session mutex
|
|
55
|
-
if (this.currentSessions >= this.maxSessions) {
|
|
56
|
-
this.logger.debug(`Reached max number of sessions ${this.maxSessions}, locking mutex`);
|
|
57
|
-
await this.sessionMutex.acquire();
|
|
58
|
-
}
|
|
59
|
-
this.logger.debug(`Acquired tenant session (${this.currentSessions} / ${this.maxSessions})`);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Release a session from the session mutex. If the total number of current sessions drops below
|
|
63
|
-
* the max number of sessions, the session mutex will be released so new sessions can be started.
|
|
64
|
-
*/
|
|
65
|
-
releaseSession() {
|
|
66
|
-
this.logger.debug('Releasing tenant session');
|
|
67
|
-
if (this.currentSessions > 0) {
|
|
68
|
-
this.logger.debug(`Decreasing current sessions to ${this.currentSessions - 1} (max: ${this.maxSessions})`);
|
|
69
|
-
this.currentSessions--;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
this.logger.warn('Total sessions is already at 0, and releasing a session should not happen in this case. Not decrementing current session count.');
|
|
73
|
-
}
|
|
74
|
-
// If the number of current sessions is lower than the max number of sessions we can release the mutex
|
|
75
|
-
if (this.sessionMutex.isLocked() && this.currentSessions < this.maxSessions) {
|
|
76
|
-
this.logger.debug(`Releasing session mutex as number of current sessions ${this.currentSessions} is below max number of sessions ${this.maxSessions}`);
|
|
77
|
-
// Even though marked as deprecated, it is not actually deprecated and will be kept
|
|
78
|
-
// https://github.com/DirtyHairy/async-mutex/issues/50#issuecomment-1007785141
|
|
79
|
-
this.sessionMutex.release();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.TenantSessionMutex = TenantSessionMutex;
|
|
84
|
-
//# sourceMappingURL=TenantSessionMutex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TenantSessionMutex.js","sourceRoot":"","sources":["../../src/context/TenantSessionMutex.ts"],"names":[],"mappings":";;;AAGA,yCAA2C;AAC3C,6CAAgD;AAEhD;;;;GAIG;AACH,MAAa,kBAAkB;IAM7B,YAAmB,MAAc,EAAE,WAAW,GAAG,QAAQ,EAAE,qBAA6B;QALhF,qBAAgB,GAAG,CAAC,CAAA;QACZ,gBAAW,GAAG,QAAQ,CAAA;QAKpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,6HAA6H;QAC7H,IA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YAAY,CAAC,OAAO,EAAE,CAAA;QACnC,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,IAAI,CAAC,eAAe,MAAM,IAAI,CAAC,WAAW,GAAG,CAAC,CAAA;IAC9F,CAAC;IAED;;;OAGG;IACI,cAAc;QACnB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAE7C,IAAI,IAAI,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,IAAI,CAAC,eAAe,GAAG,CAAC,UAAU,IAAI,CAAC,WAAW,GAAG,CAAC,CAAA;YAC1G,IAAI,CAAC,eAAe,EAAE,CAAA;QACxB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,iIAAiI,CAClI,CAAA;QACH,CAAC;QAED,sGAAsG;QACtG,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YAC5E,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,yDAAyD,IAAI,CAAC,eAAe,oCAAoC,IAAI,CAAC,WAAW,EAAE,CACpI,CAAA;YACD,mFAAmF;YACnF,8EAA8E;YAC9E,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAA;QAC7B,CAAC;IACH,CAAC;CACF;AA5FD,gDA4FC"}
|
package/build/context/types.d.ts
DELETED
|
File without changes
|
package/build/context/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":""}
|
package/build/index.d.ts
DELETED
package/build/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
exports.TenantRecord = void 0;
|
|
18
|
-
var TenantRecord_1 = require("./repository/TenantRecord");
|
|
19
|
-
Object.defineProperty(exports, "TenantRecord", { enumerable: true, get: function () { return TenantRecord_1.TenantRecord; } });
|
|
20
|
-
__exportStar(require("./TenantsModule"), exports);
|
|
21
|
-
__exportStar(require("./TenantsApi"), exports);
|
|
22
|
-
__exportStar(require("./TenantsApiOptions"), exports);
|
|
23
|
-
__exportStar(require("./TenantsModuleConfig"), exports);
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0DAA2E;AAAlE,4GAAA,YAAY,OAAA;AACrB,kDAA+B;AAC/B,+CAA4B;AAC5B,sDAAmC;AACnC,wDAAqC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TenantConfig.js","sourceRoot":"","sources":["../../src/models/TenantConfig.ts"],"names":[],"mappings":""}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,CAAC;YACV,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;QAC5C,CAAC;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,AAAjB,CAAiB"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
exports.TenantRepository = TenantRepository;
|
|
27
|
-
exports.TenantRepository = TenantRepository = __decorate([
|
|
28
|
-
(0, core_1.injectable)(),
|
|
29
|
-
__param(0, (0, core_1.inject)(core_1.InjectionSymbols.StorageService)),
|
|
30
|
-
__metadata("design:paramtypes", [Object, core_1.EventEmitter])
|
|
31
|
-
], TenantRepository);
|
|
32
|
-
//# sourceMappingURL=TenantRepository.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,iBAAU,GAAE;IAGR,WAAA,IAAA,aAAM,EAAC,uBAAgB,CAAC,cAAc,CAAC,CAAA;6CAC1B,mBAAY;GAHjB,gBAAgB,CAW5B"}
|
|
@@ -1,26 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,CAAC;YACV,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;QAC9D,CAAC;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,AAAxB,CAAwB"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
exports.TenantRoutingRepository = TenantRoutingRepository;
|
|
29
|
-
exports.TenantRoutingRepository = TenantRoutingRepository = __decorate([
|
|
30
|
-
(0, core_1.injectable)(),
|
|
31
|
-
__param(0, (0, core_1.inject)(core_1.InjectionSymbols.StorageService)),
|
|
32
|
-
__metadata("design:paramtypes", [Object, core_1.EventEmitter])
|
|
33
|
-
], TenantRoutingRepository);
|
|
34
|
-
//# sourceMappingURL=TenantRoutingRepository.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,iBAAU,GAAE;IAGR,WAAA,IAAA,aAAM,EAAC,uBAAgB,CAAC,cAAc,CAAC,CAAA;6CAC1B,mBAAY;GAHjB,uBAAuB,CAanC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/repository/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B;AAC9B,qDAAkC;AAClC,wDAAqC;AACrC,4DAAyC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { TenantConfig } from '../models/TenantConfig';
|
|
2
|
-
import type { AgentContext, Key, Query, QueryOptions } 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>, queryOptions?: QueryOptions): Promise<TenantRecord[]>;
|
|
15
|
-
findTenantRoutingRecordByRecipientKey(agentContext: AgentContext, recipientKey: Key): Promise<TenantRoutingRecord | null>;
|
|
16
|
-
addTenantRoutingRecord(agentContext: AgentContext, tenantId: string, recipientKey: Key): Promise<TenantRoutingRecord>;
|
|
17
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
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, queryOptions) {
|
|
59
|
-
return this.tenantRepository.findByQuery(agentContext, query, queryOptions);
|
|
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
|
-
exports.TenantRecordService = TenantRecordService;
|
|
74
|
-
exports.TenantRecordService = TenantRecordService = __decorate([
|
|
75
|
-
(0, core_1.injectable)(),
|
|
76
|
-
__metadata("design:paramtypes", [repository_1.TenantRepository, repository_1.TenantRoutingRepository])
|
|
77
|
-
], TenantRecordService);
|
|
78
|
-
//# sourceMappingURL=TenantRecordService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
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AAmB,GAAG,IAAI,gCAAmB,CAAC;YAClD,QAAQ;YACR,uBAAuB,EAAE,YAAY,CAAC,WAAW;SAClD,CAAC,CAAA;QAEF,MAAM,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAA;QAE1E,OAAO,mBAAmB,CAAA;IAC5B,CAAC;CACF,CAAA;AA5FY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,iBAAU,GAAE;qCAK0B,6BAAgB,EAA2B,oCAAuB;GAJ5F,mBAAmB,CA4F/B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './TenantRecordService';
|
package/build/services/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateTenantsModuleV0_4ToV0_5 = updateTenantsModuleV0_4ToV0_5;
|
|
4
|
-
const tenantRecord_1 = require("./tenantRecord");
|
|
5
|
-
async function updateTenantsModuleV0_4ToV0_5(agent) {
|
|
6
|
-
await (0, tenantRecord_1.migrateTenantRecordToV0_5)(agent);
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/updates/0.4-0.5/index.ts"],"names":[],"mappings":";;AAIA,sEAEC;AAJD,iDAA0D;AAEnD,KAAK,UAAU,6BAA6B,CAA0B,KAAY;IACvF,MAAM,IAAA,wCAAyB,EAAC,KAAK,CAAC,CAAA;AACxC,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
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>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateTenantRecordToV0_5 = migrateTenantRecordToV0_5;
|
|
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
|
-
//# sourceMappingURL=tenantRecord.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tenantRecord.js","sourceRoot":"","sources":["../../../src/updates/0.4-0.5/tenantRecord.ts"],"names":[],"mappings":";;AAYA,8DAgBC;AA1BD,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,CAAC;QACzC,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;IACpH,CAAC;AACH,CAAC"}
|