@nmshd/transport 2.3.5 → 2.4.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 (72) hide show
  1. package/dist/buildInformation.js +5 -5
  2. package/dist/modules/accounts/AccountController.d.ts +1 -0
  3. package/dist/modules/accounts/AccountController.d.ts.map +1 -1
  4. package/dist/modules/accounts/AccountController.js +3 -0
  5. package/dist/modules/accounts/AccountController.js.map +1 -1
  6. package/dist/modules/devices/DeviceController.d.ts +1 -0
  7. package/dist/modules/devices/DeviceController.d.ts.map +1 -1
  8. package/dist/modules/devices/DeviceController.js +5 -0
  9. package/dist/modules/devices/DeviceController.js.map +1 -1
  10. package/dist/modules/devices/backbone/DeviceAuthClient.d.ts +1 -0
  11. package/dist/modules/devices/backbone/DeviceAuthClient.d.ts.map +1 -1
  12. package/dist/modules/devices/backbone/DeviceAuthClient.js +3 -0
  13. package/dist/modules/devices/backbone/DeviceAuthClient.js.map +1 -1
  14. package/dist/modules/devices/local/Device.d.ts +2 -0
  15. package/dist/modules/devices/local/Device.d.ts.map +1 -1
  16. package/dist/modules/devices/local/Device.js +7 -1
  17. package/dist/modules/devices/local/Device.js.map +1 -1
  18. package/dist/modules/index.d.ts +0 -1
  19. package/dist/modules/index.d.ts.map +1 -1
  20. package/dist/modules/index.js +0 -1
  21. package/dist/modules/index.js.map +1 -1
  22. package/dist/modules/sync/ChangedItems.d.ts +1 -2
  23. package/dist/modules/sync/ChangedItems.d.ts.map +1 -1
  24. package/dist/modules/sync/ChangedItems.js +9 -5
  25. package/dist/modules/sync/ChangedItems.js.map +1 -1
  26. package/dist/modules/sync/DatawalletModificationsProcessor.d.ts +6 -6
  27. package/dist/modules/sync/DatawalletModificationsProcessor.d.ts.map +1 -1
  28. package/dist/modules/sync/DatawalletModificationsProcessor.js +2 -2
  29. package/dist/modules/sync/DatawalletModificationsProcessor.js.map +1 -1
  30. package/dist/modules/sync/SyncController.d.ts +1 -0
  31. package/dist/modules/sync/SyncController.d.ts.map +1 -1
  32. package/dist/modules/sync/SyncController.js +41 -8
  33. package/dist/modules/sync/SyncController.js.map +1 -1
  34. package/dist/modules/sync/backbone/FinalizeSyncRun.d.ts +2 -2
  35. package/dist/modules/sync/backbone/FinalizeSyncRun.d.ts.map +1 -1
  36. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessor.d.ts +14 -0
  37. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessor.d.ts.map +1 -0
  38. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessor.js +14 -0
  39. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessor.js.map +1 -0
  40. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.d.ts +9 -0
  41. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.d.ts.map +1 -0
  42. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.js +35 -0
  43. package/dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.js.map +1 -0
  44. package/dist/modules/sync/externalEventProcessors/MessageDeliveredExternalEventProcessor.d.ts +7 -0
  45. package/dist/modules/sync/externalEventProcessors/MessageDeliveredExternalEventProcessor.d.ts.map +1 -0
  46. package/dist/modules/sync/externalEventProcessors/MessageDeliveredExternalEventProcessor.js +16 -0
  47. package/dist/modules/sync/externalEventProcessors/MessageDeliveredExternalEventProcessor.js.map +1 -0
  48. package/dist/modules/sync/externalEventProcessors/MessageReceivedExternalEventProcessor.d.ts +7 -0
  49. package/dist/modules/sync/externalEventProcessors/MessageReceivedExternalEventProcessor.d.ts.map +1 -0
  50. package/dist/modules/sync/externalEventProcessors/MessageReceivedExternalEventProcessor.js +16 -0
  51. package/dist/modules/sync/externalEventProcessors/MessageReceivedExternalEventProcessor.js.map +1 -0
  52. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.d.ts +7 -0
  53. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.d.ts.map +1 -0
  54. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.js +18 -0
  55. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.js.map +1 -0
  56. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCreatedExternalEventProcessor.d.ts +7 -0
  57. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCreatedExternalEventProcessor.d.ts.map +1 -0
  58. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCreatedExternalEventProcessor.js +18 -0
  59. package/dist/modules/sync/externalEventProcessors/RelationshipChangeCreatedExternalEventProcessor.js.map +1 -0
  60. package/dist/modules/sync/externalEventProcessors/index.d.ts +6 -0
  61. package/dist/modules/sync/externalEventProcessors/index.d.ts.map +1 -0
  62. package/dist/modules/sync/externalEventProcessors/index.js +22 -0
  63. package/dist/modules/sync/externalEventProcessors/index.js.map +1 -0
  64. package/lib-web/nmshd.transport.js +285 -129
  65. package/lib-web/nmshd.transport.js.map +1 -1
  66. package/lib-web/nmshd.transport.min.js +1 -1
  67. package/lib-web/nmshd.transport.min.js.map +1 -1
  68. package/package.json +6 -6
  69. package/dist/modules/sync/ExternalEventsProcessor.d.ts +0 -25
  70. package/dist/modules/sync/ExternalEventsProcessor.d.ts.map +0 -1
  71. package/dist/modules/sync/ExternalEventsProcessor.js +0 -96
  72. package/dist/modules/sync/ExternalEventsProcessor.js.map +0 -1
