@credo-ts/tenants 0.5.0-alpha.129 → 0.5.0-alpha.131

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.
@@ -1,15 +1,16 @@
1
- import type { CreateTenantOptions, GetTenantAgentOptions, WithTenantAgentCallback } from './TenantsApiOptions';
1
+ import type { CreateTenantOptions, GetTenantAgentOptions, UpdateTenantStorageOptions, WithTenantAgentCallback } from './TenantsApiOptions';
2
2
  import type { TenantRecord } from './repository';
3
3
  import type { DefaultAgentModules, ModulesMap, Query } from '@credo-ts/core';
4
- import { AgentContext, AgentContextProvider, Logger } from '@credo-ts/core';
4
+ import { AgentContext, Logger } from '@credo-ts/core';
5
5
  import { TenantAgent } from './TenantAgent';
6
+ import { TenantAgentContextProvider } from './context/TenantAgentContextProvider';
6
7
  import { TenantRecordService } from './services';
7
8
  export declare class TenantsApi<AgentModules extends ModulesMap = DefaultAgentModules> {
8
9
  readonly rootAgentContext: AgentContext;
9
10
  private tenantRecordService;
10
11
  private agentContextProvider;
11
12
  private logger;
12
- constructor(tenantRecordService: TenantRecordService, rootAgentContext: AgentContext, agentContextProvider: AgentContextProvider, logger: Logger);
13
+ constructor(tenantRecordService: TenantRecordService, rootAgentContext: AgentContext, agentContextProvider: TenantAgentContextProvider, logger: Logger);
13
14
  getTenantAgent({ tenantId }: GetTenantAgentOptions): Promise<TenantAgent<AgentModules>>;
14
15
  withTenantAgent(options: GetTenantAgentOptions, withTenantAgentCallback: WithTenantAgentCallback<AgentModules>): Promise<void>;
15
16
  createTenant(options: CreateTenantOptions): Promise<TenantRecord>;
@@ -19,4 +20,6 @@ export declare class TenantsApi<AgentModules extends ModulesMap = DefaultAgentMo
19
20
  updateTenant(tenant: TenantRecord): Promise<void>;
20
21
  findTenantsByQuery(query: Query<TenantRecord>): Promise<TenantRecord[]>;
21
22
  getAllTenants(): Promise<TenantRecord[]>;
23
+ updateTenantStorage({ tenantId, updateOptions }: UpdateTenantStorageOptions): Promise<void>;
24
+ getTenantsWithOutdatedStorage(): Promise<TenantRecord[]>;
22
25
  }
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.TenantsApi = void 0;
16
16
  const core_1 = require("@credo-ts/core");
17
17
  const TenantAgent_1 = require("./TenantAgent");
18
+ const TenantAgentContextProvider_1 = require("./context/TenantAgentContextProvider");
18
19
  const services_1 = require("./services");
19
20
  let TenantsApi = class TenantsApi {
20
21
  constructor(tenantRecordService, rootAgentContext, agentContextProvider, logger) {
@@ -85,13 +86,31 @@ let TenantsApi = class TenantsApi {
85
86
  this.logger.debug('Getting all tenants');
86
87
  return this.tenantRecordService.getAllTenants(this.rootAgentContext);
87
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
+ }
88
106
  };
89
107
  TenantsApi = __decorate([
90
108
  (0, core_1.injectable)(),
91
109
  __param(2, (0, core_1.inject)(core_1.InjectionSymbols.AgentContextProvider)),
92
110
  __param(3, (0, core_1.inject)(core_1.InjectionSymbols.Logger)),
93
111
  __metadata("design:paramtypes", [services_1.TenantRecordService,
94
- core_1.AgentContext, Object, Object])
112
+ core_1.AgentContext,
113
+ TenantAgentContextProvider_1.TenantAgentContextProvider, Object])
95
114
  ], TenantsApi);
96
115
  exports.Ten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AAC,CAAA;qCAHX,8BAAmB;QACtB,mBAAY;QACuC,uDAA0B;GATtF,UAAU,CAuHtB;AAvHY,gCAAU"}
