@nmshd/app-runtime 1.0.4 → 2.0.0-alpha.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.
Files changed (51) hide show
  1. package/dist/AppConfig.js +12 -0
  2. package/dist/AppConfig.js.map +1 -1
  3. package/dist/AppRuntime.d.ts +7 -6
  4. package/dist/AppRuntime.js +27 -26
  5. package/dist/AppRuntime.js.map +1 -1
  6. package/dist/buildInformation.js +5 -5
  7. package/dist/events/AccountSelectedEvent.d.ts +2 -2
  8. package/dist/events/AccountSelectedEvent.js +3 -3
  9. package/dist/events/AccountSelectedEvent.js.map +1 -1
  10. package/dist/extensibility/AppServices.d.ts +2 -1
  11. package/dist/extensibility/AppServices.js +3 -3
  12. package/dist/extensibility/AppServices.js.map +1 -1
  13. package/dist/extensibility/facades/AppRuntimeFacade.d.ts +1 -1
  14. package/dist/extensibility/facades/AppRuntimeFacade.js +4 -4
  15. package/dist/extensibility/facades/AppRuntimeFacade.js.map +1 -1
  16. package/dist/extensibility/facades/AppStringProcessorFacade.js +2 -2
  17. package/dist/extensibility/facades/AppStringProcessorFacade.js.map +1 -1
  18. package/dist/modules/AppRuntimeModule.d.ts +6 -1
  19. package/dist/modules/AppRuntimeModule.js +19 -0
  20. package/dist/modules/AppRuntimeModule.js.map +1 -1
  21. package/dist/modules/appEvents/AppLaunchModule.d.ts +1 -2
  22. package/dist/modules/appEvents/AppLaunchModule.js +5 -13
  23. package/dist/modules/appEvents/AppLaunchModule.js.map +1 -1
  24. package/dist/modules/appEvents/MailReceivedModule.d.ts +1 -2
  25. package/dist/modules/appEvents/MailReceivedModule.js +5 -10
  26. package/dist/modules/appEvents/MailReceivedModule.js.map +1 -1
  27. package/dist/modules/appEvents/OnboardingChangeReceivedModule.d.ts +1 -2
  28. package/dist/modules/appEvents/OnboardingChangeReceivedModule.js +5 -10
  29. package/dist/modules/appEvents/OnboardingChangeReceivedModule.js.map +1 -1
  30. package/dist/modules/appSync/AppSyncModule.js +6 -3
  31. package/dist/modules/appSync/AppSyncModule.js.map +1 -1
  32. package/dist/modules/pushNotifications/PushNotificationModule.d.ts +4 -7
  33. package/dist/modules/pushNotifications/PushNotificationModule.js +12 -51
  34. package/dist/modules/pushNotifications/PushNotificationModule.js.map +1 -1
  35. package/dist/modules/runtimeEvents/MessageReceivedModule.d.ts +1 -2
  36. package/dist/modules/runtimeEvents/MessageReceivedModule.js +5 -10
  37. package/dist/modules/runtimeEvents/MessageReceivedModule.js.map +1 -1
  38. package/dist/modules/runtimeEvents/RelationshipChangedModule.d.ts +1 -2
  39. package/dist/modules/runtimeEvents/RelationshipChangedModule.js +5 -10
  40. package/dist/modules/runtimeEvents/RelationshipChangedModule.js.map +1 -1
  41. package/dist/multiAccount/AccountServices.js +1 -1
  42. package/dist/multiAccount/AccountServices.js.map +1 -1
  43. package/dist/multiAccount/MultiAccountController.js +3 -3
  44. package/dist/multiAccount/MultiAccountController.js.map +1 -1
  45. package/dist/multiAccount/MultiAccountFacade.js +1 -1
  46. package/dist/multiAccount/MultiAccountFacade.js.map +1 -1
  47. package/dist/multiAccount/data/LocalAccount.js +3 -4
  48. package/dist/multiAccount/data/LocalAccount.js.map +1 -1
  49. package/lib-web/nmshd.app-runtime.js +192 -162
  50. package/lib-web/nmshd.app-runtime.min.js +1 -1
  51. package/package.json +18 -18
@@ -56,6 +56,18 @@ function createAppConfig(...configs) {
56
56
  displayName: "Relationship Changed Module",
57
57
  location: "relationshipChanged",
58
58
  enabled: true
59
+ },
60
+ decider: {
61
+ displayName: "Decider Module",
62
+ name: "DeciderModule",
63
+ location: "@nmshd/runtime:DeciderModule",
64
+ enabled: true
65
+ },
66
+ request: {
67
+ displayName: "Request Module",
68
+ name: "RequestModule",
69
+ location: "@nmshd/runtime:RequestModule",
70
+ enabled: true
59
71
  }
60
72
  }
61
73
  };
@@ -135,18 +147,9 @@ class AppRuntime extends runtime_1.Runtime {
135
147
  get multiAccountController() {
136
148
  return this._multiAccountController;
137
149
  }
138
- get expander() {
139
- return this.getDataViewExpander();
140
- }
141
150
  get accountServices() {
142
151
  return this._accountServices;
143
152
  }
144
- get appServices() {
145
- if (!this._appServices) {
146
- throw AppRuntimeErrors_1.AppRuntimeErrors.general.appServicesUnavailable().logWith(this.logger);
147
- }
148
- return this._appServices;
149
- }
150
153
  get nativeEnvironment() {
151
154
  return this._nativeEnvironment;
152
155
  }
@@ -156,10 +159,10 @@ class AppRuntime extends runtime_1.Runtime {
156
159
  }
157
160
  return this._currentSession.account;
158
161
  }