@@ -33561,11 +33561,11 @@ exports.buildInformation = void 0;
33561
33561
  const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
33562
33562
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
33563
33563
  exports.buildInformation = {
33564
- version: "2.3.5",
33565
- build: "56",
33566
- date: "2024-03-22T09:00:27+00:00",
33567
- commit: "498d7ebebf68df253b9364ff67f0c9798c54655d",
33568
- dependencies: {"@js-soft/docdb-access-abstractions":"1.0.3","@js-soft/logging-abstractions":"^1.0.1","@js-soft/simple-logger":"1.0.4","@js-soft/ts-utils":"^2.3.3","axios":"^1.6.8","fast-json-patch":"^3.1.1","form-data":"^4.0.0","json-stringify-safe":"^5.0.1","lodash":"^4.17.21","luxon":"^3.4.4","qs":"^6.12.0","reflect-metadata":"^0.2.1","ts-simple-nameof":"^1.3.1","uuid":"^9.0.1"},
33564
+ version: "2.4.1",
33565
+ build: "64",
33566
+ date: "2024-04-08T14:17:48+00:00",
33567
+ commit: "2c9d6dbb7fd529de72e9693b07ad44c49073c795",
33568
+ dependencies: {"@js-soft/docdb-access-abstractions":"1.0.4","@js-soft/logging-abstractions":"^1.0.1","@js-soft/simple-logger":"1.0.4","@js-soft/ts-utils":"^2.3.3","axios":"^1.6.8","fast-json-patch":"^3.1.1","form-data":"^4.0.0","json-stringify-safe":"^5.0.1","lodash":"^4.17.21","luxon":"^3.4.4","qs":"^6.12.0","reflect-metadata":"^0.2.2","ts-simple-nameof":"^1.3.1","uuid":"^9.0.1"},
33569
33569
  libraries: {
33570
33570
  crypto: crypto_1.buildInformation,
33571
33571
  serval: ts_serval_1.buildInformation
@@ -36671,6 +36671,9 @@ class AccountController {
36671
36671
  async registerPushNotificationToken(token) {
36672
36672
  await this.deviceAuthClient.registerPushNotificationToken(token);
36673
36673
  }
36674
+ async unregisterPushNotificationToken() {
36675
+ await this.deviceAuthClient.unregisterPushNotificationToken();
36676
+ }
36674
36677
  fetchDeviceInfo() {
36675
36678
  return Promise.resolve({
36676
36679
  operatingSystem: "",
@@ -38243,6 +38246,11 @@ class DeviceController extends core_1.TransportController {
38243
38246
  password: credentials.password
38244
38247
  };
38245
38248
  }
38249
+ async markAsOffboarded() {
38250
+ this.device.isOffboarded = true;
38251
+ await this.parent.devices.update(this.device);
38252
+ await this.parent.syncDatawallet();
38253
+ }
38246
38254
  }
38247
38255
  exports.DeviceController = DeviceController;
38248
38256
  __decorate([
@@ -38626,6 +38634,9 @@ class DeviceAuthClient extends core_1.RESTClientAuthenticate {
38626
38634
  async registerPushNotificationToken(input) {
38627
38635
  return await this.put("/api/v1/Devices/Self/PushNotifications", input);
38628
38636
  }
38637
+ async unregisterPushNotificationToken() {
38638
+ return await this.delete("/api/v1/Devices/Self/PushNotifications");
38639
+ }
38629
38640
  }
38630
38641
  exports.DeviceAuthClient = DeviceAuthClient;
38631
38642
  //# sourceMappingURL=DeviceAuthClient.js.map
@@ -38706,7 +38717,8 @@ let Device = class Device extends core_1.CoreSynchronizable {
38706
38717
  (0, ts_simple_nameof_1.nameof)((d) => d.lastLoginAt),
38707
38718
  (0, ts_simple_nameof_1.nameof)((d) => d.username),
38708
38719
  (0, ts_simple_nameof_1.nameof)((d) => d.initialPassword),
38709
- (0, ts_simple_nameof_1.nameof)((d) => d.datawalletVersion)
38720
+ (0, ts_simple_nameof_1.nameof)((d) => d.datawalletVersion),
38721
+ (0, ts_simple_nameof_1.nameof)((d) => d.isOffboarded)
38710
38722
  ];
38711
38723
  this.userdataProperties = [(0, ts_simple_nameof_1.nameof)((d) => d.name), (0, ts_simple_nameof_1.nameof)((d) => d.description)];
38712
38724
  }
@@ -38780,6 +38792,11 @@ __decorate([
38780
38792
  (0, ts_serval_1.serialize)(),
38781
38793
  __metadata("design:type", Number)
38782
38794
  ], Device.prototype, "datawalletVersion", void 0);
38795
+ __decorate([
38796
+ (0, ts_serval_1.validate)({ nullable: true }),
38797
+ (0, ts_serval_1.serialize)(),
38798
+ __metadata("design:type", Boolean)
38799
+ ], Device.prototype, "isOffboarded", void 0);
38783
38800
  exports.Device = Device = __decorate([
38784
38801
  (0, ts_serval_1.type)("Device")
38785
38802
  ], Device);
@@ -39837,7 +39854,6 @@ __exportStar(__webpack_require__(/*! ./sync/backbone/StartSyncRun */ "./dist/mod
39837
39854
  __exportStar(__webpack_require__(/*! ./sync/backbone/SyncClient */ "./dist/modules/sync/backbone/SyncClient.js"), exports);
39838
39855
  __exportStar(__webpack_require__(/*! ./sync/ChangedItems */ "./dist/modules/sync/ChangedItems.js"), exports);
39839
39856
  __exportStar(__webpack_require__(/*! ./sync/DatawalletModificationsProcessor */ "./dist/modules/sync/DatawalletModificationsProcessor.js"), exports);
39840
- __exportStar(__webpack_require__(/*! ./sync/ExternalEventsProcessor */ "./dist/modules/sync/ExternalEventsProcessor.js"), exports);
39841
39857
  __exportStar(__webpack_require__(/*! ./sync/local/DatawalletModification */ "./dist/modules/sync/local/DatawalletModification.js"), exports);
39842
39858
  var SyncCallback_1 = __webpack_require__(/*! ./sync/SyncCallback */ "./dist/modules/sync/SyncCallback.js");
39843
39859
  Object.defineProperty(exports, "SyncStep", ({ enumerable: true, get: function () { return SyncCallback_1.SyncStep; } }));
@@ -43661,22 +43677,26 @@ exports.SecretContainerPlain = SecretContainerPlain = __decorate([
43661
43677
  /*!*******************************************!*\
43662
43678
  !*** ./dist/modules/sync/ChangedItems.js ***!
43663
43679
  \*******************************************/
43664
- /***/ ((__unused_webpack_module, exports) => {
43680
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
43665
43681
 
43666
43682
  "use strict";
43667
43683
 
43668
43684
  Object.defineProperty(exports, "__esModule", ({ value: true }));
43669
43685
  exports.ChangedItems = void 0;
43686
+ const Message_1 = __webpack_require__(/*! ../messages/local/Message */ "./dist/modules/messages/local/Message.js");
43687
+ const Relationship_1 = __webpack_require__(/*! ../relationships/local/Relationship */ "./dist/modules/relationships/local/Relationship.js");
43670
43688
  class ChangedItems {
43671
43689
  constructor(relationships = [], messages = []) {
43672
43690
  this.relationships = relationships;
43673
43691
  this.messages = messages;
43674
43692
  }
43675
- addRelationship(relationship) {
43676
- this.relationships.push(relationship);
43677
- }
43678
- addMessage(message) {
43679
- this.messages.push(message);
43693
+ addItem(item) {
43694
+ if (item instanceof Message_1.Message) {
43695
+ this.messages.push(item);
43696
+ }
43697
+ else if (item instanceof Relationship_1.Relationship) {
43698
+ this.relationships.push(item);
43699
+ }
43680
43700
  }
43681
43701
  }
43682
43702
  exports.ChangedItems = ChangedItems;
@@ -43786,11 +43806,11 @@ const core_1 = __webpack_require__(/*! ../../core */ "./dist/core/index.js");
43786
43806
  const DbCollectionName_1 = __webpack_require__(/*! ../../core/DbCollectionName */ "./dist/core/DbCollectionName.js");
43787
43807
  const File_1 = __webpack_require__(/*! ../files/local/File */ "./dist/modules/files/local/File.js");
43788
43808
  const Message_1 = __webpack_require__(/*! ../messages/local/Message */ "./dist/modules/messages/local/Message.js");
43789
- const RelationshipTemplate_1 = __webpack_require__(/*! ../relationshipTemplates/local/RelationshipTemplate */ "./dist/modules/relationshipTemplates/local/RelationshipTemplate.js");
43790
43809
  const Relationship_1 = __webpack_require__(/*! ../relationships/local/Relationship */ "./dist/modules/relationships/local/Relationship.js");
43810
+ const RelationshipTemplate_1 = __webpack_require__(/*! ../relationshipTemplates/local/RelationshipTemplate */ "./dist/modules/relationshipTemplates/local/RelationshipTemplate.js");
43791
43811
  const Token_1 = __webpack_require__(/*! ../tokens/local/Token */ "./dist/modules/tokens/local/Token.js");
43792
- const SyncCallback_1 = __webpack_require__(/*! ./SyncCallback */ "./dist/modules/sync/SyncCallback.js");
43793
43812
  const DatawalletModification_1 = __webpack_require__(/*! ./local/DatawalletModification */ "./dist/modules/sync/local/DatawalletModification.js");
43813
+ const SyncCallback_1 = __webpack_require__(/*! ./SyncCallback */ "./dist/modules/sync/SyncCallback.js");
43794
43814
  class DatawalletModificationsProcessor {
43795
43815
  get log() {
43796
43816
  return this.logger;
@@ -43990,112 +44010,6 @@ exports.CacheFetcher = CacheFetcher;
43990
44010
 
43991
44011
  /***/ }),
43992
44012
 
43993
- /***/ "./dist/modules/sync/ExternalEventsProcessor.js":
43994
- /*!******************************************************!*\
43995
- !*** ./dist/modules/sync/ExternalEventsProcessor.js ***!
43996
- \******************************************************/
43997
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
43998
-
43999
- "use strict";
44000
-
44001
- Object.defineProperty(exports, "__esModule", ({ value: true }));
44002
- exports.ExternalEventsProcessor = void 0;
44003
- const core_1 = __webpack_require__(/*! ../../core */ "./dist/core/index.js");
44004
- const events_1 = __webpack_require__(/*! ../../events */ "./dist/events/index.js");
44005
- const ChangedItems_1 = __webpack_require__(/*! ./ChangedItems */ "./dist/modules/sync/ChangedItems.js");
44006
- const SyncCallback_1 = __webpack_require__(/*! ./SyncCallback */ "./dist/modules/sync/SyncCallback.js");
44007
- class ExternalEventsProcessor {
44008
- constructor(messagesController, relationshipsController, externalEvents, reporter, eventBus, ownAddress) {
44009
- this.messagesController = messagesController;
44010
- this.relationshipsController = relationshipsController;
44011
- this.externalEvents = externalEvents;
44012
- this.eventBus = eventBus;
44013
- this.ownAddress = ownAddress;
44014
- this.changedItems = new ChangedItems_1.ChangedItems();
44015
- this.results = [];
44016
- this.log = core_1.TransportLoggerFactory.getLogger(ExternalEventsProcessor);
44017
- this.syncStep = reporter.createStep(SyncCallback_1.SyncStep.ExternalEventsProcessing, externalEvents.length);
44018
- }
44019
- async execute() {
44020
- for (const externalEvent of this.externalEvents) {
44021
- try {
44022
- switch (externalEvent.type) {
44023
- case "MessageReceived":
44024
- await this.applyMessageReceivedEvent(externalEvent);
44025
- break;
44026
- case "MessageDelivered":
44027
- await this.applyMessageDeliveredEvent(externalEvent);
44028
- break;
44029
- case "RelationshipChangeCreated":
44030
- await this.applyRelationshipChangeCreatedEvent(externalEvent);
44031
- break;
44032
- case "RelationshipChangeCompleted":
44033
- await this.applyRelationshipChangeCompletedEvent(externalEvent);
44034
- break;
44035
- default:
44036
- throw new core_1.TransportError(`'${externalEvent.type}' is not a supported external event type.`);
44037
- }
44038
- this.results.push({
44039
- externalEventId: externalEvent.id
44040
- });
44041
- }
44042
- catch (e) {
44043
- this.log.error("There was an error while trying to apply an external event: ", e);
44044
- let errorCode;
44045
- if (e.code) {
44046
- errorCode = e.code;
44047
- }
44048
- else if (e.message) {
44049
- errorCode = e.message;
44050
- }
44051
- else {
44052
- errorCode = JSON.stringify(e);
44053
- }
44054
- this.results.push({
44055
- externalEventId: externalEvent.id,
44056
- errorCode: errorCode
44057
- });
44058
- }
44059
- finally {
44060
- this.syncStep.progress();
44061
- }
44062
- }
44063
- }
44064
- async applyRelationshipChangeCompletedEvent(externalEvent) {
44065
- const payload = externalEvent.payload;
44066
- const relationship = await this.relationshipsController.applyChangeById(payload.changeId);
44067
- if (relationship) {
44068
- this.eventBus.publish(new events_1.RelationshipChangedEvent(this.ownAddress, relationship));
44069
- this.changedItems.addRelationship(relationship);
44070
- }
44071
- }
44072
- async applyRelationshipChangeCreatedEvent(externalEvent) {
44073
- const payload = externalEvent.payload;
44074
- const relationship = await this.relationshipsController.applyChangeById(payload.changeId);
44075
- if (relationship) {
44076
- this.eventBus.publish(new events_1.RelationshipChangedEvent(this.ownAddress, relationship));
44077
- this.changedItems.addRelationship(relationship);
44078
- }
44079
- }
44080
- async applyMessageDeliveredEvent(externalEvent) {
44081
- const messageReceivedPayload = externalEvent.payload;
44082
- const updatedMessages = await this.messagesController.updateCache([messageReceivedPayload.id]);
44083
- const deliveredMessage = updatedMessages[0];
44084
- this.eventBus.publish(new events_1.MessageDeliveredEvent(this.ownAddress, deliveredMessage));
44085
- this.changedItems.addMessage(deliveredMessage);
44086
- }
44087
- async applyMessageReceivedEvent(externalEvent) {
44088
- const newMessagePayload = externalEvent.payload;
44089
- const newMessage = await this.messagesController.loadPeerMessage(core_1.CoreId.from(newMessagePayload.id));
44090
- this.eventBus.publish(new events_1.MessageReceivedEvent(this.ownAddress, newMessage));
44091
- this.changedItems.addMessage(newMessage);
44092
- }
44093
- }
44094
- exports.ExternalEventsProcessor = ExternalEventsProcessor;
44095
- //# sourceMappingURL=ExternalEventsProcessor.js.map
44096
-
44097
- /***/ }),
44098
-
44099
44013
  /***/ "./dist/modules/sync/SyncCallback.js":
44100
44014
  /*!*******************************************!*\
44101
44015
  !*** ./dist/modules/sync/SyncCallback.js ***!
@@ -44152,16 +44066,16 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
44152
44066
  exports.SyncController = void 0;
44153
44067
  const ts_utils_1 = __webpack_require__(/*! @js-soft/ts-utils */ "../../node_modules/@js-soft/ts-utils/dist/index.js");
44154
44068
  const core_1 = __webpack_require__(/*! ../../core */ "./dist/core/index.js");
44069
+ const StartSyncRun_1 = __webpack_require__(/*! ./backbone/StartSyncRun */ "./dist/modules/sync/backbone/StartSyncRun.js");
44070
+ const SyncClient_1 = __webpack_require__(/*! ./backbone/SyncClient */ "./dist/modules/sync/backbone/SyncClient.js");
44155
44071
  const ChangedItems_1 = __webpack_require__(/*! ./ChangedItems */ "./dist/modules/sync/ChangedItems.js");
44156
44072
  const DatawalletModificationMapper_1 = __webpack_require__(/*! ./DatawalletModificationMapper */ "./dist/modules/sync/DatawalletModificationMapper.js");
44157
44073
  const DatawalletModificationsProcessor_1 = __webpack_require__(/*! ./DatawalletModificationsProcessor */ "./dist/modules/sync/DatawalletModificationsProcessor.js");
44158
- const ExternalEventsProcessor_1 = __webpack_require__(/*! ./ExternalEventsProcessor */ "./dist/modules/sync/ExternalEventsProcessor.js");
44159
- const SyncCallback_1 = __webpack_require__(/*! ./SyncCallback */ "./dist/modules/sync/SyncCallback.js");
44160
- const StartSyncRun_1 = __webpack_require__(/*! ./backbone/StartSyncRun */ "./dist/modules/sync/backbone/StartSyncRun.js");
44161
- const SyncClient_1 = __webpack_require__(/*! ./backbone/SyncClient */ "./dist/modules/sync/backbone/SyncClient.js");
44074
+ const externalEventProcessors_1 = __webpack_require__(/*! ./externalEventProcessors */ "./dist/modules/sync/externalEventProcessors/index.js");
44162
44075
  const DatawalletModification_1 = __webpack_require__(/*! ./local/DatawalletModification */ "./dist/modules/sync/local/DatawalletModification.js");
44163
44076
  const DeviceMigrations_1 = __webpack_require__(/*! ./migrations/DeviceMigrations */ "./dist/modules/sync/migrations/DeviceMigrations.js");
44164
44077
  const IdentityMigrations_1 = __webpack_require__(/*! ./migrations/IdentityMigrations */ "./dist/modules/sync/migrations/IdentityMigrations.js");
44078
+ const SyncCallback_1 = __webpack_require__(/*! ./SyncCallback */ "./dist/modules/sync/SyncCallback.js");
44165
44079
  class SyncController extends core_1.TransportController {
44166
44080
  get cacheFetcher() {
44167
44081
  if (!this._cacheFetcher) {
@@ -44173,6 +44087,7 @@ class SyncController extends core_1.TransportController {
44173
44087
  super(core_1.ControllerName.Sync, parent);
44174
44088
  this.unpushedDatawalletModifications = unpushedDatawalletModifications;
44175
44089
  this.datawalletEnabled = datawalletEnabled;
44090
+ this.externalEventRegistry = new externalEventProcessors_1.ExternalEventProcessorRegistry();
44176
44091
  this.client = dependencyOverrides.syncClient ?? new SyncClient_1.SyncClient(this.config, this.parent.authenticator);
44177
44092
  this.identityMigrations = new IdentityMigrations_1.IdentityMigrations(this.parent);
44178
44093
  this.deviceMigrations = new DeviceMigrations_1.DeviceMigrations(this.parent);
@@ -44425,12 +44340,44 @@ class SyncController extends core_1.TransportController {
44425
44340
  throw getExternalEventsResult.error;
44426
44341
  }
44427
44342
  const externalEvents = await getExternalEventsResult.value.collect();
44428
- const externalEventProcessor = new ExternalEventsProcessor_1.ExternalEventsProcessor(this.parent.messages, this.parent.relationships, externalEvents, reporter, this.eventBus, this.parent.identity.address.toString());
44429
- await externalEventProcessor.execute();
44343
+ const syncStep = reporter.createStep(SyncCallback_1.SyncStep.ExternalEventsProcessing, externalEvents.length);
44344
+ const results = [];
44345
+ const changedItems = new ChangedItems_1.ChangedItems();
44346
+ for (const externalEvent of externalEvents) {
44347
+ try {
44348
+ const externalEventProcessorConstructor = this.externalEventRegistry.getProcessorForItem(externalEvent.type);
44349
+ const item = await new externalEventProcessorConstructor(this.eventBus, this.parent).execute(externalEvent);
44350
+ if (item)
44351
+ changedItems.addItem(item);
44352
+ results.push({
44353
+ externalEventId: externalEvent.id
44354
+ });
44355
+ }
44356
+ catch (e) {
44357
+ this.log.error("There was an error while trying to apply an external event: ", e);
44358
+ let errorCode;
44359
+ if (e.code) {
44360
+ errorCode = e.code;
44361
+ }
44362
+ else if (e.message) {
44363
+ errorCode = e.message;
44364
+ }
44365
+ else {
44366
+ errorCode = JSON.stringify(e);
44367
+ }
44368
+ results.push({
44369
+ externalEventId: externalEvent.id,
44370
+ errorCode: errorCode
44371
+ });
44372
+ }
44373
+ finally {
44374
+ syncStep.progress();
44375
+ }
44376
+ }
44430
44377
  externalEventStep.finish();
44431
44378
  return {
44432
- externalEventResults: externalEventProcessor.results,
44433
- changedItems: externalEventProcessor.changedItems
44379
+ externalEventResults: results,
44380
+ changedItems: changedItems
44434
44381
  };
44435
44382
  }
44436
44383
  async finalizeExternalEventsSyncRun(externalEventResults) {
@@ -44869,6 +44816,215 @@ exports.SyncClient = SyncClient;
44869
44816
 
44870
44817
  /***/ }),
44871
44818
 
44819
+ /***/ "./dist/modules/sync/externalEventProcessors/ExternalEventProcessor.js":
44820
+ /*!*****************************************************************************!*\
44821
+ !*** ./dist/modules/sync/externalEventProcessors/ExternalEventProcessor.js ***!
44822
+ \*****************************************************************************/
44823
+ /***/ ((__unused_webpack_module, exports) => {
44824
+
44825
+ "use strict";
44826
+
44827
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
44828
+ exports.ExternalEventProcessor = void 0;
44829
+ class ExternalEventProcessor {
44830
+ constructor(eventBus, accountController) {
44831
+ this.eventBus = eventBus;
44832
+ this.accountController = accountController;
44833
+ }
44834
+ get ownAddress() {
44835
+ return this.accountController.identity.address.toString();
44836
+ }
44837
+ }
44838
+ exports.ExternalEventProcessor = ExternalEventProcessor;
44839
+ //# sourceMappingURL=ExternalEventProcessor.js.map
44840
+
44841
+ /***/ }),
44842
+
44843
+ /***/ "./dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.js":
44844
+ /*!*************************************************************************************!*\
44845
+ !*** ./dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.js ***!
44846
+ \*************************************************************************************/
44847
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
44848
+
44849
+ "use strict";
44850
+
44851
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
44852
+ exports.ExternalEventProcessorRegistry = void 0;
44853
+ const core_1 = __webpack_require__(/*! ../../../core */ "./dist/core/index.js");
44854
+ const MessageDeliveredExternalEventProcessor_1 = __webpack_require__(/*! ./MessageDeliveredExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/MessageDeliveredExternalEventProcessor.js");
44855
+ const MessageReceivedExternalEventProcessor_1 = __webpack_require__(/*! ./MessageReceivedExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/MessageReceivedExternalEventProcessor.js");
44856
+ const RelationshipChangeCompletedExternalEventProcessor_1 = __webpack_require__(/*! ./RelationshipChangeCompletedExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.js");
44857
+ const RelationshipChangeCreatedExternalEventProcessor_1 = __webpack_require__(/*! ./RelationshipChangeCreatedExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/RelationshipChangeCreatedExternalEventProcessor.js");
44858
+ class ExternalEventProcessorRegistry {
44859
+ constructor() {
44860
+ this.processors = new Map();
44861
+ this.registerProcessor("MessageReceived", MessageReceivedExternalEventProcessor_1.MessageReceivedExternalEventProcessor);
44862
+ this.registerProcessor("MessageDelivered", MessageDeliveredExternalEventProcessor_1.MessageDeliveredExternalEventProcessor);
44863
+ this.registerProcessor("RelationshipChangeCreated", RelationshipChangeCreatedExternalEventProcessor_1.RelationshipChangeCreatedExternalEventProcessor);
44864
+ this.registerProcessor("RelationshipChangeCompleted", RelationshipChangeCompletedExternalEventProcessor_1.RelationshipChangeCompletedExternalEventProcessor);
44865
+ }
44866
+ registerProcessor(externalEventName, externalEventProcessor) {
44867
+ if (this.processors.has(externalEventName)) {
44868
+ throw new core_1.TransportError(`There is already a externalEventProcessor registered for '${externalEventName}'. Use 'replaceProcessorForType' if you want to replace it.`);
44869
+ }
44870
+ this.processors.set(externalEventName, externalEventProcessor);
44871
+ }
44872
+ registerOrReplaceProcessor(externalEventName, externalEventProcessor) {
44873
+ this.processors.set(externalEventName, externalEventProcessor);
44874
+ }
44875
+ getProcessorForItem(externalEventName) {
44876
+ const externalEventProcessor = this.processors.get(externalEventName);
44877
+ if (!externalEventProcessor) {
44878
+ throw new core_1.TransportError(`There was no processor registered for '${externalEventName}'.`);
44879
+ }
44880
+ return externalEventProcessor;
44881
+ }
44882
+ }
44883
+ exports.ExternalEventProcessorRegistry = ExternalEventProcessorRegistry;
44884
+ //# sourceMappingURL=ExternalEventProcessorRegistry.js.map
44885
+
44886
+ /***/ }),
44887
+
44888
+ /***/ "./dist/modules/sync/externalEventProcessors/MessageDeliveredExternalEventProcessor.js":
44889
+ /*!*********************************************************************************************!*\
44890
+ !*** ./dist/modules/sync/externalEventProcessors/MessageDeliveredExternalEventProcessor.js ***!
44891
+ \*********************************************************************************************/
44892
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
44893
+
44894
+ "use strict";
44895
+
44896
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
44897
+ exports.MessageDeliveredExternalEventProcessor = void 0;
44898
+ const events_1 = __webpack_require__(/*! ../../../events */ "./dist/events/index.js");
44899
+ const ExternalEventProcessor_1 = __webpack_require__(/*! ./ExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/ExternalEventProcessor.js");
44900
+ class MessageDeliveredExternalEventProcessor extends ExternalEventProcessor_1.ExternalEventProcessor {
44901
+ async execute(externalEvent) {
44902
+ const messageReceivedPayload = externalEvent.payload;
44903
+ const updatedMessages = await this.accountController.messages.updateCache([messageReceivedPayload.id]);
44904
+ const deliveredMessage = updatedMessages[0];
44905
+ this.eventBus.publish(new events_1.MessageDeliveredEvent(this.ownAddress, deliveredMessage));
44906
+ return deliveredMessage;
44907
+ }
44908
+ }
44909
+ exports.MessageDeliveredExternalEventProcessor = MessageDeliveredExternalEventProcessor;
44910
+ //# sourceMappingURL=MessageDeliveredExternalEventProcessor.js.map
44911
+
44912
+ /***/ }),
44913
+
44914
+ /***/ "./dist/modules/sync/externalEventProcessors/MessageReceivedExternalEventProcessor.js":
44915
+ /*!********************************************************************************************!*\
44916
+ !*** ./dist/modules/sync/externalEventProcessors/MessageReceivedExternalEventProcessor.js ***!
44917
+ \********************************************************************************************/
44918
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
44919
+
44920
+ "use strict";
44921
+
44922
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
44923
+ exports.MessageReceivedExternalEventProcessor = void 0;
44924
+ const core_1 = __webpack_require__(/*! ../../../core */ "./dist/core/index.js");
44925
+ const events_1 = __webpack_require__(/*! ../../../events */ "./dist/events/index.js");
44926
+ const ExternalEventProcessor_1 = __webpack_require__(/*! ./ExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/ExternalEventProcessor.js");
44927
+ class MessageReceivedExternalEventProcessor extends ExternalEventProcessor_1.ExternalEventProcessor {
44928
+ async execute(externalEvent) {
44929
+ const newMessagePayload = externalEvent.payload;
44930
+ const newMessage = await this.accountController.messages.loadPeerMessage(core_1.CoreId.from(newMessagePayload.id));
44931
+ this.eventBus.publish(new events_1.MessageReceivedEvent(this.ownAddress, newMessage));
44932
+ return newMessage;
44933
+ }
44934
+ }
44935
+ exports.MessageReceivedExternalEventProcessor = MessageReceivedExternalEventProcessor;
44936
+ //# sourceMappingURL=MessageReceivedExternalEventProcessor.js.map
44937
+
44938
+ /***/ }),
44939
+
44940
+ /***/ "./dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.js":
44941
+ /*!********************************************************************************************************!*\
44942
+ !*** ./dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.js ***!
44943
+ \********************************************************************************************************/
44944
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
44945
+
44946
+ "use strict";
44947
+
44948
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
44949
+ exports.RelationshipChangeCompletedExternalEventProcessor = void 0;
44950
+ const events_1 = __webpack_require__(/*! ../../../events */ "./dist/events/index.js");
44951
+ const ExternalEventProcessor_1 = __webpack_require__(/*! ./ExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/ExternalEventProcessor.js");
44952
+ class RelationshipChangeCompletedExternalEventProcessor extends ExternalEventProcessor_1.ExternalEventProcessor {
44953
+ async execute(externalEvent) {
44954
+ const payload = externalEvent.payload;
44955
+ const relationship = await this.accountController.relationships.applyChangeById(payload.changeId);
44956
+ if (relationship) {
44957
+ this.eventBus.publish(new events_1.RelationshipChangedEvent(this.ownAddress, relationship));
44958
+ return relationship;
44959
+ }
44960
+ return;
44961
+ }
44962
+ }
44963
+ exports.RelationshipChangeCompletedExternalEventProcessor = RelationshipChangeCompletedExternalEventProcessor;
44964
+ //# sourceMappingURL=RelationshipChangeCompletedExternalEventProcessor.js.map
44965
+
44966
+ /***/ }),
44967
+
44968
+ /***/ "./dist/modules/sync/externalEventProcessors/RelationshipChangeCreatedExternalEventProcessor.js":
44969
+ /*!******************************************************************************************************!*\
44970
+ !*** ./dist/modules/sync/externalEventProcessors/RelationshipChangeCreatedExternalEventProcessor.js ***!
44971
+ \******************************************************************************************************/
44972
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
44973
+
44974
+ "use strict";
44975
+
44976
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
44977
+ exports.RelationshipChangeCreatedExternalEventProcessor = void 0;
44978
+ const events_1 = __webpack_require__(/*! ../../../events */ "./dist/events/index.js");
44979
+ const ExternalEventProcessor_1 = __webpack_require__(/*! ./ExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/ExternalEventProcessor.js");
44980
+ class RelationshipChangeCreatedExternalEventProcessor extends ExternalEventProcessor_1.ExternalEventProcessor {
44981
+ async execute(externalEvent) {
44982
+ const payload = externalEvent.payload;
44983
+ const relationship = await this.accountController.relationships.applyChangeById(payload.changeId);
44984
+ if (relationship) {
44985
+ this.eventBus.publish(new events_1.RelationshipChangedEvent(this.ownAddress, relationship));
44986
+ return relationship;
44987
+ }
44988
+ return;
44989
+ }
44990
+ }
44991
+ exports.RelationshipChangeCreatedExternalEventProcessor = RelationshipChangeCreatedExternalEventProcessor;
44992
+ //# sourceMappingURL=RelationshipChangeCreatedExternalEventProcessor.js.map
44993
+
44994
+ /***/ }),
44995
+
44996
+ /***/ "./dist/modules/sync/externalEventProcessors/index.js":
44997
+ /*!************************************************************!*\
44998
+ !*** ./dist/modules/sync/externalEventProcessors/index.js ***!
44999
+ \************************************************************/
45000
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
45001
+
45002
+ "use strict";
45003
+
45004
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
45005
+ if (k2 === undefined) k2 = k;
45006
+ var desc = Object.getOwnPropertyDescriptor(m, k);
45007
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
45008
+ desc = { enumerable: true, get: function() { return m[k]; } };
45009
+ }
45010
+ Object.defineProperty(o, k2, desc);
45011
+ }) : (function(o, m, k, k2) {
45012
+ if (k2 === undefined) k2 = k;
45013
+ o[k2] = m[k];
45014
+ }));
45015
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
45016
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
45017
+ };
45018
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
45019
+ __exportStar(__webpack_require__(/*! ./ExternalEventProcessorRegistry */ "./dist/modules/sync/externalEventProcessors/ExternalEventProcessorRegistry.js"), exports);
45020
+ __exportStar(__webpack_require__(/*! ./MessageDeliveredExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/MessageDeliveredExternalEventProcessor.js"), exports);
45021
+ __exportStar(__webpack_require__(/*! ./MessageReceivedExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/MessageReceivedExternalEventProcessor.js"), exports);
45022
+ __exportStar(__webpack_require__(/*! ./RelationshipChangeCompletedExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/RelationshipChangeCompletedExternalEventProcessor.js"), exports);
45023
+ __exportStar(__webpack_require__(/*! ./RelationshipChangeCreatedExternalEventProcessor */ "./dist/modules/sync/externalEventProcessors/RelationshipChangeCreatedExternalEventProcessor.js"), exports);
45024
+ //# sourceMappingURL=index.js.map
45025
+
45026
+ /***/ }),
45027
+
44872
45028
  /***/ "./dist/modules/sync/local/DatawalletModification.js":
44873
45029
  /*!***********************************************************!*\
44874
45030
  !*** ./dist/modules/sync/local/DatawalletModification.js ***!