@@ -1,6 +1,6 @@
1
1
  import type { TenantAgent } from './TenantAgent';
2
2
  import type { TenantConfig } from './models/TenantConfig';
3
- import type { ModulesMap } from '@credo-ts/core';
3
+ import type { ModulesMap, UpdateAssistantUpdateOptions } from '@credo-ts/core';
4
4
  export interface GetTenantAgentOptions {
5
5
  tenantId: string;
6
6
  }
@@ -8,3 +8,7 @@ export type WithTenantAgentCallback<AgentModules extends ModulesMap> = (tenantAg
8
8
  export interface CreateTenantOptions {
9
9
  config: Omit<TenantConfig, 'walletConfig'>;
10
10
  }
11
+ export interface UpdateTenantStorageOptions {
12
+ tenantId: string;
13
+ updateOptions?: UpdateAssistantUpdateOptions;
14
+ }
@@ -1,4 +1,5 @@
1
- import type { AgentContextProvider } from '@credo-ts/core';
1
+ import type { TenantRecord } from '../repository';
2
+ import type { AgentContextProvider, UpdateAssistantUpdateOptions } from '@credo-ts/core';
2
3
  import { AgentContext, EventEmitter, Logger } from '@credo-ts/core';
3
4
  import { TenantRecordService } from '../services';
4
5
  import { TenantSessionCoordinator } from './TenantSessionCoordinator';
@@ -17,4 +18,23 @@ export declare class TenantAgentContextProvider implements AgentContextProvider
17
18
  private getRecipientKeysFromEncryptedMessage;
18
19
  private registerRecipientKeyForTenant;
19
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;
20
40
  }
@@ -14,6 +14,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.TenantAgentContextProvider = void 0;
16
16
  const core_1 = require("@credo-ts/core");
17
+ const TenantAgent_1 = require("../TenantAgent");
17
18
  const services_1 = require("../services");
18
19
  const TenantSessionCoordinator_1 = require("./TenantSessionCoordinator");
19
20
  let TenantAgentContextProvider = class TenantAgentContextProvider {
@@ -29,7 +30,17 @@ let TenantAgentContextProvider = class TenantAgentContextProvider {
29
30
  async getAgentContextForContextCorrelationId(tenantId) {
30
31
  // TODO: maybe we can look at not having to retrieve the tenant record if there's already a context available.
31
32
  const tenantRecord = await this.tenantRecordService.getTenantById(this.rootAgentContext, tenantId);
32
- const agentContext = this.tenantSessionCoordinator.getContextForSession(tenantRecord);
33
+ const shouldUpdate = !(0, core_1.isStorageUpToDate)(tenantRecord.storageVersion);
34
+ // If the tenant storage is not up to date, and autoUpdate is disabled we throw an error
35
+ if (shouldUpdate && !this.rootAgentContext.config.autoUpdateStorageOnStartup) {
36
+ throw new core_1.CredoError(`Current agent storage for tenant ${tenantRecord.id} is not up to date. ` +
37
+ `To prevent the tenant state from getting corrupted the tenant initialization is aborted. ` +
38
+ `Make sure to update the tenant storage (currently at ${tenantRecord.storageVersion}) to the latest version (${core_1.UpdateAssistant.frameworkStorageVersion}). ` +
39
+ `You can also downgrade your version of Credo.`);
40
+ }
41
+ const agentContext = await this.tenantSessionCoordinator.getContextForSession(tenantRecord, {
42
+ runInMutex: shouldUpdate ? (agentContext) => this._updateTenantStorage(tenantRecord, agentContext) : undefined,
43
+ });
33
44
  this.logger.debug(`Created tenant agent context for tenant '${tenantId}'`);
34
45
  return agentContext;
35
46
  }
@@ -103,6 +114,48 @@ let TenantAgentContextProvider = class TenantAgentContextProvider {
103
114
  await this.registerRecipientKeyForTenant(contextCorrelationId, recipientKey);
104
115
  });
105
116
  }
