@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
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2020-present Hyperledger Contributors.
|
|
190
|
+
Copyright 2021 Queen’s Printer for Ontario. Mostafa Youssef (https://github.com/MosCD3), Amit Padmani (https://github.com/nbAmit), Prasad Katkar (https://github.com/NB-PrasadKatkar), Mike Richardson (https://github.com/NB-MikeRichardson)
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<br />
|
|
3
|
+
<img
|
|
4
|
+
alt="Credo Logo"
|
|
5
|
+
src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png"
|
|
6
|
+
height="250px"
|
|
7
|
+
/>
|
|
8
|
+
</p>
|
|
9
|
+
<h1 align="center"><b>Credo Tenants Module</b></h1>
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a
|
|
12
|
+
href="https://raw.githubusercontent.com/openwallet-foundation/credo-ts/main/LICENSE"
|
|
13
|
+
><img
|
|
14
|
+
alt="License"k
|
|
15
|
+
src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"
|
|
16
|
+
/></a>
|
|
17
|
+
<a href="https://www.typescriptlang.org/"
|
|
18
|
+
><img
|
|
19
|
+
alt="typescript"
|
|
20
|
+
src="https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg"
|
|
21
|
+
/></a>
|
|
22
|
+
<a href="https://www.npmjs.com/package/@credo-ts/tenants"
|
|
23
|
+
><img
|
|
24
|
+
alt="@credo-ts/tenants version"
|
|
25
|
+
src="https://img.shields.io/npm/v/@credo-ts/tenants"
|
|
26
|
+
/></a>
|
|
27
|
+
|
|
28
|
+
</p>
|
|
29
|
+
<br />
|
|
30
|
+
|
|
31
|
+
Credo Tenant Module provides an optional addon to Credo to use an agent with multiple tenants.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentContext, DefaultAgentModules, ModulesMap } from '@credo-ts/core';
|
|
2
|
+
import { BaseAgent } from '@credo-ts/core';
|
|
3
|
+
export declare class TenantAgent<AgentModules extends ModulesMap = DefaultAgentModules> extends BaseAgent<AgentModules> {
|
|
4
|
+
private sessionHasEnded;
|
|
5
|
+
constructor(agentContext: AgentContext);
|
|
6
|
+
initialize(): Promise<void>;
|
|
7
|
+
endSession(): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TenantAgent = void 0;
|
|
4
|
+
const core_1 = require("@credo-ts/core");
|
|
5
|
+
class TenantAgent extends core_1.BaseAgent {
|
|
6
|
+
constructor(agentContext) {
|
|
7
|
+
super(agentContext.config, agentContext.dependencyManager);
|
|
8
|
+
this.sessionHasEnded = false;
|
|
9
|
+
}
|
|
10
|
+
async initialize() {
|
|
11
|
+
if (this.sessionHasEnded) {
|
|
12
|
+
throw new core_1.CredoError("Can't initialize agent after tenant sessions has been ended.");
|
|
13
|
+
}
|
|
14
|
+
await super.initialize();
|
|
15
|
+
this._isInitialized = true;
|
|
16
|
+
}
|
|
17
|
+
async endSession() {
|
|
18
|
+
this.logger.trace(`Ending session for agent context with contextCorrelationId '${this.agentContext.contextCorrelationId}'`);
|
|
19
|
+
await this.agentContext.endSession();
|
|
20
|
+
this._isInitialized = false;
|
|
21
|
+
this.sessionHasEnded = true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.TenantAgent = TenantAgent;
|
|
25
|
+
//# sourceMappingURL=TenantAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantAgent.js","sourceRoot":"","sources":["../src/TenantAgent.ts"],"names":[],"mappings":";;;AAEA,yCAAsD;AAEtD,MAAa,WAAmE,SAAQ,gBAAuB;IAG7G,YAAmB,YAA0B;QAC3C,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAA;QAHpD,oBAAe,GAAG,KAAK,CAAA;IAI/B,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,IAAI,IAAI,CAAC,eAAe,EAAE;YACxB,MAAM,IAAI,iBAAU,CAAC,8DAA8D,CAAC,CAAA;SACrF;QAED,MAAM,KAAK,CAAC,UAAU,EAAE,CAAA;QACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;IAC5B,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,+DAA+D,IAAI,CAAC,YAAY,CAAC,oBAAoB,GAAG,CACzG,CAAA;QACD,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAA;QACpC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAA;QAC3B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAA;IAC7B,CAAC;CACF;AAxBD,kCAwBC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CreateTenantOptions, GetTenantAgentOptions, UpdateTenantStorageOptions, WithTenantAgentCallback } from './TenantsApiOptions';
|
|
2
|
+
import type { TenantRecord } from './repository';
|
|
3
|
+
import type { DefaultAgentModules, ModulesMap, Query } from '@credo-ts/core';
|
|
4
|
+
import { AgentContext, Logger } from '@credo-ts/core';
|
|
5
|
+
import { TenantAgent } from './TenantAgent';
|
|
6
|
+
import { TenantAgentContextProvider } from './context/TenantAgentContextProvider';
|
|
7
|
+
import { TenantRecordService } from './services';
|
|
8
|
+
export declare class TenantsApi<AgentModules extends ModulesMap = DefaultAgentModules> {
|
|
9
|
+
readonly rootAgentContext: AgentContext;
|
|
10
|
+
private tenantRecordService;
|
|
11
|
+
private agentContextProvider;
|
|
12
|
+
private logger;
|
|
13
|
+
constructor(tenantRecordService: TenantRecordService, rootAgentContext: AgentContext, agentContextProvider: TenantAgentContextProvider, logger: Logger);
|
|
14
|
+
getTenantAgent({ tenantId }: GetTenantAgentOptions): Promise<TenantAgent<AgentModules>>;
|
|
15
|
+
withTenantAgent(options: GetTenantAgentOptions, withTenantAgentCallback: WithTenantAgentCallback<AgentModules>): Promise<void>;
|
|
16
|
+
createTenant(options: CreateTenantOptions): Promise<TenantRecord>;
|
|
17
|
+
getTenantById(tenantId: string): Promise<TenantRecord>;
|
|
18
|
+
findTenantsByLabel(label: string): Promise<TenantRecord[]>;
|
|
19
|
+
deleteTenantById(tenantId: string): Promise<void>;
|
|
20
|
+
updateTenant(tenant: TenantRecord): Promise<void>;
|
|
21
|
+
findTenantsByQuery(query: Query<TenantRecord>): Promise<TenantRecord[]>;
|
|
22
|
+
getAllTenants(): Promise<TenantRecord[]>;
|
|
23
|
+
updateTenantStorage({ tenantId, updateOptions }: UpdateTenantStorageOptions): Promise<void>;
|
|
24
|
+
getTenantsWithOutdatedStorage(): Promise<TenantRecord[]>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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.TenantsApi = void 0;
|
|
16
|
+
const core_1 = require("@credo-ts/core");
|
|
17
|
+
const TenantAgent_1 = require("./TenantAgent");
|
|
18
|
+
const TenantAgentContextProvider_1 = require("./context/TenantAgentContextProvider");
|
|
19
|
+
const services_1 = require("./services");
|
|
20
|
+
let TenantsApi = class TenantsApi {
|
|
21
|
+
constructor(tenantRecordService, rootAgentContext, agentContextProvider, logger) {
|
|
22
|
+
this.tenantRecordService = tenantRecordService;
|
|
23
|
+
this.rootAgentContext = rootAgentContext;
|
|
24
|
+
this.agentContextProvider = agentContextProvider;
|
|
25
|
+
this.logger = logger;
|
|
26
|
+
}
|
|
27
|
+
async getTenantAgent({ tenantId }) {
|
|
28
|
+
this.logger.debug(`Getting tenant agent for tenant '${tenantId}'`);
|
|
29
|
+
const tenantContext = await this.agentContextProvider.getAgentContextForContextCorrelationId(tenantId);
|
|
30
|
+
this.logger.trace(`Got tenant context for tenant '${tenantId}'`);
|
|
31
|
+
const tenantAgent = new TenantAgent_1.TenantAgent(tenantContext);
|
|
32
|
+
await tenantAgent.initialize();
|
|
33
|
+
this.logger.trace(`Initializing tenant agent for tenant '${tenantId}'`);
|
|
34
|
+
return tenantAgent;
|
|
35
|
+
}
|
|
36
|
+
async withTenantAgent(options, withTenantAgentCallback) {
|
|
37
|
+
this.logger.debug(`Getting tenant agent for tenant '${options.tenantId}' in with tenant agent callback`);
|
|
38
|
+
const tenantAgent = await this.getTenantAgent(options);
|
|
39
|
+
try {
|
|
40
|
+
this.logger.debug(`Calling tenant agent callback for tenant '${options.tenantId}'`);
|
|
41
|
+
await withTenantAgentCallback(tenantAgent);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.logger.error(`Error in tenant agent callback for tenant '${options.tenantId}'`, { error });
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
this.logger.debug(`Ending tenant agent session for tenant '${options.tenantId}'`);
|
|
49
|
+
await tenantAgent.endSession();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async createTenant(options) {
|
|
53
|
+
this.logger.debug(`Creating tenant with label ${options.config.label}`);
|
|
54
|
+
const tenantRecord = await this.tenantRecordService.createTenant(this.rootAgentContext, options.config);
|
|
55
|
+
// This initializes the tenant agent, creates the wallet etc...
|
|
56
|
+
const tenantAgent = await this.getTenantAgent({ tenantId: tenantRecord.id });
|
|
57
|
+
await tenantAgent.endSession();
|
|
58
|
+
this.logger.info(`Successfully created tenant '${tenantRecord.id}'`);
|
|
59
|
+
return tenantRecord;
|
|
60
|
+
}
|
|
61
|
+
async getTenantById(tenantId) {
|
|
62
|
+
this.logger.debug(`Getting tenant by id '${tenantId}'`);
|
|
63
|
+
return this.tenantRecordService.getTenantById(this.rootAgentContext, tenantId);
|
|
64
|
+
}
|
|
65
|
+
async findTenantsByLabel(label) {
|
|
66
|
+
this.logger.debug(`Finding tenants by label '${label}'`);
|
|
67
|
+
return this.tenantRecordService.findTenantsByLabel(this.rootAgentContext, label);
|
|
68
|
+
}
|
|
69
|
+
async deleteTenantById(tenantId) {
|
|
70
|
+
this.logger.debug(`Deleting tenant by id '${tenantId}'`);
|
|
71
|
+
// TODO: force remove context from the context provider (or session manager)
|
|
72
|
+
const tenantAgent = await this.getTenantAgent({ tenantId });
|
|
73
|
+
this.logger.trace(`Deleting wallet for tenant '${tenantId}'`);
|
|
74
|
+
await tenantAgent.wallet.delete();
|
|
75
|
+
this.logger.trace(`Shutting down agent for tenant '${tenantId}'`);
|
|
76
|
+
await tenantAgent.endSession();
|
|
77
|
+
return this.tenantRecordService.deleteTenantById(this.rootAgentContext, tenantId);
|
|
78
|
+
}
|
|
79
|
+
async updateTenant(tenant) {
|
|
80
|
+
await this.tenantRecordService.updateTenant(this.rootAgentContext, tenant);
|
|
81
|
+
}
|
|
82
|
+
async findTenantsByQuery(query) {
|
|
83
|
+
return this.tenantRecordService.findTenantsByQuery(this.rootAgentContext, query);
|
|
84
|
+
}
|
|
85
|
+
async getAllTenants() {
|
|
86
|
+
this.logger.debug('Getting all tenants');
|
|
87
|
+
return this.tenantRecordService.getAllTenants(this.rootAgentContext);
|
|
88
|
+
}
|
|
89
|
+
async updateTenantStorage({ tenantId, updateOptions }) {
|
|
90
|
+
this.logger.debug(`Updating tenant storage for tenant '${tenantId}'`);
|
|
91
|
+
const tenantRecord = await this.tenantRecordService.getTenantById(this.rootAgentContext, tenantId);
|
|
92
|
+
if ((0, core_1.isStorageUpToDate)(tenantRecord.storageVersion)) {
|
|
93
|
+
this.logger.debug(`Tenant storage for tenant '${tenantId}' is already up to date. Skipping update`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
await this.agentContextProvider.updateTenantStorage(tenantRecord, updateOptions);
|
|
97
|
+
}
|
|
98
|
+
async getTenantsWithOutdatedStorage() {
|
|
99
|
+
const outdatedTenants = await this.tenantRecordService.findTenantsByQuery(this.rootAgentContext, {
|
|
100
|
+
$not: {
|
|
101
|
+
storageVersion: core_1.UpdateAssistant.frameworkStorageVersion,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
return outdatedTenants;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
TenantsApi = __decorate([
|
|
108
|
+
(0, core_1.injectable)(),
|
|
109
|
+
__param(2, (0, core_1.inject)(core_1.InjectionSymbols.AgentContextProvider)),
|
|
110
|
+
__param(3, (0, core_1.inject)(core_1.InjectionSymbols.Logger)),
|
|
111
|
+
__metadata("design:paramtypes", [services_1.TenantRecordService,
|
|
112
|
+
core_1.AgentContext,
|
|
113
|
+
TenantAgentContextProvider_1.TenantAgentContextProvider, Object])
|
|
114
|
+
], TenantsApi);
|
|
115
|
+
exports.TenantsApi = TenantsApi;
|
|
116
|
+
//# sourceMappingURL=TenantsApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantsApi.js","sourceRoot":"","sources":["../src/TenantsApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,yCAQuB;AAEvB,+CAA2C;AAC3C,qFAAiF;AACjF,yCAAgD;AAGzC,IAAM,UAAU,GAAhB,MAAM,UAAU;IAMrB,YACE,mBAAwC,EACxC,gBAA8B,EACiB,oBAAgD,EAC9D,MAAc;QAE/C,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAC9C,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;QAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,EAAE,QAA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,aAAa,CAAC,CAAA;IAClF,CAAC;IAEM,KAAK,CAAC,6BAA6B;QACxC,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,IAAI,CAAC,gBAAgB,EAAE;YAC/F,IAAI,EAAE;gBACJ,cAAc,EAAE,sBAAe,CAAC,uBAAuB;aACxD;SACF,CAAC,CAAA;QAEF,OAAO,eAAe,CAAA;IACxB,CAAC;CACF,CAAA;AAvHY,UAAU;IADtB,IAAA,iBAAU,GAAE;IAUR,WAAA,IAAA,aAAM,EAAC,uBAAgB,CAAC,oBAAoB,CAAC,CAAA;IAC7C,WAAA,IAAA,aAAM,EAAC,uBAAgB,CAAC,MAAM,CAAC,CAAA;qCAHX,8BAAmB;QACtB,mBAAY;QACuC,uDAA0B;GATtF,UAAU,CAuHtB;AAvHY,gCAAU"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TenantAgent } from './TenantAgent';
|
|
2
|
+
import type { TenantConfig } from './models/TenantConfig';
|
|
3
|
+
import type { ModulesMap, UpdateAssistantUpdateOptions } from '@credo-ts/core';
|
|
4
|
+
export interface GetTenantAgentOptions {
|
|
5
|
+
tenantId: string;
|
|
6
|
+
}
|
|
7
|
+
export type WithTenantAgentCallback<AgentModules extends ModulesMap> = (tenantAgent: TenantAgent<AgentModules>) => Promise<void>;
|
|
8
|
+
export interface CreateTenantOptions {
|
|
9
|
+
config: Omit<TenantConfig, 'walletConfig'>;
|
|
10
|
+
}
|
|
11
|
+
export interface UpdateTenantStorageOptions {
|
|
12
|
+
tenantId: string;
|
|
13
|
+
updateOptions?: UpdateAssistantUpdateOptions;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantsApiOptions.js","sourceRoot":"","sources":["../src/TenantsApiOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TenantsModuleConfigOptions } from './TenantsModuleConfig';
|
|
2
|
+
import type { Constructor, ModulesMap, DependencyManager, Module, EmptyModuleMap } from '@credo-ts/core';
|
|
3
|
+
import { TenantsApi } from './TenantsApi';
|
|
4
|
+
import { TenantsModuleConfig } from './TenantsModuleConfig';
|
|
5
|
+
import { updateTenantsModuleV0_4ToV0_5 } from './updates/0.4-0.5';
|
|
6
|
+
export declare class TenantsModule<AgentModules extends ModulesMap = EmptyModuleMap> implements Module {
|
|
7
|
+
readonly config: TenantsModuleConfig;
|
|
8
|
+
readonly api: Constructor<TenantsApi<AgentModules>>;
|
|
9
|
+
constructor(config?: TenantsModuleConfigOptions);
|
|
10
|
+
/**
|
|
11
|
+
* Registers the dependencies of the tenants module on the dependency manager.
|
|
12
|
+
*/
|
|
13
|
+
register(dependencyManager: DependencyManager): void;
|
|
14
|
+
updates: {
|
|
15
|
+
fromVersion: "0.4";
|
|
16
|
+
toVersion: "0.5";
|
|
17
|
+
doUpdate: typeof updateTenantsModuleV0_4ToV0_5;
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TenantsModule = void 0;
|
|
4
|
+
const core_1 = require("@credo-ts/core");
|
|
5
|
+
const TenantsApi_1 = require("./TenantsApi");
|
|
6
|
+
const TenantsModuleConfig_1 = require("./TenantsModuleConfig");
|
|
7
|
+
const TenantAgentContextProvider_1 = require("./context/TenantAgentContextProvider");
|
|
8
|
+
const TenantSessionCoordinator_1 = require("./context/TenantSessionCoordinator");
|
|
9
|
+
const repository_1 = require("./repository");
|
|
10
|
+
const services_1 = require("./services");
|
|
11
|
+
const _0_4_0_5_1 = require("./updates/0.4-0.5");
|
|
12
|
+
class TenantsModule {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.api = TenantsApi_1.TenantsApi;
|
|
15
|
+
this.updates = [
|
|
16
|
+
{
|
|
17
|
+
fromVersion: '0.4',
|
|
18
|
+
toVersion: '0.5',
|
|
19
|
+
doUpdate: _0_4_0_5_1.updateTenantsModuleV0_4ToV0_5,
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
this.config = new TenantsModuleConfig_1.TenantsModuleConfig(config);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Registers the dependencies of the tenants module on the dependency manager.
|
|
26
|
+
*/
|
|
27
|
+
register(dependencyManager) {
|
|
28
|
+
// Warn about experimental module
|
|
29
|
+
dependencyManager
|
|
30
|
+
.resolve(core_1.AgentConfig)
|
|
31
|
+
.logger.warn("The '@credo-ts/tenants' module is experimental and could have unexpected breaking changes. When using this module, make sure to use strict versions for all @credo-ts packages.");
|
|
32
|
+
// Api
|
|
33
|
+
// NOTE: this is a singleton because tenants can't have their own tenants. This makes sure the tenants api is always used in the root agent context.
|
|
34
|
+
dependencyManager.registerSingleton(TenantsApi_1.TenantsApi);
|
|
35
|
+
// Config
|
|
36
|
+
dependencyManager.registerInstance(TenantsModuleConfig_1.TenantsModuleConfig, this.config);
|
|
37
|
+
// Services
|
|
38
|
+
dependencyManager.registerSingleton(services_1.TenantRecordService);
|
|
39
|
+
// Repositories
|
|
40
|
+
dependencyManager.registerSingleton(repository_1.TenantRepository);
|
|
41
|
+
dependencyManager.registerSingleton(repository_1.TenantRoutingRepository);
|
|
42
|
+
dependencyManager.registerSingleton(core_1.InjectionSymbols.AgentContextProvider, TenantAgentContextProvider_1.TenantAgentContextProvider);
|
|
43
|
+
dependencyManager.registerSingleton(TenantSessionCoordinator_1.TenantSessionCoordinator);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.TenantsModule = TenantsModule;
|
|
47
|
+
//# sourceMappingURL=TenantsModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantsModule.js","sourceRoot":"","sources":["../src/TenantsModule.ts"],"names":[],"mappings":";;;AAGA,yCAA8D;AAE9D,6CAAyC;AACzC,+DAA2D;AAC3D,qFAAiF;AACjF,iFAA6E;AAC7E,6CAAwE;AACxE,yCAAgD;AAChD,gDAAiE;AAEjE,MAAa,aAAa;IAKxB,YAAmB,MAAmC;QAFtC,QAAG,GAA0C,uBAAU,CAAA;QAmChE,YAAO,GAAG;YACf;gBACE,WAAW,EAAE,KAAK;gBAClB,SAAS,EAAE,KAAK;gBAChB,QAAQ,EAAE,wCAA6B;aACxC;SACiB,CAAA;QAtClB,IAAI,CAAC,MAAM,GAAG,IAAI,yCAAmB,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,iBAAoC;QAClD,iCAAiC;QACjC,iBAAiB;aACd,OAAO,CAAC,kBAAW,CAAC;aACpB,MAAM,CAAC,IAAI,CACV,iLAAiL,CAClL,CAAA;QAEH,MAAM;QACN,oJAAoJ;QACpJ,iBAAiB,CAAC,iBAAiB,CAAC,uBAAU,CAAC,CAAA;QAE/C,SAAS;QACT,iBAAiB,CAAC,gBAAgB,CAAC,yCAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAEpE,WAAW;QACX,iBAAiB,CAAC,iBAAiB,CAAC,8BAAmB,CAAC,CAAA;QAExD,eAAe;QACf,iBAAiB,CAAC,iBAAiB,CAAC,6BAAgB,CAAC,CAAA;QACrD,iBAAiB,CAAC,iBAAiB,CAAC,oCAAuB,CAAC,CAAA;QAE5D,iBAAiB,CAAC,iBAAiB,CAAC,uBAAgB,CAAC,oBAAoB,EAAE,uDAA0B,CAAC,CAAA;QACtG,iBAAiB,CAAC,iBAAiB,CAAC,mDAAwB,CAAC,CAAA;IAC/D,CAAC;CASF;AA7CD,sCA6CC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TenantsModuleConfigOptions defines the interface for the options of the TenantsModuleConfig class.
|
|
3
|
+
* This can contain optional parameters that have default values in the config class itself.
|
|
4
|
+
*/
|
|
5
|
+
export interface TenantsModuleConfigOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Maximum number of concurrent tenant sessions that can be active at the same time. Defaults to
|
|
8
|
+
* 100 concurrent sessions. The default is low on purpose, to make sure deployments determine their own
|
|
9
|
+
* session limit based on the hardware and usage of the tenants module. Use `Infinity` to allow unlimited
|
|
10
|
+
* concurrent sessions.
|
|
11
|
+
*
|
|
12
|
+
* @default 100
|
|
13
|
+
*/
|
|
14
|
+
sessionLimit?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Timeout in milliseconds for acquiring a tenant session. If the {@link TenantsModuleConfigOptions.maxNumberOfSessions} is reached and
|
|
17
|
+
* a tenant sessions couldn't be acquired within the specified timeout, an error will be thrown and the session creation will be aborted.
|
|
18
|
+
* Use `Infinity` to disable the timeout.
|
|
19
|
+
*
|
|
20
|
+
* @default 1000
|
|
21
|
+
*/
|
|
22
|
+
sessionAcquireTimeout?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class TenantsModuleConfig {
|
|
25
|
+
private options;
|
|
26
|
+
constructor(options?: TenantsModuleConfigOptions);
|
|
27
|
+
/** See {@link TenantsModuleConfigOptions.sessionLimit} */
|
|
28
|
+
get sessionLimit(): number;
|
|
29
|
+
/** See {@link TenantsModuleConfigOptions.sessionAcquireTimeout} */
|
|
30
|
+
get sessionAcquireTimeout(): number;
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TenantsModuleConfig = void 0;
|
|
4
|
+
class TenantsModuleConfig {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.options = options !== null && options !== void 0 ? options : {};
|
|
7
|
+
}
|
|
8
|
+
/** See {@link TenantsModuleConfigOptions.sessionLimit} */
|
|
9
|
+
get sessionLimit() {
|
|
10
|
+
var _a;
|
|
11
|
+
return (_a = this.options.sessionLimit) !== null && _a !== void 0 ? _a : 100;
|
|
12
|
+
}
|
|
13
|
+
/** See {@link TenantsModuleConfigOptions.sessionAcquireTimeout} */
|
|
14
|
+
get sessionAcquireTimeout() {
|
|
15
|
+
var _a;
|
|
16
|
+
return (_a = this.options.sessionAcquireTimeout) !== null && _a !== void 0 ? _a : 1000;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.TenantsModuleConfig = TenantsModuleConfig;
|
|
20
|
+
//# sourceMappingURL=TenantsModuleConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TenantsModuleConfig.js","sourceRoot":"","sources":["../src/TenantsModuleConfig.ts"],"names":[],"mappings":";;;AAyBA,MAAa,mBAAmB;IAG9B,YAAmB,OAAoC;QACrD,IAAI,CAAC,OAAO,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAA;IAC9B,CAAC;IAED,0DAA0D;IAC1D,IAAW,YAAY;;QACrB,OAAO,MAAA,IAAI,CAAC,OAAO,CAAC,YAAY,mCAAI,GAAG,CAAA;IACzC,CAAC;IAED,mEAAmE;IACnE,IAAW,qBAAqB;;QAC9B,OAAO,MAAA,IAAI,CAAC,OAAO,CAAC,qBAAqB,mCAAI,IAAI,CAAA;IACnD,CAAC;CACF;AAhBD,kDAgBC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { TenantRecord } from '../repository';
|
|
2
|
+
import type { AgentContextProvider, UpdateAssistantUpdateOptions } from '@credo-ts/core';
|
|
3
|
+
import { AgentContext, EventEmitter, Logger } from '@credo-ts/core';
|
|
4
|
+
import { TenantRecordService } from '../services';
|
|
5
|
+
import { TenantSessionCoordinator } from './TenantSessionCoordinator';
|
|
6
|
+
export declare class TenantAgentContextProvider implements AgentContextProvider {
|
|
7
|
+
private tenantRecordService;
|
|
8
|
+
private rootAgentContext;
|
|
9
|
+
private eventEmitter;
|
|
10
|
+
private logger;
|
|
11
|
+
private tenantSessionCoordinator;
|
|
12
|
+
constructor(tenantRecordService: TenantRecordService, rootAgentContext: AgentContext, eventEmitter: EventEmitter, tenantSessionCoordinator: TenantSessionCoordinator, logger: Logger);
|
|
13
|
+
getAgentContextForContextCorrelationId(contextCorrelationId: string): Promise<AgentContext>;
|
|
14
|
+
getContextForInboundMessage(inboundMessage: unknown, options?: {
|
|
15
|
+
contextCorrelationId?: string;
|
|
16
|
+
}): Promise<AgentContext>;
|
|
17
|
+
endSessionForAgentContext(agentContext: AgentContext): Promise<void>;
|
|
18
|
+
private getRecipientKeysFromEncryptedMessage;
|
|
19
|
+
private registerRecipientKeyForTenant;
|
|
20
|
+
private listenForRoutingKeyCreatedEvents;
|
|
21
|
+
/**
|
|
22
|
+
* Method to allow updating the tenant storage, this method can be called from the TenantsApi
|
|
23
|
+
* to update the storage for a tenant manually
|
|
24
|
+
*/
|
|
25
|
+
updateTenantStorage(tenantRecord: TenantRecord, updateOptions?: UpdateAssistantUpdateOptions): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Handle the case where the tenant storage is outdated. If auto-update is disabled we will throw an error
|
|
28
|
+
* and not update the storage. If auto-update is enabled we will update the storage.
|
|
29
|
+
*
|
|
30
|
+
* When this method is called we can be sure that we are in the mutex runExclusive lock and thus other sessions
|
|
31
|
+
* will not be able to open a session for this tenant until we're done.
|
|
32
|
+
*
|
|
33
|
+
* NOTE: We don't support multi-instance locking for now. That means you can only have a single instance open and
|
|
34
|
+
* it will prevent multiple processes from updating the tenant storage at the same time. However if multi-instances
|
|
35
|
+
* are used, we can't prevent multiple instances from updating the tenant storage at the same time.
|
|
36
|
+
* In the future we can make the tenantSessionCoordinator an interface and allowing a instance-tenant-lock as well
|
|
37
|
+
* as an tenant-lock (across all instances)
|
|
38
|
+
*/
|
|
39
|
+
private _updateTenantStorage;
|
|
40
|
+
}
|