159
- login(accountController, consumptionController) {
160
- super.login(accountController, consumptionController);
161
- this._appServices = new extensibility_1.AppServices(this);
162
- return this;
162
+ async login(accountController, consumptionController) {
163
+ const services = await super.login(accountController, consumptionController);
164
+ const appServices = new extensibility_1.AppServices(this, services.transportServices, services.consumptionServices, services.dataViewExpander);
165
+ return { ...services, appServices };
163
166
  }
164
167
  get currentSession() {
165
168
  if (!this._currentSession) {
@@ -167,6 +170,19 @@ class AppRuntime extends runtime_1.Runtime {
167
170
  }
168
171
  return this._currentSession;
169
172
  }
173
+ getServices(address) {
174
+ const addressString = typeof address === "string" ? address : address.toString();
175
+ const session = this._availableSessions.find((session) => session.address === addressString);
176
+ if (!session) {
177
+ throw new Error(`Account ${addressString} not logged in.`);
178
+ }
179
+ return {
180
+ transportServices: session.transportServices,
181
+ consumptionServices: session.consumptionServices,
182
+ appServices: session.appServices,
183
+ dataViewExpander: session.expander
184
+ };
185
+ }
170
186
  getSessions() {
171
187
  return this._availableSessions.map((session) => session.account);
172
188
  }
@@ -214,7 +230,7 @@ class AppRuntime extends runtime_1.Runtime {
214
230
  return await this._selectAccountPromise;
215
231
  }
216
232
  if (availableSession) {
217
- this.login(availableSession.accountController, availableSession.consumptionController);
233
+ await this.login(availableSession.accountController, availableSession.consumptionController);
218
234
  this._currentSession = availableSession;
219
235
  this.eventBus.publish(new events_1.AccountSelectedEvent(availableSession.address, availableSession.account.id));
220
236
  return availableSession.account;
@@ -235,17 +251,17 @@ class AppRuntime extends runtime_1.Runtime {
235
251
  throw AppRuntimeErrors_1.AppRuntimeErrors.general.addressUnavailable().logWith(this.logger);
236
252
  }
237
253
  const consumptionController = await new consumption_1.ConsumptionController(this.transport, accountController).init();
238
- this.login(accountController, consumptionController);
254
+ const services = await this.login(accountController, consumptionController);
239
255
  this.logger.debug(`Finished login to ${accountId}.`);
240
256
  const session = {
241
257
  address: localAccount.address.toString(),
242
258
  account: multiAccount_1.LocalAccountMapper.toLocalAccountDTO(localAccount),
243
- consumptionServices: this.consumptionServices,
244
- transportServices: this.transportServices,
245
- expander: this.getDataViewExpander(),
246
- appServices: this.appServices,
247
- accountController: accountController,
248
- consumptionController: consumptionController
259
+ consumptionServices: services.consumptionServices,
260
+ transportServices: services.transportServices,
261
+ expander: services.dataViewExpander,
262
+ appServices: services.appServices,
263
+ accountController,
264
+ consumptionController
249
265
  };
250
266
  this._availableSessions.push(session);
251
267
  this._currentSession = session;
@@ -279,7 +295,7 @@ class AppRuntime extends runtime_1.Runtime {
279
295
  this._currentSession.selectedRelationship = undefined;
280
296
  return;
281
297
  }
282
- const result = await this.appServices.relationships.renderRelationship(id);
298
+ const result = await this.currentSession.appServices.relationships.renderRelationship(id);
283
299
  if (result.isError) {
284
300
  throw result.error;
285
301
  }
@@ -349,10 +365,7 @@ class AppRuntime extends runtime_1.Runtime {
349
365
  return Promise.reject(error);
350
366
  }
351
367
  const connectorModuleConfiguration = moduleConfiguration;
352
- const module = new moduleConstructor();
353
- module.runtime = this;
354
- module.configuration = connectorModuleConfiguration;
355
- module.logger = this.loggerFactory.getLogger(moduleConstructor);
368
+ const module = new moduleConstructor(this, connectorModuleConfiguration, this.loggerFactory.getLogger(moduleConstructor));
356
369
  this.modules.add(module);
357
370
  this.logger.info(`Module '${this.getModuleName(moduleConfiguration)}' was loaded successfully.`);
358
371
  return Promise.resolve();
@@ -545,11 +558,11 @@ const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
545
558
  const runtime_1 = __webpack_require__(/*! @nmshd/runtime */ "@nmshd/runtime");
546
559
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
547
560
  exports.buildInformation = {
548
- version: "1.0.4",
549
- build: "5",
550
- date: "2022-03-08T08:49:34+00:00",
551
- commit: "6074b326e1acab736dc4078dd56b79d6ffbe084d",
552
- dependencies: {"@js-soft/docdb-access-loki":"^1.0.2","@js-soft/native-abstractions":"^1.0.3","@nmshd/runtime":"1.3.5","lodash":"^4.17.21"},
561
+ version: "2.0.0-alpha.1",
562
+ build: "10",
563
+ date: "2022-06-01T20:24:29+00:00",
564
+ commit: "a154d97b354e9610ad6d3f6fbe8db88e865393eb",
565
+ dependencies: {"@js-soft/docdb-access-loki":"^1.0.2","@js-soft/native-abstractions":"^1.1.0","@nmshd/runtime":"2.0.0-alpha.13","lodash":"^4.17.21"},
553
566
  libraries: {
554
567
  serval: ts_serval_1.buildInformation,
555
568
  crypto: crypto_1.buildInformation,
@@ -577,10 +590,10 @@ const runtime_1 = __webpack_require__(/*! @nmshd/runtime */ "@nmshd/runtime");
577
590
  class AccountSelectedEvent extends runtime_1.DataEvent {
578
591
  /**
579
592
  * Create an AccountSelected Event
580
- * @param accountId The accountId of the selected account.
593
+ * @param localAccountId The accountId of the selected account.
581
594
  */
582
- constructor(address, accountId) {
583
- super(AccountSelectedEvent.namespace, address, { localAccountId: accountId, address: address });
595
+ constructor(address, localAccountId) {
596
+ super(AccountSelectedEvent.namespace, address, { localAccountId, address });
584
597
  }
585
598
  }
586
599
  exports.AccountSelectedEvent = AccountSelectedEvent;
@@ -777,9 +790,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
777
790
  exports.AppServices = void 0;
778
791
  const facades_1 = __webpack_require__(/*! ./facades */ "./dist/extensibility/facades/index.js");
779
792
  class AppServices {
780
- constructor(appRuntime) {
781
- this.relationships = new facades_1.AppRelationshipFacade(appRuntime);
782
- this.stringProcessor = new facades_1.AppStringProcessorFacade(appRuntime);
793
+ constructor(appRuntime, transportServices, consumptionServices, expander) {
794
+ this.relationships = new facades_1.AppRelationshipFacade(appRuntime, transportServices, consumptionServices, expander);
795
+ this.stringProcessor = new facades_1.AppStringProcessorFacade(appRuntime, transportServices, consumptionServices, expander);
783
796
  }
784
797
  }
785
798
  exports.AppServices = AppServices;
@@ -898,11 +911,11 @@ exports.AppRuntimeFacade = void 0;
898
911
  const UserfriendlyApplicationError_1 = __webpack_require__(/*! ../../UserfriendlyApplicationError */ "./dist/UserfriendlyApplicationError.js");
899
912
  const UserfriendlyResult_1 = __webpack_require__(/*! ../../UserfriendlyResult */ "./dist/UserfriendlyResult.js");
900
913
  class AppRuntimeFacade {
901
- constructor(runtime) {
914
+ constructor(runtime, transportServices, consumptionServices, expander) {
902
915
  this.runtime = runtime;
903
- this.transportServices = runtime.transportServices;
904
- this.consumptionServices = runtime.consumptionServices;
905
- this.expander = runtime.expander;
916
+ this.transportServices = transportServices;
917
+ this.consumptionServices = consumptionServices;
918
+ this.expander = expander;
906
919
  }
907
920
  async parseErrorResult(result) {
908
921
  const userfriendlyMessageResult = await this.runtime.translate(result.error.code);
@@ -970,9 +983,9 @@ class AppStringProcessorFacade extends AppRuntimeFacade_1.AppRuntimeFacade {
970
983
  const content = tokenDTO.content;
971
984
  const uiBridge = await this.runtime.uiBridge();
972
985
  try {
973
- const tokenContent = await ts_serval_1.SerializableAsync.fromUnknown(content);
986
+ const tokenContent = ts_serval_1.Serializable.fromUnknown(content);
974
987
  if (tokenContent instanceof transport_1.TokenContentRelationshipTemplate) {
975
- const templateResult = await this.runtime.transportServices.relationshipTemplates.loadPeerRelationshipTemplate({
988
+ const templateResult = await this.transportServices.relationshipTemplates.loadPeerRelationshipTemplate({
976
989
  id: tokenContent.templateId.toString(),
977
990
  secretKey: tokenContent.secretKey.toBase64()
978
991
  });
@@ -1128,6 +1141,25 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
1128
1141
  exports.AppRuntimeModule = void 0;
1129
1142
  const runtime_1 = __webpack_require__(/*! @nmshd/runtime */ "@nmshd/runtime");
1130
1143
  class AppRuntimeModule extends runtime_1.RuntimeModule {
1144
+ constructor() {
1145
+ super(...arguments);
1146
+ this.registeredNativeEventSubscriptions = [];
1147
+ }
1148
+ subscribeToNativeEvent(event, handler) {
1149
+ const subscriptionResult = this.runtime.nativeEnvironment.eventBus.subscribe(event, handler);
1150
+ if (subscriptionResult.isError) {
1151
+ this.logger.error(subscriptionResult.error);
1152
+ throw subscriptionResult.error;
1153
+ }
1154
+ this.registeredNativeEventSubscriptions.push({ id: subscriptionResult.value, target: event });
1155
+ }
1156
+ unsubscribeFromAllEvents() {
1157
+ super.unsubscribeFromAllEvents();
1158
+ for (const subscription of this.registeredNativeEventSubscriptions) {
1159
+ this.runtime.nativeEnvironment.eventBus.unsubscribe(subscription.target, subscription.id);
1160
+ }
1161
+ this.registeredNativeEventSubscriptions.splice(0);
1162
+ }
1131
1163
  }
1132
1164
  exports.AppRuntimeModule = AppRuntimeModule;
1133
1165
  //# sourceMappingURL=AppRuntimeModule.js.map
@@ -1154,22 +1186,14 @@ class AppLaunchModule extends AppRuntimeModule_1.AppRuntimeModule {
1154
1186
  async init() {
1155
1187
  // Nothing to do here
1156
1188
  }
1157
- async urlOpenEventListener(event) {
1158
- await this.runtime.appServices.stringProcessor.processURL(event.url);
1159
- }
1160
1189
  start() {
1161
- const subscriptionResult = this.runtime.nativeEnvironment.eventBus.subscribe(native_abstractions_1.UrlOpenEvent, this.urlOpenEventListener.bind(this));
1162
- if (subscriptionResult.isError) {
1163
- this.logger.error(subscriptionResult.error);
1164
- }
1165
- else {
1166
- this.urlOpenSubscriptionId = subscriptionResult.value;
1167
- }
1190
+ this.subscribeToNativeEvent(native_abstractions_1.UrlOpenEvent, this.handleUrlOpen.bind(this));
1191
+ }
1192
+ async handleUrlOpen(event) {
1193
+ await this.runtime.currentSession.appServices.stringProcessor.processURL(event.url);
1168
1194
  }
1169
1195
  stop() {
1170
- if (this.urlOpenSubscriptionId) {
1171
- this.runtime.nativeEnvironment.eventBus.unsubscribe(native_abstractions_1.UrlOpenEvent, this.urlOpenSubscriptionId);
1172
- }
1196
+ this.unsubscribeFromAllEvents();
1173
1197
  }
1174
1198
  }
1175
1199
  exports.AppLaunchModule = AppLaunchModule;
@@ -1197,7 +1221,10 @@ class MailReceivedModule extends AppRuntimeModule_1.AppRuntimeModule {
1197
1221
  async init() {
1198
1222
  // Nothing to do here
1199
1223
  }
1200
- async mailReceivedListener(event) {
1224
+ start() {
1225
+ this.subscribeToEvent(events_1.MailReceivedEvent, this.handleMailReceived.bind(this));
1226
+ }
1227
+ async handleMailReceived(event) {
1201
1228
  const mail = event.data;
1202
1229
  const session = this.runtime.findSessionByAddress(event.eventTargetAddress);
1203
1230
  if (!session) {
@@ -1211,16 +1238,8 @@ class MailReceivedModule extends AppRuntimeModule_1.AppRuntimeModule {
1211
1238
  }
1212
1239
  });
1213
1240
  }
1214
- start() {
1215
- const subscriptionId = this.runtime.eventBus.subscribe(events_1.MailReceivedEvent, this.mailReceivedListener.bind(this));
1216
- this.subscriptionId = subscriptionId;
1217
- }
1218
1241
  stop() {
1219
- if (!this.subscriptionId) {
1220
- this.logger.warn("No Subscription available.");
1221
- return;
1222
- }
1223
- this.runtime.eventBus.unsubscribe(events_1.MailReceivedEvent, this.subscriptionId);
1242
+ this.unsubscribeFromAllEvents();
1224
1243
  }
1225
1244
  }
1226
1245
  exports.MailReceivedModule = MailReceivedModule;
@@ -1249,7 +1268,10 @@ class OnboardingChangeReceivedModule extends AppRuntimeModule_1.AppRuntimeModule
1249
1268
  async init() {
1250
1269
  // Nothing to do here
1251
1270
  }
1252
- async onboardingChangeReceivedHandler(event) {
1271
+ start() {
1272
+ this.subscribeToEvent(events_1.OnboardingChangeReceivedEvent, this.handleOnboardingChangeReceived.bind(this));
1273
+ }
1274
+ async handleOnboardingChangeReceived(event) {
1253
1275
  const change = event.data.change;
1254
1276
  const identity = event.data.identity;
1255
1277
  let title = "";
@@ -1283,16 +1305,8 @@ class OnboardingChangeReceivedModule extends AppRuntimeModule_1.AppRuntimeModule
1283
1305
  }
1284
1306
  });
1285
1307
  }
1286
- start() {
1287
- const subscriptionId = this.runtime.eventBus.subscribe(events_1.OnboardingChangeReceivedEvent, this.onboardingChangeReceivedHandler.bind(this));
1288
- this.subscriptionId = subscriptionId;
1289
- }
1290
1308
  stop() {
1291
- if (!this.subscriptionId) {
1292
- this.logger.warn("No Subscription available.");
1293
- return;
1294
- }
1295
- this.runtime.eventBus.unsubscribe(events_1.MailReceivedEvent, this.subscriptionId);
1309
+ this.unsubscribeFromAllEvents();
1296
1310
  }
1297
1311
  }
1298
1312
  exports.OnboardingChangeReceivedModule = OnboardingChangeReceivedModule;
@@ -1359,9 +1373,12 @@ class AppSyncModule extends AppRuntimeModule_1.AppRuntimeModule {
1359
1373
  this.started = true;
1360
1374
  }
1361
1375
  async sync() {
1362
- const result = await this.runtime.transportServices.account.syncEverything();
1363
- if (result.isError) {
1364
- this.logger.error(result.error);
1376
+ for (const session of this.runtime.getSessions()) {
1377
+ const services = this.runtime.getServices(session.address);
1378
+ const result = await services.transportServices.account.syncEverything();
1379
+ if (result.isError) {
1380
+ this.logger.error(result.error);
1381
+ }
1365
1382
  }
1366
1383
  if (this.started) {
1367
1384
  this.syncTimeout = setTimeout(() => this.sync(), this.configuration.interval * 1000);
@@ -1476,8 +1493,13 @@ class PushNotificationModule extends AppRuntimeModule_1.AppRuntimeModule {
1476
1493
  async init() {
1477
1494
  // Nothing to do here
1478
1495
  }
1479
- async handleRemoteNotificationEvent(event) {
1480
- this.logger.trace("PushNotificationModule.handleRemoteNotificationEvent", event);
1496
+ start() {
1497
+ this.subscribeToNativeEvent(native_abstractions_1.RemoteNotificationEvent, this.handleRemoteNotification.bind(this));
1498
+ this.subscribeToNativeEvent(native_abstractions_1.RemoteNotificationRegistrationEvent, this.handleTokenRegistration.bind(this));
1499
+ this.subscribeToEvent(events_1.AccountSelectedEvent, this.handleAccountSelected.bind(this));
1500
+ }
1501
+ async handleRemoteNotification(event) {
1502
+ this.logger.trace("PushNotificationModule.handleRemoteNotification", event);
1481
1503
  const notification = event.notification;
1482
1504
  const content = notification.content;
1483
1505
  try {
@@ -1512,9 +1534,9 @@ class PushNotificationModule extends AppRuntimeModule_1.AppRuntimeModule {
1512
1534
  this.logger.error(e);
1513
1535
  }
1514
1536
  }
1515
- async handleTokenRegistrationEvent(event) {
1537
+ async handleTokenRegistration(event) {
1516
1538
  try {
1517
- this.logger.trace("PushNotificationModule.handleTokenRegistrationEvent", event);
1539
+ this.logger.trace("PushNotificationModule.handleTokenRegistration", event);
1518
1540
  for (const account of this.runtime.getSessions()) {
1519
1541
  await this.registerPushTokenForLocalAccount(account.id, event.token);
1520
1542
  }
@@ -1523,9 +1545,9 @@ class PushNotificationModule extends AppRuntimeModule_1.AppRuntimeModule {
1523
1545
  this.logger.error(e);
1524
1546
  }
1525
1547
  }
1526
- async handleAccountSelectedEvent(event) {
1548
+ async handleAccountSelected(event) {
1527
1549
  try {
1528
- this.logger.trace("PushNotificationModule.handleAccountSelectedEvent", event);
1550
+ this.logger.trace("PushNotificationModule.handleAccountSelected", event);
1529
1551
  const tokenResult = this.getNotificationTokenFromConfig();
1530
1552
  if (tokenResult.isSuccess) {
1531
1553
  await this.registerPushTokenForLocalAccount(event.data.localAccountId, tokenResult.value);
@@ -1581,52 +1603,8 @@ class PushNotificationModule extends AppRuntimeModule_1.AppRuntimeModule {
1581
1603
  }
1582
1604
  return ts_utils_1.Result.ok(pushTokenResult.value);
1583
1605
  }
1584
- start() {
1585
- const remoteNotificationResult = this.runtime.nativeEnvironment.eventBus.subscribe(native_abstractions_1.RemoteNotificationEvent, this.handleRemoteNotificationEvent.bind(this));
1586
- if (remoteNotificationResult.isError) {
1587
- throw AppRuntimeErrors_1.AppRuntimeErrors.modules.pushNotificationModule
1588
- .subscriptionNotPossible(remoteNotificationResult.error.message, remoteNotificationResult.error)
1589
- .logWith(this.logger);
1590
- }
1591
- this.subscriptionIdRemoteNotification = remoteNotificationResult.value;
1592
- const tokenRegistrationResult = this.runtime.nativeEnvironment.eventBus.subscribe(native_abstractions_1.RemoteNotificationRegistrationEvent, this.handleTokenRegistrationEvent.bind(this));
1593
- if (tokenRegistrationResult.isError) {
1594
- throw AppRuntimeErrors_1.AppRuntimeErrors.modules.pushNotificationModule
1595
- .subscriptionNotPossible(tokenRegistrationResult.error.message, tokenRegistrationResult.error)
1596
- .logWith(this.logger);
1597
- }
1598
- this.subscriptionIdTokenRegistration = tokenRegistrationResult.value;
1599
- this.subscriptionIdAccountSelection = this.runtime.eventBus.subscribe(events_1.AccountSelectedEvent, this.handleAccountSelectedEvent.bind(this));
1600
- }
1601
1606
  stop() {
1602
- if (!this.subscriptionIdRemoteNotification) {
1603
- this.logger.warn("No RemoteNotificationEvent subscription available.");
1604
- }
1605
- else {
1606
- const result = this.runtime.nativeEnvironment.eventBus.unsubscribe(native_abstractions_1.RemoteNotificationEvent, this.subscriptionIdRemoteNotification);
1607
- if (result.isError) {
1608
- throw AppRuntimeErrors_1.AppRuntimeErrors.modules.pushNotificationModule
1609
- .unsubscriptionNotPossible(result.error.message, result.error)
1610
- .logWith(this.logger);
1611
- }
1612
- }
1613
- if (!this.subscriptionIdTokenRegistration) {
1614
- this.logger.warn("No RemoteNotificationRegistrationEvent subscription available.");
1615
- }
1616
- else {
1617
- const result = this.runtime.nativeEnvironment.eventBus.unsubscribe(native_abstractions_1.RemoteNotificationRegistrationEvent, this.subscriptionIdTokenRegistration);
1618
- if (result.isError) {
1619
- throw AppRuntimeErrors_1.AppRuntimeErrors.modules.pushNotificationModule
1620
- .unsubscriptionNotPossible(result.error.message, result.error)
1621
- .logWith(this.logger);
1622
- }
1623
- }
1624
- if (!this.subscriptionIdAccountSelection) {
1625
- this.logger.warn("No AccountSelectedEvent subscription available.");
1626
- }
1627
- else {
1628
- this.runtime.eventBus.unsubscribe(events_1.AccountSelectedEvent, this.subscriptionIdAccountSelection);
1629
- }
1607
+ this.unsubscribeFromAllEvents();
1630
1608
  }
1631
1609
  }
1632
1610
  exports.PushNotificationModule = PushNotificationModule;
@@ -1684,7 +1662,10 @@ class MessageReceivedModule extends AppRuntimeModule_1.AppRuntimeModule {
1684
1662
  async init() {
1685
1663
  // Nothing to do here
1686
1664
  }
1687
- async messageReceivedEventListener(event) {
1665
+ start() {
1666
+ this.subscribeToEvent(runtime_1.MessageReceivedEvent, this.handleMessageReceived.bind(this));
1667
+ }
1668
+ async handleMessageReceived(event) {
1688
1669
  const message = event.data;
1689
1670
  const session = this.runtime.findSessionByAddress(event.eventTargetAddress);
1690
1671
  if (!session) {
@@ -1708,16 +1689,8 @@ class MessageReceivedModule extends AppRuntimeModule_1.AppRuntimeModule {
1708
1689
  break;
1709
1690
  }
1710
1691
  }
1711
- start() {
1712
- const subscriptionId = this.runtime.eventBus.subscribe(runtime_1.MessageReceivedEvent, this.messageReceivedEventListener.bind(this));
1713
- this.subscriptionId = subscriptionId;
1714
- }
1715
1692
  stop() {
1716
- if (!this.subscriptionId) {
1717
- this.logger.warn("No Subscription available.");
1718
- return;
1719
- }
1720
- this.runtime.eventBus.unsubscribe(runtime_1.MessageReceivedEvent, this.subscriptionId);
1693
+ this.unsubscribeFromAllEvents();
1721
1694
  }
1722
1695
  }
1723
1696
  exports.MessageReceivedModule = MessageReceivedModule;
@@ -1746,7 +1719,10 @@ class RelationshipChangedModule extends AppRuntimeModule_1.AppRuntimeModule {
1746
1719
  async init() {
1747
1720
  // Nothing to do here
1748
1721
  }
1749
- async relationshipChangedHandler(event) {
1722
+ start() {
1723
+ this.subscribeToEvent(runtime_1.RelationshipChangedEvent, this.handleRelationshipChanged.bind(this));
1724
+ }
1725
+ async handleRelationshipChanged(event) {
1750
1726
  const relationship = event.data;
1751
1727
  const session = this.runtime.findSessionByAddress(event.eventTargetAddress);
1752
1728
  if (!session) {
@@ -1764,16 +1740,8 @@ class RelationshipChangedModule extends AppRuntimeModule_1.AppRuntimeModule {
1764
1740
  }
1765
1741
  }
1766
1742
  }
1767
- start() {
1768
- const subscriptionId = this.runtime.eventBus.subscribe(runtime_1.RelationshipChangedEvent, this.relationshipChangedHandler.bind(this));
1769
- this.subscriptionId = subscriptionId;
1770
- }
1771
1743
  stop() {
1772
- if (!this.subscriptionId) {
1773
- this.logger.warn("No Subscription available.");
1774
- return;
1775
- }
1776
- this.runtime.eventBus.unsubscribe(runtime_1.RelationshipChangedEvent, this.subscriptionId);
1744
+ this.unsubscribeFromAllEvents();
1777
1745
  }
1778
1746
  }
1779
1747
  exports.RelationshipChangedModule = RelationshipChangedModule;
@@ -1837,7 +1805,7 @@ class AccountServices {
1837
1805
  return LocalAccountMapper_1.LocalAccountMapper.toLocalAccountDTO(localAccount);
1838
1806
  }
1839
1807
  async onboardAccount(onboardingInfo) {
1840
- const sharedSecret = await runtime_1.DeviceMapper.toDeviceSharedSecret(onboardingInfo);
1808
+ const sharedSecret = runtime_1.DeviceMapper.toDeviceSharedSecret(onboardingInfo);
1841
1809
  const [localAccount] = await this.multiAccountController.onboardDevice(sharedSecret);
1842
1810
  return LocalAccountMapper_1.LocalAccountMapper.toLocalAccountDTO(localAccount);
1843
1811
  }
@@ -1910,7 +1878,7 @@ class MultiAccountController {
1910
1878
  return LocalAccount_1.LocalAccount.from(dbAccount);
1911
1879
  }
1912
1880
  async getAccountByAddress(address) {
1913
- const dbAccount = await this._localAccounts.findOne({ address: address });
1881
+ const dbAccount = await this._localAccounts.findOne({ address });
1914
1882
  if (!dbAccount) {
1915
1883
  throw transport_1.TransportErrors.general.recordNotFound(LocalAccount_1.LocalAccount, address).logWith(this._log);
1916
1884
  }
@@ -1980,8 +1948,8 @@ class MultiAccountController {
1980
1948
  let localAccount = LocalAccount_1.LocalAccount.from({
1981
1949
  id,
1982
1950
  directory: ".",
1983
- realm: realm,
1984
- name: name,
1951
+ realm,
1952
+ name,
1985
1953
  order: -1
1986
1954
  });
1987
1955
  await this._localAccounts.create(localAccount);
@@ -2039,14 +2007,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
2039
2007
  var __metadata = (this && this.__metadata) || function (k, v) {
2040
2008
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2041
2009
  };
2042
- var LocalAccount_1;
2043
2010
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2044
2011
  exports.LocalAccount = void 0;
2045
2012
  const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
2046
2013
  const transport_1 = __webpack_require__(/*! @nmshd/transport */ "@nmshd/transport");
2047
- let LocalAccount = LocalAccount_1 = class LocalAccount extends transport_1.CoreSerializable {
2014
+ let LocalAccount = class LocalAccount extends transport_1.CoreSerializable {
2048
2015
  static from(value) {
2049
- return super.from(value, LocalAccount_1);
2016
+ return this.fromAny(value);
2050
2017
  }
2051
2018
  };
2052
2019
  __decorate([
@@ -2079,7 +2046,7 @@ __decorate([
2079
2046
  (0, ts_serval_1.serialize)(),
2080
2047
  __metadata("design:type", Number)
2081
2048
  ], LocalAccount.prototype, "order", void 0);
2082
- LocalAccount = LocalAccount_1 = __decorate([
2049
+ LocalAccount = __decorate([
2083
2050
  (0, ts_serval_1.type)("LocalAccount")
2084
2051
  ], LocalAccount);
2085
2052
  exports.LocalAccount = LocalAccount;
@@ -2640,6 +2607,19 @@ var AppType;
2640
2607
 
2641
2608
  /***/ }),
2642
2609
 
2610
+ /***/ "./node_modules/@js-soft/native-abstractions/dist/INativeDatabaseFactory.js":
2611
+ /*!**********************************************************************************!*\
2612
+ !*** ./node_modules/@js-soft/native-abstractions/dist/INativeDatabaseFactory.js ***!
2613
+ \**********************************************************************************/
2614
+ /***/ ((__unused_webpack_module, exports) => {
2615
+
2616
+ "use strict";
2617
+
2618
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2619
+ //# sourceMappingURL=INativeDatabaseFactory.js.map
2620
+
2621
+ /***/ }),
2622
+
2643
2623
  /***/ "./node_modules/@js-soft/native-abstractions/dist/INativeDeviceInfoAccess.js":
2644
2624
  /*!***********************************************************************************!*\
2645
2625
  !*** ./node_modules/@js-soft/native-abstractions/dist/INativeDeviceInfoAccess.js ***!
@@ -2650,6 +2630,9 @@ var AppType;
2650
2630
 
2651
2631
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2652
2632
  exports.PushServices = void 0;
2633
+ /**
2634
+ * Type of remote push notification service used
2635
+ */
2653
2636
  var PushServices;
2654
2637
  (function (PushServices) {
2655
2638
  PushServices["apns"] = "apns";
@@ -2696,19 +2679,25 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
2696
2679
 
2697
2680
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2698
2681
  exports.NativeFileStorage = void 0;
2682
+ /**
2683
+ * Available storage locations
2684
+ */
2699
2685
  var NativeFileStorage;
2700
2686
  (function (NativeFileStorage) {
2687
+ /**
2688
+ * Used for storing temporary files
2689
+ */
2701
2690
  NativeFileStorage["Temp"] = "temp";
2702
2691
  /**
2703
- * C:\Users\<user-id>
2692
+ * Home folder of the user
2704
2693
  */
2705
2694
  NativeFileStorage["Home"] = "home";
2706
2695
  /**
2707
- * C:\Users\<user-id>\AppData\Roaming\<app-id>\
2696
+ * Used for storing application data on desktop
2708
2697
  */
2709
2698
  NativeFileStorage["Data"] = "data";
2710
2699
  /**
2711
- * C:\Program Files\<app-id>\
2700
+ * Used for storing application data on mobile
2712
2701
  */
2713
2702
  NativeFileStorage["App"] = "app";
2714
2703
  })(NativeFileStorage = exports.NativeFileStorage || (exports.NativeFileStorage = {}));
@@ -2902,6 +2891,9 @@ exports.NativeEvent = NativeEvent;
2902
2891
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2903
2892
  exports.BackButtonEvent = exports.ThemeEvent = exports.ThemeTextStyle = exports.AppCloseEvent = exports.AppReadyEvent = exports.FileViewEvent = exports.UrlOpenEvent = exports.ConfigurationRemoveEvent = exports.ConfigurationSetEvent = exports.ConfigurationSaveEvent = exports.RemoteNotificationEvent = exports.RemoteNotificationRegistrationEvent = void 0;
2904
2893
  const NativeEvent_1 = __webpack_require__(/*! ./NativeEvent */ "./node_modules/@js-soft/native-abstractions/dist/NativeEvent.js");
2894
+ /**
2895
+ * Event fired when {@link INativePushNotificationAccess} sucessfully received a registration token
2896
+ */
2905
2897
  class RemoteNotificationRegistrationEvent extends NativeEvent_1.NativeEvent {
2906
2898
  constructor(token) {
2907
2899
  super(RemoteNotificationRegistrationEvent.namespace);
@@ -2910,6 +2902,9 @@ class RemoteNotificationRegistrationEvent extends NativeEvent_1.NativeEvent {
2910
2902
  }
2911
2903
  exports.RemoteNotificationRegistrationEvent = RemoteNotificationRegistrationEvent;
2912
2904
  RemoteNotificationRegistrationEvent.namespace = "RemoteNotificationRegistration";
2905
+ /**
2906
+ * Event fired when {@link INativePushNotificationAccess} received a remote notification
2907
+ */
2913
2908
  class RemoteNotificationEvent extends NativeEvent_1.NativeEvent {
2914
2909
  constructor(notification) {
2915
2910
  super(RemoteNotificationEvent.namespace);
@@ -2918,6 +2913,9 @@ class RemoteNotificationEvent extends NativeEvent_1.NativeEvent {
2918
2913
  }
2919
2914
  exports.RemoteNotificationEvent = RemoteNotificationEvent;
2920
2915
  RemoteNotificationEvent.namespace = "RemoteNotification";
2916
+ /**
2917
+ * Event fired when {@link INativeConfigAccess} finishes a save operation
2918
+ */
2921
2919
  class ConfigurationSaveEvent extends NativeEvent_1.NativeEvent {
2922
2920
  constructor() {
2923
2921
  super(ConfigurationSaveEvent.namespace);
@@ -2925,6 +2923,9 @@ class ConfigurationSaveEvent extends NativeEvent_1.NativeEvent {
2925
2923
  }
2926
2924
  exports.ConfigurationSaveEvent = ConfigurationSaveEvent;
2927
2925
  ConfigurationSaveEvent.namespace = "ConfigurationSave";
2926
+ /**
2927
+ * Event fired when {@link INativeConfigAccess} changes the configuration
2928
+ */
2928
2929
  class ConfigurationSetEvent extends NativeEvent_1.NativeEvent {
2929
2930
  constructor(key, value) {
2930
2931
  super(ConfigurationSetEvent.namespace);
@@ -2934,6 +2935,9 @@ class ConfigurationSetEvent extends NativeEvent_1.NativeEvent {
2934
2935
  }
2935
2936
  exports.ConfigurationSetEvent = ConfigurationSetEvent;
2936
2937
  ConfigurationSetEvent.namespace = "ConfigurationSet";
2938
+ /**
2939
+ * Event fired when the {@link INativeConfigAccess} removes a configuration element
2940
+ */
2937
2941
  class ConfigurationRemoveEvent extends NativeEvent_1.NativeEvent {
2938
2942
  constructor(key) {
2939
2943
  super(ConfigurationRemoveEvent.namespace);
@@ -2942,6 +2946,9 @@ class ConfigurationRemoveEvent extends NativeEvent_1.NativeEvent {
2942
2946
  }
2943
2947
  exports.ConfigurationRemoveEvent = ConfigurationRemoveEvent;
2944
2948
  ConfigurationRemoveEvent.namespace = "ConfigurationRemove";
2949
+ /**
2950
+ * Event fired when {@link INativeLaunchOptions} registers, that the app was started by an url
2951
+ */
2945
2952
  class UrlOpenEvent extends NativeEvent_1.NativeEvent {
2946
2953
  constructor(url) {
2947
2954
  super(UrlOpenEvent.namespace);
@@ -2950,6 +2957,9 @@ class UrlOpenEvent extends NativeEvent_1.NativeEvent {
2950
2957
  }
2951
2958
  exports.UrlOpenEvent = UrlOpenEvent;
2952
2959
  UrlOpenEvent.namespace = "UrlOpenEvent";
2960
+ /**
2961
+ * Event fired when {@link INativeLaunchOptions} registers, that the app was started by a file open instruction
2962
+ */
2953
2963
  class FileViewEvent extends NativeEvent_1.NativeEvent {
2954
2964
  constructor(uri) {
2955
2965
  super(FileViewEvent.namespace);
@@ -2958,6 +2968,9 @@ class FileViewEvent extends NativeEvent_1.NativeEvent {
2958
2968
  }
2959
2969
  exports.FileViewEvent = FileViewEvent;
2960
2970
  FileViewEvent.namespace = "FileViewEvent";
2971
+ /**
2972
+ * Event fired when the app is ready
2973
+ */
2961
2974
  class AppReadyEvent extends NativeEvent_1.NativeEvent {
2962
2975
  constructor() {
2963
2976
  super(AppReadyEvent.namespace);
@@ -2965,6 +2978,9 @@ class AppReadyEvent extends NativeEvent_1.NativeEvent {
2965
2978
  }
2966
2979
  exports.AppReadyEvent = AppReadyEvent;
2967
2980
  AppReadyEvent.namespace = "AppReadyEvent";
2981
+ /**
2982
+ * Event fired when the app closes
2983
+ */
2968
2984
  class AppCloseEvent extends NativeEvent_1.NativeEvent {
2969
2985
  constructor() {
2970
2986
  super(AppCloseEvent.namespace);
@@ -2977,6 +2993,9 @@ var ThemeTextStyle;
2977
2993
  ThemeTextStyle["Dark"] = "dark";
2978
2994
  ThemeTextStyle["Light"] = "light";
2979
2995
  })(ThemeTextStyle = exports.ThemeTextStyle || (exports.ThemeTextStyle = {}));
2996
+ /**
2997
+ * Event fired when the app changes theme
2998
+ */
2980
2999
  class ThemeEvent extends NativeEvent_1.NativeEvent {
2981
3000
  constructor(backgroundColor, textStyle, textColor, image) {
2982
3001
  super(ThemeEvent.namespace);
@@ -2988,6 +3007,9 @@ class ThemeEvent extends NativeEvent_1.NativeEvent {
2988
3007
  }
2989
3008
  exports.ThemeEvent = ThemeEvent;
2990
3009
  ThemeEvent.namespace = "ThemeEvent";
3010
+ /**
3011
+ * Event fired when the back button is pressed
3012
+ */
2991
3013
  class BackButtonEvent extends NativeEvent_1.NativeEvent {
2992
3014
  constructor() {
2993
3015
  super(BackButtonEvent.namespace);
@@ -3009,6 +3031,9 @@ BackButtonEvent.namespace = "BackButtonEvent";
3009
3031
 
3010
3032
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3011
3033
  exports.NativePlatform = void 0;
3034
+ /**
3035
+ * Frameworks used to access native functionalities
3036
+ */
3012
3037
  var NativePlatform;
3013
3038
  (function (NativePlatform) {
3014
3039
  NativePlatform["Cordova"] = "Cordova";
@@ -3029,7 +3054,11 @@ var NativePlatform;
3029
3054
 
3030
3055
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3031
3056
  if (k2 === undefined) k2 = k;
3032
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3057
+ var desc = Object.getOwnPropertyDescriptor(m, k);
3058
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
3059
+ desc = { enumerable: true, get: function() { return m[k]; } };
3060
+ }
3061
+ Object.defineProperty(o, k2, desc);
3033
3062
  }) : (function(o, m, k, k2) {
3034
3063
  if (k2 === undefined) k2 = k;
3035
3064
  o[k2] = m[k];
@@ -3041,6 +3070,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3041
3070
  __exportStar(__webpack_require__(/*! ./INativeAuthenticationAccess */ "./node_modules/@js-soft/native-abstractions/dist/INativeAuthenticationAccess.js"), exports);
3042
3071
  __exportStar(__webpack_require__(/*! ./INativeBootstrapper */ "./node_modules/@js-soft/native-abstractions/dist/INativeBootstrapper.js"), exports);
3043
3072
  __exportStar(__webpack_require__(/*! ./INativeConfigAccess */ "./node_modules/@js-soft/native-abstractions/dist/INativeConfigAccess.js"), exports);
3073
+ __exportStar(__webpack_require__(/*! ./INativeDatabaseFactory */ "./node_modules/@js-soft/native-abstractions/dist/INativeDatabaseFactory.js"), exports);
3044
3074
  __exportStar(__webpack_require__(/*! ./INativeDeviceInfoAccess */ "./node_modules/@js-soft/native-abstractions/dist/INativeDeviceInfoAccess.js"), exports);
3045
3075
  __exportStar(__webpack_require__(/*! ./INativeEnvironment */ "./node_modules/@js-soft/native-abstractions/dist/INativeEnvironment.js"), exports);
3046
3076
  __exportStar(__webpack_require__(/*! ./INativeEventBus */ "./node_modules/@js-soft/native-abstractions/dist/INativeEventBus.js"), exports);