117
+ /**
118
+ * Method to allow updating the tenant storage, this method can be called from the TenantsApi
119
+ * to update the storage for a tenant manually
120
+ */
121
+ async updateTenantStorage(tenantRecord, updateOptions) {
122
+ await this.tenantSessionCoordinator.getContextForSession(tenantRecord, {
123
+ // runInMutex allows us to run the updateTenantStorage method in a mutex lock
124
+ // prevent other sessions from being started while the update is in progress
125
+ runInMutex: (agentContext) => this._updateTenantStorage(tenantRecord, agentContext, updateOptions),
126
+ });
127
+ }
128
+ /**
129
+ * Handle the case where the tenant storage is outdated. If auto-update is disabled we will throw an error
130
+ * and not update the storage. If auto-update is enabled we will update the storage.
131
+ *
132
+ * When this method is called we can be sure that we are in the mutex runExclusive lock and thus other sessions
133
+ * will not be able to open a session for this tenant until we're done.
134
+ *
135
+ * NOTE: We don't support multi-instance locking for now. That means you can only have a single instance open and
136
+ * it will prevent multiple processes from updating the tenant storage at the same time. However if multi-instances
137
+ * are used, we can't prevent multiple instances from updating the tenant storage at the same time.
138
+ * In the future we can make the tenantSessionCoordinator an interface and allowing a instance-tenant-lock as well
139
+ * as an tenant-lock (across all instances)
140
+ */
141
+ async _updateTenantStorage(tenantRecord, agentContext, updateOptions) {
142
+ var _a;
143
+ try {
144
+ // Update the tenant storage
145
+ const tenantAgent = new TenantAgent_1.TenantAgent(agentContext);
146
+ const updateAssistant = new core_1.UpdateAssistant(tenantAgent);
147
+ await updateAssistant.initialize();
148
+ await updateAssistant.update(Object.assign(Object.assign({}, updateOptions), { backupBeforeStorageUpdate: (_a = updateOptions === null || updateOptions === void 0 ? void 0 : updateOptions.backupBeforeStorageUpdate) !== null && _a !== void 0 ? _a : agentContext.config.backupBeforeStorageUpdate }));
149
+ // Update the storage version in the tenant record
150
+ tenantRecord.storageVersion = await updateAssistant.getCurrentAgentStorageVersion();
151
+ const tenantRecordService = this.rootAgentContext.dependencyManager.resolve(services_1.TenantRecordService);
152
+ await tenantRecordService.updateTenant(this.rootAgentContext, tenantRecord);
153
+ }
154
+ catch (error) {
155
+ this.logger.error(`Error occurred while updating tenant storage for tenant ${tenantRecord.id}`, error);
156
+ throw error;
157
+ }
158
+ }
106
159
  };
107
160
  TenantAgentContextProvider = __decorate([
108
161
  (0, core_1.injectable)(),
@@ -1 +1 @@
1
- {"version":3,"file":"TenantAgentContextProvider.js","sourceRoot":"","sources":["../../src/context/TenantAgentContextProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yCAcuB;AAEvB,0CAAiD;AAEjD,yEAAqE;AAG9D,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAOrC,YACE,mBAAwC,EACxC,gBAA8B,EAC9B,YAA0B,EAC1B,wBAAkD,EACjB,MAAc;QAE/C,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAC9C,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAA;QACxD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,8GAA8G;QAC9G,IAAI,CAAC,gCAAgC,EAAE,CAAA;IACzC,CAAC;IAEM,KAAK,CAAC,sCAAsC,CAAC,QAAgB;QAClE,8GAA8G;QAC9G,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAA;QAClG,MAAM,YAAY,GAAG,IAAI,CAAC,wBAAwB,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAA;QAErF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4CAA4C,QAAQ,GAAG,CAAC,CAAA;QAE1E,OAA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C,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;;OAYG;IACK,KAAK,CAAC,oBAAoB,CAChC,YAA0B,EAC1B,YAA0B,EAC1B,aAA4C;;QAE5C,IAAI;YACF,4BAA4B;YAC5B,MAAM,WAAW,GAAG,IAAI,yBAAW,CAAC,YAAY,CAAC,CAAA;YACjD,MAAM,eAAe,GAAG,IAAI,sBAAe,CAAC,WAAW,CAAC,CAAA;YACxD,MAAM,eAAe,CAAC,UAAU,EAAE,CAAA;YAClC,MAAM,eAAe,CAAC,MAAM,iCACvB,aAAa,KAChB,yBAAyB,EACvB,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,yBAAyB,mCAAI,YAAY,CAAC,MAAM,CAAC,yBAAyB,IAC3F,CAAA;YAEF,kDAAkD;YAClD,YAAY,CAAC,cAAc,GAAG,MAAM,eAAe,CAAC,6BAA6B,EAAE,CAAA;YACnF,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,OAAO,CAAC,8BAAmB,CAAC,CAAA;YAChG,MAAM,mBAAmB,CAAC,YAAY,CAAC,IAAI,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAA;SAC5E;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2DAA2D,YAAY,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,CAAA;YACtG,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF,CAAA;AA7LY,0BAA0B;IADtC,IAAA,iBAAU,GAAE;IAaR,WAAA,IAAA,aAAM,EAAC,uBAAgB,CAAC,MAAM,CAAC,CAAA;qCAJX,8BAAmB;QACtB,mBAAY;QAChB,mBAAY;QACA,mDAAwB;GAXzC,0BAA0B,CA6LtC;AA7LY,gEAA0B"}
@@ -24,8 +24,13 @@ export declare class TenantSessionCoordinator {
24
24
  * Get agent context to use for a session. If an agent context for this tenant does not exist yet
25
25
  * it will create it and store it for later use. If the agent context does already exist it will
26
26
  * be returned.
27
+ *
28
+ * @parm tenantRecord The tenant record for which to get the agent context
27
29
  */
28
- getContextForSession(tenantRecord: TenantRecord): Promise<AgentContext>;
30
+ getContextForSession(tenantRecord: TenantRecord, { runInMutex, }?: {
31
+ /** optional callback that will be run inside the mutex lock */
32
+ runInMutex?: (agentContext: AgentContext) => Promise<void>;
33
+ }): Promise<AgentContext>;
29
34
  /**
30
35
  * End a session for the provided agent context. It will decrease the session count for the agent context.
31
36
  * If the number of sessions is zero after the context for this session has been ended, the agent context will be closed.
@@ -45,16 +45,18 @@ let TenantSessionCoordinator = class TenantSessionCoordinator {
45
45
  this.rootAgentContext = rootAgentContext;
46
46
  this.logger = logger;
47
47
  this.tenantsModuleConfig = tenantsModuleConfig;
48
- // TODO: we should make the timeout and the session limit configurable, but until we have the modularization in place with
49
- // module specific config, it's not easy to do so. Keeping it hardcoded for now
50
- this.sessionMutex = new TenantSessionMutex_1.TenantSessionMutex(this.logger, this.tenantsModuleConfig.sessionLimit, this.tenantsModuleConfig.sessionAcquireTimeout);
48
+ this.sessionMutex = new TenantSessionMutex_1.TenantSessionMutex(this.logger, this.tenantsModuleConfig.sessionLimit,
49
+ // TODO: we should probably allow a higher session acquire timeout if the storage is being updated?
50
+ this.tenantsModuleConfig.sessionAcquireTimeout);
51
51
  }
52
52
  /**
53
53
  * Get agent context to use for a session. If an agent context for this tenant does not exist yet
54
54
  * it will create it and store it for later use. If the agent context does already exist it will
55
55
  * be returned.
56
+ *
57
+ * @parm tenantRecord The tenant record for which to get the agent context
56
58
  */
57
- async getContextForSession(tenantRecord) {
59
+ async getContextForSession(tenantRecord, { runInMutex, } = {}) {
58
60
  this.logger.debug(`Getting context for session with tenant '${tenantRecord.id}'`);
59
61
  // Wait for a session to be available
60
62
  await this.sessionMutex.acquireSession();
@@ -71,6 +73,9 @@ let TenantSessionCoordinator = class TenantSessionCoordinator {
71
73
  // the session count.
72
74
  tenantSessions.sessionCount++;
73
75
  this.logger.debug(`Increased agent context session count for tenant '${tenantRecord.id}' to ${tenantSessions.sessionCount}`);
76
+ if (runInMutex) {
77
+ await runInMutex(tenantSessions.agentContext);
78
+ }
74
79
  return tenantSessions.agentContext;
75
80
  });
76
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"TenantSessionCoordinator.js","sourceRoot":"","sources":["../../src/context/TenantSessionCoordinator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,yCAUuB;AACvB,6CAAgD;AAEhD,gEAA4D;AAE5D,6DAAyD;AAEzD;;;;;;;;;;GAUG;AAEI,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAOnC,YACE,gBAA8B,EACG,MAAc,EAC/C,mBAAwC;QAPlC,8BAAyB,GAA8B,EAAE,CAAA;QAS/D,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAE9C,0HAA0H;QAC1H,+EAA+E;QAC/E,IAAI,CAAC,YAAY,GAAG,IAAI,uCAAkB,CACxC,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,mBAAmB,CAAC,YAAY,EACrC,IAAI,CAAC,mBAAmB,CAAC,qBAAqB,CAC/C,CAAA;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,oBAAoB,CAAC,YAA0B;QAC1D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4CAA4C,YAAY,CAAC,EAAE,GAAG,CAAC,CAAA;QAEjF,qCAAqC;QACrC,MAAM,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,CAAA;QAExC,IAAI;YACF,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;gBACxE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,YAAY,CAAC,EAAE,kBAAkB,CAAC,CAAA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AI,CAAC,MAAM,CAAC,KAAK,CAAC,qCAAqC,YAAY,CAAC,oBAAoB,GAAG,CAAC,CAAA;QAC5F,MAAM,YAAY,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAA;IAChD,CAAC;CACF,CAAA;AAvMY,wBAAwB;IADpC,IAAA,iBAAU,GAAE;IAUR,WAAA,IAAA,aAAM,EAAC,uBAAgB,CAAC,MAAM,CAAC,CAAA;qCADd,mBAAY,UAET,yCAAmB;GAV/B,wBAAwB,CAuMpC;AAvMY,4DAAwB"}
@@ -1,5 +1,5 @@
1
1
  import type { TenantConfig } from '../models/TenantConfig';
2
- import type { RecordTags, TagsBase } from '@credo-ts/core';
2
+ import type { RecordTags, TagsBase, VersionString } from '@credo-ts/core';
3
3
  import { BaseRecord } from '@credo-ts/core';
4
4
  export type TenantRecordTags = RecordTags<TenantRecord>;
5
5
  export interface TenantRecordProps {
@@ -7,16 +7,27 @@ export interface TenantRecordProps {
7
7
  createdAt?: Date;
8
8
  config: TenantConfig;
9
9
  tags?: TagsBase;
10
+ storageVersion: VersionString;
10
11
  }
11
12
  export type DefaultTenantRecordTags = {
12
13
  label: string;
14
+ storageVersion: VersionString;
13
15
  };
14
16
  export declare class TenantRecord extends BaseRecord<DefaultTenantRecordTags> {
15
17
  static readonly type = "TenantRecord";
16
18
  readonly type = "TenantRecord";
17
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;
18
28
  constructor(props: TenantRecordProps);
19
29
  getTags(): {
20
30
  label: string;
31
+ storageVersion: VersionString;
21
32
  };
22
33
  }
@@ -7,15 +7,24 @@ class TenantRecord extends core_1.BaseRecord {
7
7
  var _a, _b, _c;
8
8
  super();
9
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';
10
18
  if (props) {
11
19
  this.id = (_a = props.id) !== null && _a !== void 0 ? _a : core_1.utils.uuid();
12
20
  this.createdAt = (_b = props.createdAt) !== null && _b !== void 0 ? _b : new Date();
13
21
  this._tags = (_c = props.tags) !== null && _c !== void 0 ? _c : {};
14
22
  this.config = props.config;
23
+ this.storageVersion = props.storageVersion;
15
24
  }
16
25
  }
17
26
  getTags() {
18
- return Object.assign(Object.assign({}, this._tags), { label: this.config.label });
27
+ return Object.assign(Object.assign({}, this._tags), { label: this.config.label, storageVersion: this.storageVersion });
19
28
  }
20
29
  }
21
30
  exports.TenantRecord = TenantRecord;
@@ -1 +1 @@
1
- {"version":3,"file":"TenantRecord.js","sourceRoot":"","sources":["../../src/repository/TenantRecord.ts"],"names":[],"mappings":";;;AAGA,yCAAkD;AAelD,MAAa,YAAa,SAAQ,iBAAmC;IAMnE,YAAmB,KAAwB;;QACzC,KAAK,EAAE,CAAA;QALO,SAAI,GAAG,YAAY,CAAC,IAAI,CAAA;QAOtC,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;SAC3B;IACH,CAAC;IAEM,OAAO;QACZ,uCACK,IAAI,CAAC,KAAK,KACb,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,IACzB;IACH,CAAC;;AAtBH,oCAuBC;AAtBwB,iBAAI,GAAG,cAAc,CAAA"}
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"}
@@ -28,6 +28,7 @@ let TenantRecordService = class TenantRecordService {
28
28
  key: walletKey,
29
29
  keyDerivationMethod: core_1.KeyDerivationMethod.Raw,
30
30
  } }),
31
+ storageVersion: core_1.UpdateAssistant.frameworkStorageVersion,
31
32
  });
32
33
  await this.tenantRepository.save(agentContext, tenantRecord);
33
34
  return tenantRecord;
@@ -1 +1 @@
1
- {"version":3,"file":"TenantRecordService.js","sourceRoot":"","sources":["../../src/services/TenantRecordService.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CAChD,YAA0B,EAC1B,YAAiB;QAEjB,OAAO,IAAI,CAAC,uBAAuB,CAAC,kBAAkB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;IACpF,CAAC;IAEM,KAAK,CAAC,sBAAsB,CACjC,YAA0B,EAC1B,QAAgB,EAChB,YAAiB;QAEjB,MAAM,mBAAmB,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,mBAAmB;IAD/B,IAAA,iBAAU,GAAE;qCAK0B,6BAAgB,EAA2B,oCAAuB;GAJ5F,mBAAmB,CA4F/B;AA5FY,kDAAmB"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@credo-ts/tenants",
3
3
  "main": "build/index",
4
4
  "types": "build/index",
5
- "version": "0.5.0-alpha.129+793527c9",
5
+ "version": "0.5.0-alpha.131+7cc33a96",
6
6
  "files": [
7
7
  "build"
8
8
  ],
@@ -24,14 +24,14 @@
24
24
  "test": "jest"
25
25
  },
26
26
  "dependencies": {
27
- "@credo-ts/core": "0.5.0-alpha.129+793527c9",
27
+ "@credo-ts/core": "0.5.0-alpha.131+7cc33a96",
28
28
  "async-mutex": "^0.4.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@credo-ts/node": "0.5.0-alpha.129+793527c9",
31
+ "@credo-ts/node": "0.5.0-alpha.131+7cc33a96",
32
32
  "reflect-metadata": "^0.1.13",
33
33
  "rimraf": "^4.4.0",
34
34
  "typescript": "~4.9.5"
35
35
  },
36
- "gitHead": "793527c9d99ee5ececc5e05c0d05dbd960877fe0"
36
+ "gitHead": "7cc33a96527c757486cea542cb15785236791532"
37
37
  }