@sumaris-net/ngx-components 0.28.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/sumaris-net.ngx-components.umd.js +286 -303
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +2 -2
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/doc/changelog.md +4 -0
- package/esm2015/src/app/core/graphql/graphql.service.js +5 -8
- package/esm2015/src/app/core/services/account.service.js +177 -188
- package/esm2015/src/app/core/services/base-entity-service.class.js +9 -7
- package/esm2015/src/app/core/services/base-graphql-service.class.js +7 -2
- package/esm2015/src/app/core/services/config.service.js +9 -54
- package/esm2015/src/app/core/services/model/account.model.js +1 -1
- package/esm2015/src/app/core/services/model/settings.model.js +29 -2
- package/esm2015/src/app/core/services/network.service.js +5 -7
- package/esm2015/src/app/core/services/storage/entities-storage.service.js +3 -6
- package/esm2015/src/app/shared/services/startable-service.class.js +13 -2
- package/fesm2015/sumaris-net.ngx-components.js +240 -261
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/core/graphql/graphql.service.d.ts +0 -1
- package/src/app/core/services/account.service.d.ts +8 -21
- package/src/app/core/services/base-entity-service.class.d.ts +1 -0
- package/src/app/core/services/base-graphql-service.class.d.ts +3 -2
- package/src/app/core/services/config.service.d.ts +2 -9
- package/src/app/core/services/model/settings.model.d.ts +2 -0
- package/src/app/core/services/network.service.d.ts +2 -2
- package/src/app/core/services/storage/entities-storage.service.d.ts +0 -1
- package/src/app/shared/services/startable-service.class.d.ts +3 -1
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -8700,6 +8700,9 @@
|
|
|
8700
8700
|
this._startByReadyFunction = true; // should start when calling ready() ?
|
|
8701
8701
|
this._data = null;
|
|
8702
8702
|
this._started = false;
|
|
8703
|
+
this._startPromise = null;
|
|
8704
|
+
this._startPrerequisite = null;
|
|
8705
|
+
this._subscription = null;
|
|
8703
8706
|
this._startPrerequisite = prerequisiteService
|
|
8704
8707
|
? function () { return prerequisiteService.ready(); }
|
|
8705
8708
|
: function () { return Promise.resolve(); };
|
|
@@ -8734,6 +8737,10 @@
|
|
|
8734
8737
|
switch (_a.label) {
|
|
8735
8738
|
case 0:
|
|
8736
8739
|
_a.trys.push([0, 2, , 3]);
|
|
8740
|
+
if (this._subscription) {
|
|
8741
|
+
this._subscription.unsubscribe();
|
|
8742
|
+
this._subscription = null;
|
|
8743
|
+
}
|
|
8737
8744
|
return [4 /*yield*/, this.ngOnStop()];
|
|
8738
8745
|
case 1:
|
|
8739
8746
|
_a.sent();
|
|
@@ -8796,6 +8803,10 @@
|
|
|
8796
8803
|
return waitFor(function () { return _this._started; })
|
|
8797
8804
|
.then(function () { return _this._data; });
|
|
8798
8805
|
};
|
|
8806
|
+
StartableService.prototype.registerSubscription = function (sub) {
|
|
8807
|
+
this._subscription = this._subscription || new rxjs.Subscription();
|
|
8808
|
+
return this._subscription.add(sub);
|
|
8809
|
+
};
|
|
8799
8810
|
StartableService.prototype.ngOnStop = function () {
|
|
8800
8811
|
return __awaiter(this, void 0, void 0, function () {
|
|
8801
8812
|
return __generator(this, function (_a) {
|
|
@@ -11349,7 +11360,6 @@
|
|
|
11349
11360
|
_this.onPeerChanges = _this.onStart.pipe(operators.map(function (peer) { return peer && peer.url; }), operators.filter(isNotNilOrBlank), operators.distinctUntilChanged());
|
|
11350
11361
|
_this.onNetworkStatusChanges = new rxjs.BehaviorSubject(null);
|
|
11351
11362
|
_this.onResetNetworkCache = new i0.EventEmitter(true);
|
|
11352
|
-
_this._subscription = new rxjs.Subscription();
|
|
11353
11363
|
_this._listeners = {};
|
|
11354
11364
|
_this._mobile = _this.platform.is('mobile');
|
|
11355
11365
|
if (_this._mobile) {
|
|
@@ -11562,7 +11572,8 @@
|
|
|
11562
11572
|
/**
|
|
11563
11573
|
* Check if the peer is alive
|
|
11564
11574
|
*
|
|
11565
|
-
* @param
|
|
11575
|
+
* @param peer
|
|
11576
|
+
* @param opts
|
|
11566
11577
|
*/
|
|
11567
11578
|
NetworkService.prototype.checkPeerAlive = function (peer, opts) {
|
|
11568
11579
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -11758,8 +11769,8 @@
|
|
|
11758
11769
|
this.startRefreshTimer();
|
|
11759
11770
|
// Listen for device network changes
|
|
11760
11771
|
if (this.network) {
|
|
11761
|
-
this.
|
|
11762
|
-
this.
|
|
11772
|
+
this.registerSubscription(this.network.onDisconnect().subscribe(function () { return _this.onDeviceConnectionChanged('none'); }));
|
|
11773
|
+
this.registerSubscription(this.network.onConnect().subscribe(function () { return _this.onDeviceConnectionChanged(_this.network.type); }));
|
|
11763
11774
|
}
|
|
11764
11775
|
return [2 /*return*/];
|
|
11765
11776
|
}
|
|
@@ -11774,8 +11785,6 @@
|
|
|
11774
11785
|
if (this._timerRefreshCondition() === false) {
|
|
11775
11786
|
this.stopRefreshTimer();
|
|
11776
11787
|
}
|
|
11777
|
-
this._subscription.unsubscribe();
|
|
11778
|
-
this._subscription = new rxjs.Subscription();
|
|
11779
11788
|
return [2 /*return*/];
|
|
11780
11789
|
});
|
|
11781
11790
|
});
|
|
@@ -12575,7 +12584,6 @@
|
|
|
12575
12584
|
_this.progressBarService = progressBarService;
|
|
12576
12585
|
_this.storage = storage;
|
|
12577
12586
|
_this.environment = environment;
|
|
12578
|
-
_this._subscription = new rxjs.Subscription();
|
|
12579
12587
|
_this._$save = new i0.EventEmitter(true);
|
|
12580
12588
|
_this._dirty = false;
|
|
12581
12589
|
_this._saving = false;
|
|
@@ -13024,7 +13032,7 @@
|
|
|
13024
13032
|
// Restore sequences
|
|
13025
13033
|
_a.sent();
|
|
13026
13034
|
// Start a save timer
|
|
13027
|
-
this.
|
|
13035
|
+
this.registerSubscription(rxjs.merge(this._$save, rxjs.timer(this._saveTimerPeriod, this._saveTimerPeriod))
|
|
13028
13036
|
.pipe(
|
|
13029
13037
|
// Avoid to many call (e.g. when $save AND timer are triggered
|
|
13030
13038
|
operators.throttleTime(this._saveTimerPeriod))
|
|
@@ -13040,8 +13048,6 @@
|
|
|
13040
13048
|
return __generator(this, function (_a) {
|
|
13041
13049
|
switch (_a.label) {
|
|
13042
13050
|
case 0:
|
|
13043
|
-
this._subscription.unsubscribe();
|
|
13044
|
-
this._subscription = new rxjs.Subscription();
|
|
13045
13051
|
if (!this.dirty) return [3 /*break*/, 2];
|
|
13046
13052
|
return [4 /*yield*/, this.storeLocally()];
|
|
13047
13053
|
case 1:
|
|
@@ -13259,8 +13265,36 @@
|
|
|
13259
13265
|
}
|
|
13260
13266
|
this.nonce = source.nonce;
|
|
13261
13267
|
};
|
|
13268
|
+
UserSettings.prototype.merge = function (source, includesProperties) {
|
|
13269
|
+
var _this = this;
|
|
13270
|
+
if (!source)
|
|
13271
|
+
return; // Skip
|
|
13272
|
+
// Reset content
|
|
13273
|
+
this.content = {};
|
|
13274
|
+
var hasChanges = false;
|
|
13275
|
+
// For each property of source object
|
|
13276
|
+
Object.keys(source)
|
|
13277
|
+
.forEach(function (key) {
|
|
13278
|
+
// If property exists in UserSettings class: store it directly
|
|
13279
|
+
if (UserSettings_1.SETTINGS_PROPERTIES.includes(key)) {
|
|
13280
|
+
if (!equals(_this[key], source[key])) {
|
|
13281
|
+
_this[key] = source[key];
|
|
13282
|
+
hasChanges = true;
|
|
13283
|
+
}
|
|
13284
|
+
}
|
|
13285
|
+
// Else, store property into the 'content' map
|
|
13286
|
+
else if (includesProperties && includesProperties.includes(key)) {
|
|
13287
|
+
if (!equals(_this.content[key], source[key])) {
|
|
13288
|
+
_this.content[key] = Object.assign({}, source[key]);
|
|
13289
|
+
hasChanges = true;
|
|
13290
|
+
}
|
|
13291
|
+
}
|
|
13292
|
+
});
|
|
13293
|
+
return hasChanges;
|
|
13294
|
+
};
|
|
13262
13295
|
return UserSettings;
|
|
13263
13296
|
}(Entity));
|
|
13297
|
+
exports.UserSettings.SETTINGS_PROPERTIES = ['locale', 'latLongFormat'];
|
|
13264
13298
|
exports.UserSettings = UserSettings_1 = __decorate([
|
|
13265
13299
|
EntityClass({ typename: 'UserSettingsVO' })
|
|
13266
13300
|
], exports.UserSettings);
|
|
@@ -13711,7 +13745,6 @@
|
|
|
13711
13745
|
_this.cryptoService = cryptoService;
|
|
13712
13746
|
_this.environment = environment;
|
|
13713
13747
|
_this.typePolicies = typePolicies;
|
|
13714
|
-
_this._subscription = new rxjs.Subscription();
|
|
13715
13748
|
_this.connectionParams = {};
|
|
13716
13749
|
_this.onNetworkError = new rxjs.Subject();
|
|
13717
13750
|
_this.customErrors = {};
|
|
@@ -14275,7 +14308,7 @@
|
|
|
14275
14308
|
debug: true
|
|
14276
14309
|
});
|
|
14277
14310
|
queueLink_1 = new QueueLink__default["default"]();
|
|
14278
|
-
this.
|
|
14311
|
+
this.registerSubscription(this._networkStatusChanged$
|
|
14279
14312
|
.subscribe(function (type) {
|
|
14280
14313
|
// Network is offline: start buffering into queue
|
|
14281
14314
|
if (type === 'none') {
|
|
@@ -14343,9 +14376,9 @@
|
|
|
14343
14376
|
return [3 /*break*/, 8];
|
|
14344
14377
|
case 8:
|
|
14345
14378
|
// Listen for network restart
|
|
14346
|
-
this.
|
|
14379
|
+
this.registerSubscription(this.network.on('start', function () { return _this.restart(); }));
|
|
14347
14380
|
// Listen for clear cache request, from network
|
|
14348
|
-
this.
|
|
14381
|
+
this.registerSubscription(this.network.on('resetCache', function () { return _this.clearCache(); }));
|
|
14349
14382
|
console.info('[graphql] Starting graphql [OK]');
|
|
14350
14383
|
return [2 /*return*/, client];
|
|
14351
14384
|
}
|
|
@@ -14358,8 +14391,6 @@
|
|
|
14358
14391
|
switch (_a.label) {
|
|
14359
14392
|
case 0:
|
|
14360
14393
|
console.info('[graphql] Stopping graphql service...');
|
|
14361
|
-
this._subscription.unsubscribe();
|
|
14362
|
-
this._subscription = new rxjs.Subscription();
|
|
14363
14394
|
return [4 /*yield*/, this.resetClient()];
|
|
14364
14395
|
case 1:
|
|
14365
14396
|
_a.sent();
|
|
@@ -14495,18 +14526,21 @@
|
|
|
14495
14526
|
return BaseGraphqlServiceOptions;
|
|
14496
14527
|
}());
|
|
14497
14528
|
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
|
14498
|
-
var BaseGraphqlService = /** @class */ (function () {
|
|
14529
|
+
var BaseGraphqlService = /** @class */ (function (_super) {
|
|
14530
|
+
__extends(BaseGraphqlService, _super);
|
|
14499
14531
|
function BaseGraphqlService(graphql, options) {
|
|
14500
|
-
this
|
|
14501
|
-
|
|
14532
|
+
var _this = _super.call(this, graphql) || this;
|
|
14533
|
+
_this.graphql = graphql;
|
|
14534
|
+
_this._mutableWatchQueries = [];
|
|
14502
14535
|
// Max updated queries, for this entity.
|
|
14503
14536
|
// - Can be override by subclasses (in constructor)
|
|
14504
14537
|
// - Use value -1 for no max size
|
|
14505
14538
|
// - Default value to 3, because it usually enough (e.g. OperationService and LandingService need at least 2)
|
|
14506
|
-
|
|
14539
|
+
_this._mutableWatchQueriesMaxCount = 3;
|
|
14507
14540
|
// for DEV only
|
|
14508
|
-
|
|
14509
|
-
|
|
14541
|
+
_this._debug = toBoolean(options && !options.production, !environment.production);
|
|
14542
|
+
_this._logPrefix = "[base-graphql-service] ";
|
|
14543
|
+
return _this;
|
|
14510
14544
|
}
|
|
14511
14545
|
BaseGraphqlService.prototype.mutableWatchQuery = function (opts) {
|
|
14512
14546
|
opts.fetchPolicy = opts.fetchPolicy || this.graphql.defaultFetchPolicy;
|
|
@@ -14704,8 +14738,11 @@
|
|
|
14704
14738
|
return { query: query, variables: variables };
|
|
14705
14739
|
});
|
|
14706
14740
|
};
|
|
14741
|
+
BaseGraphqlService.prototype.ngOnStart = function () {
|
|
14742
|
+
return Promise.resolve(null);
|
|
14743
|
+
};
|
|
14707
14744
|
return BaseGraphqlService;
|
|
14708
|
-
}());
|
|
14745
|
+
}(StartableService));
|
|
14709
14746
|
BaseGraphqlService.decorators = [
|
|
14710
14747
|
{ type: i0.Directive }
|
|
14711
14748
|
];
|
|
@@ -14758,18 +14795,16 @@
|
|
|
14758
14795
|
_this.onChange = new rxjs.Subject();
|
|
14759
14796
|
_this.onAuthTokenChange = new rxjs.Subject();
|
|
14760
14797
|
_this.onAuthBasicChange = new rxjs.Subject();
|
|
14761
|
-
_this.
|
|
14798
|
+
_this._cache = {
|
|
14762
14799
|
loaded: false,
|
|
14763
14800
|
keypair: null,
|
|
14764
14801
|
authToken: null,
|
|
14765
14802
|
authBasic: null,
|
|
14766
14803
|
pubkey: null,
|
|
14767
14804
|
mainProfile: null,
|
|
14768
|
-
account: null,
|
|
14769
14805
|
person: null,
|
|
14770
14806
|
department: null
|
|
14771
14807
|
};
|
|
14772
|
-
_this._started = false;
|
|
14773
14808
|
_this._$additionalFields = new rxjs.BehaviorSubject([]);
|
|
14774
14809
|
_this._tokenType$ = new rxjs.BehaviorSubject(undefined);
|
|
14775
14810
|
_this._debug = !environment.production;
|
|
@@ -14779,33 +14814,22 @@
|
|
|
14779
14814
|
// Send auth token to the graphql layer, when changed
|
|
14780
14815
|
_this.onAuthTokenChange.subscribe(function (token) { return _this.graphql.setAuthToken(token); });
|
|
14781
14816
|
_this.onAuthBasicChange.subscribe(function (basic) { return _this.graphql.setAuthBasic(basic); });
|
|
14782
|
-
// Listen graphql start (or restart)
|
|
14783
|
-
_this.graphql.onStart.subscribe(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
14784
|
-
return __generator(this, function (_b) {
|
|
14785
|
-
if (!this._started) {
|
|
14786
|
-
this.ready();
|
|
14787
|
-
}
|
|
14788
|
-
if (this._started && this.isLogin()) {
|
|
14789
|
-
console.debug('[account] Restarting, to retry to authenticate...');
|
|
14790
|
-
this.restart();
|
|
14791
|
-
}
|
|
14792
|
-
return [2 /*return*/];
|
|
14793
|
-
});
|
|
14794
|
-
}); });
|
|
14795
14817
|
// Force network to wait account service, after getting connection to the peer
|
|
14796
14818
|
_this.network.on('beforeTryOnlineFinish', function (online) { return __awaiter(_this, void 0, void 0, function () {
|
|
14797
14819
|
return __generator(this, function (_b) {
|
|
14798
14820
|
switch (_b.label) {
|
|
14799
14821
|
case 0:
|
|
14800
|
-
if (!(online && (!this.
|
|
14801
|
-
console.debug('[account] Force networkService.tryOnline() to wait, that account service is restarted...');
|
|
14802
|
-
//await this.stop();
|
|
14822
|
+
if (!(online && (!this.started || this.isLogin()))) return [3 /*break*/, 3];
|
|
14823
|
+
console.debug('[account] Force networkService.tryOnline() to wait, that graphql and account service is restarted...');
|
|
14803
14824
|
return [4 /*yield*/, sleep(500)];
|
|
14804
14825
|
case 1:
|
|
14805
|
-
|
|
14826
|
+
_b.sent(); // wait graphql service to be restarted
|
|
14827
|
+
if (!!this.started) return [3 /*break*/, 3];
|
|
14828
|
+
return [4 /*yield*/, this.ready()];
|
|
14829
|
+
case 2:
|
|
14806
14830
|
_b.sent();
|
|
14807
|
-
|
|
14808
|
-
case
|
|
14831
|
+
_b.label = 3;
|
|
14832
|
+
case 3: return [2 /*return*/];
|
|
14809
14833
|
}
|
|
14810
14834
|
});
|
|
14811
14835
|
}); });
|
|
@@ -14813,27 +14837,27 @@
|
|
|
14813
14837
|
}
|
|
14814
14838
|
Object.defineProperty(AccountService.prototype, "account", {
|
|
14815
14839
|
get: function () {
|
|
14816
|
-
return this.
|
|
14840
|
+
return this._cache.loaded ? this._data : undefined;
|
|
14817
14841
|
},
|
|
14818
14842
|
enumerable: false,
|
|
14819
14843
|
configurable: true
|
|
14820
14844
|
});
|
|
14821
14845
|
Object.defineProperty(AccountService.prototype, "person", {
|
|
14822
14846
|
get: function () {
|
|
14823
|
-
if (this.
|
|
14824
|
-
this.
|
|
14847
|
+
if (this._cache.loaded && !this._cache.person) {
|
|
14848
|
+
this._cache.person = this._cache.loaded ? this._data.asPerson() : undefined;
|
|
14825
14849
|
}
|
|
14826
|
-
return this.
|
|
14850
|
+
return this._cache.person;
|
|
14827
14851
|
},
|
|
14828
14852
|
enumerable: false,
|
|
14829
14853
|
configurable: true
|
|
14830
14854
|
});
|
|
14831
14855
|
Object.defineProperty(AccountService.prototype, "department", {
|
|
14832
14856
|
get: function () {
|
|
14833
|
-
if (this.
|
|
14834
|
-
this.
|
|
14857
|
+
if (this._cache.loaded && !this._cache.department) {
|
|
14858
|
+
this._cache.department = this._cache.loaded ? this._data.asPerson().department : undefined;
|
|
14835
14859
|
}
|
|
14836
|
-
return this.
|
|
14860
|
+
return this._cache.department;
|
|
14837
14861
|
},
|
|
14838
14862
|
enumerable: false,
|
|
14839
14863
|
configurable: true
|
|
@@ -14847,109 +14871,91 @@
|
|
|
14847
14871
|
console.info('[account] Using authentication token type: ' + value);
|
|
14848
14872
|
this._tokenType$.next(value);
|
|
14849
14873
|
// Reset values
|
|
14850
|
-
this.
|
|
14874
|
+
this._cache.authToken = undefined;
|
|
14851
14875
|
this.onAuthTokenChange.next(undefined);
|
|
14852
|
-
this.
|
|
14876
|
+
this._cache.authBasic = undefined;
|
|
14853
14877
|
this.onAuthBasicChange.next(undefined);
|
|
14854
14878
|
}
|
|
14855
14879
|
},
|
|
14856
14880
|
enumerable: false,
|
|
14857
14881
|
configurable: true
|
|
14858
14882
|
});
|
|
14859
|
-
AccountService.prototype.
|
|
14860
|
-
var _this = this;
|
|
14861
|
-
if (this._startPromise)
|
|
14862
|
-
return this._startPromise;
|
|
14863
|
-
if (this._started)
|
|
14864
|
-
return Promise.resolve(this.account);
|
|
14865
|
-
// Restoring local settings
|
|
14866
|
-
this._startPromise = Promise.all([
|
|
14867
|
-
this.settings.ready(),
|
|
14868
|
-
// Wait token type to be set
|
|
14869
|
-
firstNotNilPromise(this._tokenType$)
|
|
14870
|
-
])
|
|
14871
|
-
.then(function () { return _this.restoreLocally(); })
|
|
14872
|
-
.then(function () {
|
|
14873
|
-
_this._started = true;
|
|
14874
|
-
_this._startPromise = undefined;
|
|
14875
|
-
return _this.account;
|
|
14876
|
-
});
|
|
14877
|
-
return this._startPromise;
|
|
14878
|
-
};
|
|
14879
|
-
Object.defineProperty(AccountService.prototype, "started", {
|
|
14880
|
-
get: function () {
|
|
14881
|
-
return this._started;
|
|
14882
|
-
},
|
|
14883
|
-
enumerable: false,
|
|
14884
|
-
configurable: true
|
|
14885
|
-
});
|
|
14886
|
-
AccountService.prototype.stop = function () {
|
|
14883
|
+
AccountService.prototype.ngOnStart = function () {
|
|
14887
14884
|
return __awaiter(this, void 0, void 0, function () {
|
|
14888
|
-
var
|
|
14885
|
+
var _this = this;
|
|
14889
14886
|
return __generator(this, function (_b) {
|
|
14890
|
-
|
|
14891
|
-
|
|
14892
|
-
|
|
14893
|
-
|
|
14894
|
-
|
|
14895
|
-
|
|
14896
|
-
|
|
14897
|
-
|
|
14898
|
-
|
|
14899
|
-
this.
|
|
14900
|
-
|
|
14901
|
-
|
|
14902
|
-
|
|
14903
|
-
|
|
14904
|
-
|
|
14887
|
+
switch (_b.label) {
|
|
14888
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
14889
|
+
this.settings.ready(),
|
|
14890
|
+
// Wait token type to be set
|
|
14891
|
+
firstNotNilPromise(this._tokenType$)
|
|
14892
|
+
])];
|
|
14893
|
+
case 1:
|
|
14894
|
+
_b.sent();
|
|
14895
|
+
// Listen graphql start (or restart)
|
|
14896
|
+
this.registerSubscription(this.graphql.onStart.subscribe(function () {
|
|
14897
|
+
if (_this.started && _this.isLogin()) {
|
|
14898
|
+
console.debug('[account] Restarting, to retry to authenticate...');
|
|
14899
|
+
_this.restart();
|
|
14900
|
+
}
|
|
14901
|
+
}));
|
|
14902
|
+
return [4 /*yield*/, this.restoreLocally()];
|
|
14903
|
+
case 2:
|
|
14904
|
+
_b.sent();
|
|
14905
|
+
return [4 /*yield*/, this.listenSettings()];
|
|
14906
|
+
case 3:
|
|
14907
|
+
_b.sent();
|
|
14908
|
+
return [2 /*return*/, this._data];
|
|
14905
14909
|
}
|
|
14906
|
-
return [2 /*return*/];
|
|
14907
14910
|
});
|
|
14908
14911
|
});
|
|
14909
14912
|
};
|
|
14910
|
-
AccountService.prototype.
|
|
14913
|
+
AccountService.prototype.ngOnStop = function () {
|
|
14911
14914
|
return __awaiter(this, void 0, void 0, function () {
|
|
14915
|
+
var hadAuthToken, hadAuthBasic, hadAuth;
|
|
14912
14916
|
return __generator(this, function (_b) {
|
|
14913
|
-
|
|
14914
|
-
|
|
14915
|
-
|
|
14916
|
-
|
|
14917
|
-
|
|
14917
|
+
hadAuthToken = this._cache.authToken && true;
|
|
14918
|
+
hadAuthBasic = this._cache.authBasic && true;
|
|
14919
|
+
hadAuth = hadAuthToken || hadAuthBasic;
|
|
14920
|
+
this.resetData();
|
|
14921
|
+
if (hadAuth) {
|
|
14922
|
+
this.onLogout.next();
|
|
14923
|
+
this.onChange.next(undefined);
|
|
14924
|
+
if (hadAuthToken)
|
|
14925
|
+
this.onAuthTokenChange.next(undefined);
|
|
14926
|
+
if (hadAuthBasic)
|
|
14927
|
+
this.onAuthBasicChange.next(undefined);
|
|
14918
14928
|
}
|
|
14929
|
+
return [2 /*return*/];
|
|
14919
14930
|
});
|
|
14920
14931
|
});
|
|
14921
14932
|
};
|
|
14922
|
-
AccountService.prototype.ready = function () {
|
|
14923
|
-
if (this._started)
|
|
14924
|
-
return Promise.resolve(this.account);
|
|
14925
|
-
return this.start();
|
|
14926
|
-
};
|
|
14927
14933
|
AccountService.prototype.isLogin = function () {
|
|
14928
|
-
return !!(this.
|
|
14934
|
+
return !!(this._cache.pubkey && this._cache.loaded);
|
|
14929
14935
|
};
|
|
14930
14936
|
AccountService.prototype.isAuth = function () {
|
|
14931
|
-
return !!(this.
|
|
14937
|
+
return !!(this._cache.pubkey && this._cache.keypair && this._cache.keypair.secretKey);
|
|
14932
14938
|
};
|
|
14933
14939
|
AccountService.prototype.hasMinProfile = function (userProfile) {
|
|
14934
14940
|
// should be login, and status ENABLE or TEMPORARY
|
|
14935
|
-
if (!this._data
|
|
14936
|
-
(this._data.
|
|
14941
|
+
if (!this._data || !this._data.pubkey ||
|
|
14942
|
+
(this._data.statusId !== StatusIds.ENABLE && this._data.statusId !== StatusIds.TEMPORARY)) {
|
|
14937
14943
|
return false;
|
|
14938
14944
|
}
|
|
14939
|
-
return PersonUtils.hasUpperOrEqualsProfile(this._data.
|
|
14945
|
+
return PersonUtils.hasUpperOrEqualsProfile(this._data.profiles, userProfile);
|
|
14940
14946
|
};
|
|
14941
14947
|
AccountService.prototype.hasExactProfile = function (label) {
|
|
14942
14948
|
// should be login, and status ENABLE or TEMPORARY
|
|
14943
|
-
if (!this._data
|
|
14944
|
-
(this._data.
|
|
14949
|
+
if (!this._data || !this._data.pubkey ||
|
|
14950
|
+
(this._data.statusId !== StatusIds.ENABLE && this._data.statusId !== StatusIds.TEMPORARY))
|
|
14945
14951
|
return false;
|
|
14946
|
-
return this._data.
|
|
14952
|
+
return this._data.profiles.some(function (profile) { return profile === label; });
|
|
14947
14953
|
};
|
|
14948
14954
|
AccountService.prototype.hasProfileAndIsEnable = function (userProfile) {
|
|
14949
14955
|
// should be login, and status ENABLE
|
|
14950
|
-
if (!this._data
|
|
14956
|
+
if (!this._data || !this._data.pubkey || this._data.statusId !== StatusIds.ENABLE)
|
|
14951
14957
|
return false;
|
|
14952
|
-
return PersonUtils.hasUpperOrEqualsProfile(this._data.
|
|
14958
|
+
return PersonUtils.hasUpperOrEqualsProfile(this._data.profiles, userProfile);
|
|
14953
14959
|
};
|
|
14954
14960
|
AccountService.prototype.isAdmin = function () {
|
|
14955
14961
|
return this.hasProfileAndIsEnable('ADMIN');
|
|
@@ -14969,11 +14975,11 @@
|
|
|
14969
14975
|
};
|
|
14970
14976
|
AccountService.prototype.isOnlyGuest = function () {
|
|
14971
14977
|
// Should be login, and status ENABLE or TEMPORARY
|
|
14972
|
-
if (!this._data
|
|
14973
|
-
(this._data.
|
|
14978
|
+
if (!this._data || !this._data.pubkey ||
|
|
14979
|
+
(this._data.statusId !== StatusIds.ENABLE && this._data.statusId !== StatusIds.TEMPORARY))
|
|
14974
14980
|
return false;
|
|
14975
14981
|
// Profile less then user
|
|
14976
|
-
return !PersonUtils.hasUpperOrEqualsProfile(this._data.
|
|
14982
|
+
return !PersonUtils.hasUpperOrEqualsProfile(this._data.profiles, 'USER');
|
|
14977
14983
|
};
|
|
14978
14984
|
AccountService.prototype.canUserWriteDataForDepartment = function (recorderDepartment) {
|
|
14979
14985
|
if (ReferentialUtils.isEmpty(recorderDepartment)) {
|
|
@@ -14982,17 +14988,17 @@
|
|
|
14982
14988
|
return this.isAdmin();
|
|
14983
14989
|
}
|
|
14984
14990
|
// Should be login, and status ENABLE
|
|
14985
|
-
if (!this._data
|
|
14991
|
+
if (!this._data || !this._data.pubkey || this._data.statusId !== StatusIds.ENABLE)
|
|
14986
14992
|
return false;
|
|
14987
|
-
if (!this._data.
|
|
14993
|
+
if (!this._data.department || !this._data.department.id) {
|
|
14988
14994
|
console.warn('User account has no department ! Unable to check write right against recorderDepartment');
|
|
14989
14995
|
return false;
|
|
14990
14996
|
}
|
|
14991
14997
|
// Same recorder department: OK, user can write
|
|
14992
|
-
if (this._data.
|
|
14998
|
+
if (this._data.department.id === recorderDepartment.id)
|
|
14993
14999
|
return true;
|
|
14994
15000
|
// Else, check if supervisor (or more)
|
|
14995
|
-
return PersonUtils.hasUpperOrEqualsProfile(this._data.
|
|
15001
|
+
return PersonUtils.hasUpperOrEqualsProfile(this._data.profiles, 'SUPERVISOR');
|
|
14996
15002
|
};
|
|
14997
15003
|
AccountService.prototype.register = function (data) {
|
|
14998
15004
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -15007,7 +15013,7 @@
|
|
|
15007
15013
|
throw new Error('Missing required username or password');
|
|
15008
15014
|
if (this._debug)
|
|
15009
15015
|
console.debug('[account] Register new user account...', data.account);
|
|
15010
|
-
this.
|
|
15016
|
+
this._cache.loaded = false;
|
|
15011
15017
|
now = Date.now();
|
|
15012
15018
|
_b.label = 1;
|
|
15013
15019
|
case 1:
|
|
@@ -15021,29 +15027,29 @@
|
|
|
15021
15027
|
data.account.settings.locale = this.settings.locale;
|
|
15022
15028
|
data.account.settings.latLongFormat = this.settings.latLongFormat;
|
|
15023
15029
|
data.account.department.id = data.account.department.id || this.environment.defaultDepartmentId;
|
|
15024
|
-
this.
|
|
15030
|
+
this._cache.keypair = keypair;
|
|
15025
15031
|
return [4 /*yield*/, this.saveRemotely(data.account, keypair)];
|
|
15026
15032
|
case 3:
|
|
15027
15033
|
account = _b.sent();
|
|
15028
15034
|
// Default values
|
|
15029
15035
|
account.avatar = account.avatar || (this.environment.baseUrl + DEFAULT_AVATAR_IMAGE);
|
|
15030
|
-
this.
|
|
15031
|
-
this._data
|
|
15032
|
-
this.
|
|
15036
|
+
this._cache.mainProfile = PersonUtils.getMainProfile(account.profiles);
|
|
15037
|
+
this._data = account;
|
|
15038
|
+
this._cache.pubkey = account.pubkey;
|
|
15033
15039
|
// Try to auth on pod
|
|
15034
15040
|
return [4 /*yield*/, this.authenticate(data)];
|
|
15035
15041
|
case 4:
|
|
15036
15042
|
// Try to auth on pod
|
|
15037
15043
|
_b.sent();
|
|
15038
|
-
this.
|
|
15044
|
+
this._cache.loaded = true;
|
|
15039
15045
|
return [4 /*yield*/, this.saveLocally()];
|
|
15040
15046
|
case 5:
|
|
15041
15047
|
_b.sent();
|
|
15042
15048
|
console.debug("[account] Account successfully registered in " + (Date.now() - now) + "ms");
|
|
15043
15049
|
// Emit events
|
|
15044
|
-
this.onLogin.next(this._data
|
|
15045
|
-
this.onChange.next(this._data
|
|
15046
|
-
return [2 /*return*/, this._data
|
|
15050
|
+
this.onLogin.next(this._data);
|
|
15051
|
+
this.onChange.next(this._data);
|
|
15052
|
+
return [2 /*return*/, this._data];
|
|
15047
15053
|
case 6:
|
|
15048
15054
|
error_1 = _b.sent();
|
|
15049
15055
|
console.error(error_1 && error_1.message || error_1);
|
|
@@ -15065,22 +15071,22 @@
|
|
|
15065
15071
|
// Basic auth
|
|
15066
15072
|
if (tokenType === 'basic' || tokenType === 'basic-and-token') {
|
|
15067
15073
|
// Generate the authBasic, if used
|
|
15068
|
-
if (!this.
|
|
15074
|
+
if (!this._cache.authBasic) {
|
|
15069
15075
|
// Skip if token already provided
|
|
15070
|
-
if (!(this.
|
|
15076
|
+
if (!(this._cache.authToken && tokenType === 'basic-and-token')) {
|
|
15071
15077
|
if (!data || !data.username || !data.password)
|
|
15072
15078
|
throw new Error('Missing username and password');
|
|
15073
|
-
this.
|
|
15079
|
+
this._cache.authBasic = this.cryptoService.encodeBase64(data.username + ":" + data.password);
|
|
15074
15080
|
}
|
|
15075
15081
|
}
|
|
15076
|
-
this.onAuthBasicChange.next(this.
|
|
15082
|
+
this.onAuthBasicChange.next(this._cache.authBasic);
|
|
15077
15083
|
}
|
|
15078
15084
|
if (!(tokenType === 'token' || tokenType === 'basic-and-token')) return [3 /*break*/, 5];
|
|
15079
15085
|
_c.label = 2;
|
|
15080
15086
|
case 2:
|
|
15081
15087
|
_c.trys.push([2, 4, , 5]);
|
|
15082
|
-
_b = this.
|
|
15083
|
-
return [4 /*yield*/, this.authenticateAndGetToken(this.
|
|
15088
|
+
_b = this._cache;
|
|
15089
|
+
return [4 /*yield*/, this.authenticateAndGetToken(this._cache.authToken)];
|
|
15084
15090
|
case 3:
|
|
15085
15091
|
_b.authToken = _c.sent();
|
|
15086
15092
|
return [3 /*break*/, 5];
|
|
@@ -15093,7 +15099,7 @@
|
|
|
15093
15099
|
case 5:
|
|
15094
15100
|
// Forget authBasic, to switch to authToken
|
|
15095
15101
|
if (tokenType === 'basic-and-token') {
|
|
15096
|
-
this.
|
|
15102
|
+
this._cache.authBasic = undefined;
|
|
15097
15103
|
this.onAuthBasicChange.next(undefined);
|
|
15098
15104
|
}
|
|
15099
15105
|
return [2 /*return*/];
|
|
@@ -15124,18 +15130,18 @@
|
|
|
15124
15130
|
throw { code: ErrorCodes$2.UNKNOWN_ERROR, message: 'ERROR.SCRYPT_ERROR' };
|
|
15125
15131
|
case 4:
|
|
15126
15132
|
// Store pubkey+keypair
|
|
15127
|
-
this.
|
|
15128
|
-
this.
|
|
15133
|
+
this._cache.pubkey = Base58.encode(keypair.publicKey);
|
|
15134
|
+
this._cache.keypair = keypair;
|
|
15129
15135
|
return [4 /*yield*/, this.storage.get(TOKEN_STORAGE_KEY)];
|
|
15130
15136
|
case 5:
|
|
15131
15137
|
previousToken = _b.sent();
|
|
15132
|
-
previousToken = previousToken && previousToken.startsWith(this.
|
|
15138
|
+
previousToken = previousToken && previousToken.startsWith(this._cache.pubkey) && previousToken || null;
|
|
15133
15139
|
offline = this.settings.hasOfflineFeature() && (this.network.offline || data.offline === true);
|
|
15134
15140
|
if (!offline) return [3 /*break*/, 6];
|
|
15135
|
-
this.
|
|
15141
|
+
this._cache.authToken = previousToken;
|
|
15136
15142
|
// Make sure network if set as offline
|
|
15137
15143
|
this.network.setForceOffline(true, { showToast: false });
|
|
15138
|
-
console.info("[account] Login [OK] {pubkey: " + this.
|
|
15144
|
+
console.info("[account] Login [OK] {pubkey: " + this._cache.pubkey.substr(0, 8) + "}, {offline: true}");
|
|
15139
15145
|
return [3 /*break*/, 9];
|
|
15140
15146
|
case 6:
|
|
15141
15147
|
_b.trys.push([6, 8, , 9]);
|
|
@@ -15195,9 +15201,9 @@
|
|
|
15195
15201
|
throw error_5;
|
|
15196
15202
|
case 21:
|
|
15197
15203
|
// Emit event to observers
|
|
15198
|
-
this.onLogin.next(this._data
|
|
15199
|
-
this.onChange.next(this._data
|
|
15200
|
-
return [2 /*return*/, this._data
|
|
15204
|
+
this.onLogin.next(this._data);
|
|
15205
|
+
this.onChange.next(this._data);
|
|
15206
|
+
return [2 /*return*/, this._data];
|
|
15201
15207
|
}
|
|
15202
15208
|
});
|
|
15203
15209
|
});
|
|
@@ -15207,7 +15213,7 @@
|
|
|
15207
15213
|
return __generator(this, function (_b) {
|
|
15208
15214
|
switch (_b.label) {
|
|
15209
15215
|
case 0:
|
|
15210
|
-
if (!this.
|
|
15216
|
+
if (!this._cache.pubkey)
|
|
15211
15217
|
throw new Error('User not logged');
|
|
15212
15218
|
if (this.network.offline)
|
|
15213
15219
|
throw new Error('Cannot check account in offline mode');
|
|
@@ -15219,9 +15225,9 @@
|
|
|
15219
15225
|
_b.sent();
|
|
15220
15226
|
console.debug('[account] Successfully reload account');
|
|
15221
15227
|
// Emit login event to subscribers
|
|
15222
|
-
this.onLogin.next(this._data
|
|
15223
|
-
this.onChange.next(this._data
|
|
15224
|
-
return [2 /*return*/, this._data
|
|
15228
|
+
this.onLogin.next(this._data);
|
|
15229
|
+
this.onChange.next(this._data);
|
|
15230
|
+
return [2 /*return*/, this._data];
|
|
15225
15231
|
}
|
|
15226
15232
|
});
|
|
15227
15233
|
});
|
|
@@ -15236,27 +15242,27 @@
|
|
|
15236
15242
|
return __generator(this, function (_b) {
|
|
15237
15243
|
switch (_b.label) {
|
|
15238
15244
|
case 0:
|
|
15239
|
-
if (!this.
|
|
15245
|
+
if (!this._cache.pubkey)
|
|
15240
15246
|
return [2 /*return*/, Promise.reject('User not logged')];
|
|
15241
|
-
if (this.
|
|
15247
|
+
if (this._cache.pubkey !== account.pubkey)
|
|
15242
15248
|
return [2 /*return*/, Promise.reject('Not user account')];
|
|
15243
|
-
return [4 /*yield*/, this.saveRemotely(account, this.
|
|
15249
|
+
return [4 /*yield*/, this.saveRemotely(account, this._cache.keypair)];
|
|
15244
15250
|
case 1:
|
|
15245
15251
|
account = _b.sent();
|
|
15246
15252
|
// Set defaults
|
|
15247
15253
|
account.avatar = account.avatar || (this.environment.baseUrl + DEFAULT_AVATAR_IMAGE);
|
|
15248
|
-
this.
|
|
15249
|
-
this._data
|
|
15250
|
-
this.
|
|
15254
|
+
this._cache.mainProfile = PersonUtils.getMainProfile(account.profiles);
|
|
15255
|
+
this._data = account;
|
|
15256
|
+
this._cache.loaded = true;
|
|
15251
15257
|
// Save locally (in storage)
|
|
15252
15258
|
return [4 /*yield*/, this.saveLocally()];
|
|
15253
15259
|
case 2:
|
|
15254
15260
|
// Save locally (in storage)
|
|
15255
15261
|
_b.sent();
|
|
15256
15262
|
// Send event
|
|
15257
|
-
this.onLogin.next(this._data
|
|
15258
|
-
this.onChange.next(this._data
|
|
15259
|
-
return [2 /*return*/, this._data
|
|
15263
|
+
this.onLogin.next(this._data);
|
|
15264
|
+
this.onChange.next(this._data);
|
|
15265
|
+
return [2 /*return*/, this._data];
|
|
15260
15266
|
}
|
|
15261
15267
|
});
|
|
15262
15268
|
});
|
|
@@ -15267,9 +15273,9 @@
|
|
|
15267
15273
|
return __generator(this, function (_b) {
|
|
15268
15274
|
switch (_b.label) {
|
|
15269
15275
|
case 0:
|
|
15270
|
-
hadAuthToken = this.
|
|
15271
|
-
hadAuthBasic = this.
|
|
15272
|
-
pubkey = this.
|
|
15276
|
+
hadAuthToken = this._cache.authToken && true;
|
|
15277
|
+
hadAuthBasic = this._cache.authBasic && true;
|
|
15278
|
+
pubkey = this._cache && this._cache.pubkey;
|
|
15273
15279
|
this.resetData();
|
|
15274
15280
|
if (!!this.settings.hasOfflineFeature()) return [3 /*break*/, 2];
|
|
15275
15281
|
// Remove all data from the local storage
|
|
@@ -15341,9 +15347,9 @@
|
|
|
15341
15347
|
case 1:
|
|
15342
15348
|
json = _b.sent();
|
|
15343
15349
|
json = json && (typeof json === 'string') && JSON.parse(json) || json;
|
|
15344
|
-
json = json && this.
|
|
15345
|
-
if (!(!json && this.
|
|
15346
|
-
return [4 /*yield*/, this.storage.get(ACCOUNT_STORAGE_KEY + '#' + this.
|
|
15350
|
+
json = json && this._cache.pubkey && (json.pubkey === this._cache.pubkey) && json || null;
|
|
15351
|
+
if (!(!json && this._cache.pubkey)) return [3 /*break*/, 3];
|
|
15352
|
+
return [4 /*yield*/, this.storage.get(ACCOUNT_STORAGE_KEY + '#' + this._cache.pubkey)];
|
|
15347
15353
|
case 2:
|
|
15348
15354
|
json = _b.sent();
|
|
15349
15355
|
json = json && (typeof json === 'string') && JSON.parse(json) || json;
|
|
@@ -15475,7 +15481,7 @@
|
|
|
15475
15481
|
};
|
|
15476
15482
|
AccountService.prototype.listenChanges = function () {
|
|
15477
15483
|
var _this = this;
|
|
15478
|
-
if (!this.
|
|
15484
|
+
if (!this._cache.pubkey)
|
|
15479
15485
|
return rxjs.Subscription.EMPTY;
|
|
15480
15486
|
var self = this;
|
|
15481
15487
|
console.debug('[account] [WS] Listening account changes');
|
|
@@ -15498,7 +15504,7 @@
|
|
|
15498
15504
|
case 0:
|
|
15499
15505
|
if (!data)
|
|
15500
15506
|
return [2 /*return*/];
|
|
15501
|
-
existingUpdateDate = toDateISOString((_a = self._data
|
|
15507
|
+
existingUpdateDate = toDateISOString((_a = self._data) === null || _a === void 0 ? void 0 : _a.updateDate);
|
|
15502
15508
|
if (!(existingUpdateDate !== data.updateDate)) return [3 /*break*/, 2];
|
|
15503
15509
|
console.debug("[account] [WS] Detected update on {" + data.updateDate + "}");
|
|
15504
15510
|
return [4 /*yield*/, self.refresh()];
|
|
@@ -15542,27 +15548,6 @@
|
|
|
15542
15548
|
subscription.add(function () { return console.debug('[account] [WS] Stop listening account changes'); });
|
|
15543
15549
|
return subscription;
|
|
15544
15550
|
};
|
|
15545
|
-
/**
|
|
15546
|
-
* @deprecated
|
|
15547
|
-
*/
|
|
15548
|
-
AccountService.prototype.getPageSettings = function (pageId, propertyName) {
|
|
15549
|
-
return this.settings.getPageSettings(pageId, propertyName);
|
|
15550
|
-
};
|
|
15551
|
-
/**
|
|
15552
|
-
* @deprecated
|
|
15553
|
-
*/
|
|
15554
|
-
AccountService.prototype.savePageSetting = function (pageId, value, propertyName) {
|
|
15555
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
15556
|
-
return __generator(this, function (_b) {
|
|
15557
|
-
switch (_b.label) {
|
|
15558
|
-
case 0: return [4 /*yield*/, this.settings.savePageSetting(pageId, value, propertyName)];
|
|
15559
|
-
case 1:
|
|
15560
|
-
_b.sent();
|
|
15561
|
-
return [2 /*return*/];
|
|
15562
|
-
}
|
|
15563
|
-
});
|
|
15564
|
-
});
|
|
15565
|
-
};
|
|
15566
15551
|
Object.defineProperty(AccountService.prototype, "additionalFields", {
|
|
15567
15552
|
get: function () {
|
|
15568
15553
|
return this._$additionalFields.getValue();
|
|
@@ -15591,28 +15576,28 @@
|
|
|
15591
15576
|
};
|
|
15592
15577
|
/* -- protected method -- */
|
|
15593
15578
|
AccountService.prototype.resetData = function () {
|
|
15594
|
-
this.
|
|
15595
|
-
this.
|
|
15596
|
-
this.
|
|
15597
|
-
this.
|
|
15598
|
-
this.
|
|
15599
|
-
this.
|
|
15600
|
-
this.
|
|
15601
|
-
this.
|
|
15602
|
-
this._data
|
|
15579
|
+
this._cache.loaded = false;
|
|
15580
|
+
this._cache.keypair = null;
|
|
15581
|
+
this._cache.authToken = null;
|
|
15582
|
+
this._cache.authBasic = null;
|
|
15583
|
+
this._cache.pubkey = null;
|
|
15584
|
+
this._cache.mainProfile = null;
|
|
15585
|
+
this._cache.person = null;
|
|
15586
|
+
this._cache.department = null;
|
|
15587
|
+
this._data = new exports.Account();
|
|
15603
15588
|
};
|
|
15604
15589
|
AccountService.prototype.loadData = function (opts) {
|
|
15605
15590
|
return __awaiter(this, void 0, void 0, function () {
|
|
15606
|
-
var account, error_6;
|
|
15591
|
+
var account, accountSettingsContentKeys, settings, error_6;
|
|
15607
15592
|
return __generator(this, function (_b) {
|
|
15608
15593
|
switch (_b.label) {
|
|
15609
15594
|
case 0:
|
|
15610
|
-
if (!this.
|
|
15595
|
+
if (!this._cache.pubkey)
|
|
15611
15596
|
throw new Error('User not logged');
|
|
15612
|
-
this.
|
|
15597
|
+
this._cache.loaded = false;
|
|
15613
15598
|
_b.label = 1;
|
|
15614
15599
|
case 1:
|
|
15615
|
-
_b.trys.push([1,
|
|
15600
|
+
_b.trys.push([1, 5, , 6]);
|
|
15616
15601
|
return [4 /*yield*/, this.load(opts)];
|
|
15617
15602
|
case 2:
|
|
15618
15603
|
account = (_b.sent()) || new exports.Account();
|
|
@@ -15621,18 +15606,27 @@
|
|
|
15621
15606
|
account.settings = account.settings || new exports.UserSettings();
|
|
15622
15607
|
account.settings.locale = account.settings.locale || this.settings.locale;
|
|
15623
15608
|
account.settings.latLongFormat = account.settings.latLongFormat || this.settings.latLongFormat || 'DDMM';
|
|
15609
|
+
account.settings.content = account.settings.content || {};
|
|
15624
15610
|
// Read main profile
|
|
15625
|
-
this.
|
|
15611
|
+
this._cache.mainProfile = PersonUtils.getMainProfile(account.profiles);
|
|
15626
15612
|
// Update, instead of replace it
|
|
15627
|
-
if (this._data
|
|
15628
|
-
this._data.
|
|
15613
|
+
if (this._data) {
|
|
15614
|
+
this._data.fromObject(account);
|
|
15629
15615
|
}
|
|
15630
15616
|
else {
|
|
15631
|
-
this._data
|
|
15617
|
+
this._data = account;
|
|
15632
15618
|
}
|
|
15633
|
-
this.
|
|
15634
|
-
|
|
15619
|
+
this._cache.loaded = true;
|
|
15620
|
+
accountSettingsContentKeys = Object.keys(account.settings.content);
|
|
15621
|
+
if (!isNotEmptyArray(accountSettingsContentKeys)) return [3 /*break*/, 4];
|
|
15622
|
+
settings = Object.assign(Object.assign(Object.assign({}, this.settings.settings), account.settings.content), account.settings);
|
|
15623
|
+
delete settings.content; // Remove content attribute
|
|
15624
|
+
return [4 /*yield*/, this.settings.apply(settings)];
|
|
15635
15625
|
case 3:
|
|
15626
|
+
_b.sent();
|
|
15627
|
+
_b.label = 4;
|
|
15628
|
+
case 4: return [2 /*return*/, this._data];
|
|
15629
|
+
case 5:
|
|
15636
15630
|
error_6 = _b.sent();
|
|
15637
15631
|
this.resetData();
|
|
15638
15632
|
if (error_6.code && error_6.message)
|
|
@@ -15642,11 +15636,23 @@
|
|
|
15642
15636
|
code: ErrorCodes$2.LOAD_ACCOUNT_ERROR,
|
|
15643
15637
|
message: 'ERROR.LOAD_ACCOUNT_ERROR'
|
|
15644
15638
|
};
|
|
15645
|
-
case
|
|
15639
|
+
case 6: return [2 /*return*/];
|
|
15646
15640
|
}
|
|
15647
15641
|
});
|
|
15648
15642
|
});
|
|
15649
15643
|
};
|
|
15644
|
+
AccountService.prototype.listenSettings = function () {
|
|
15645
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
15646
|
+
var _this = this;
|
|
15647
|
+
return __generator(this, function (_b) {
|
|
15648
|
+
// When settings changed: save it remotely
|
|
15649
|
+
this.registerSubscription(this.settings.onChange
|
|
15650
|
+
.pipe(operators.debounceTime(1000), operators.filter(function () { return _this.isLogin() && _this.network.online; }))
|
|
15651
|
+
.subscribe(function (settings) { return _this.saveLocalSettingsRemotely(settings); }));
|
|
15652
|
+
return [2 /*return*/];
|
|
15653
|
+
});
|
|
15654
|
+
});
|
|
15655
|
+
};
|
|
15650
15656
|
AccountService.prototype.restoreLocally = function () {
|
|
15651
15657
|
return __awaiter(this, void 0, void 0, function () {
|
|
15652
15658
|
var values, pubkey, token, seckey, canRemoteAuth, error_7, jsonAccount, accountStr, account;
|
|
@@ -15670,9 +15676,9 @@
|
|
|
15670
15676
|
return [2 /*return*/];
|
|
15671
15677
|
if (this._debug)
|
|
15672
15678
|
console.debug("[account] Account restoration...");
|
|
15673
|
-
this.
|
|
15674
|
-
this.
|
|
15675
|
-
this.
|
|
15679
|
+
this._cache.authToken = token;
|
|
15680
|
+
this._cache.pubkey = pubkey;
|
|
15681
|
+
this._cache.keypair = seckey && {
|
|
15676
15682
|
publicKey: Base58.decode(pubkey),
|
|
15677
15683
|
secretKey: Base58.decode(seckey)
|
|
15678
15684
|
} || null;
|
|
@@ -15683,7 +15689,7 @@
|
|
|
15683
15689
|
return [4 /*yield*/, this.authenticate()];
|
|
15684
15690
|
case 3:
|
|
15685
15691
|
_b.sent();
|
|
15686
|
-
if (!this.
|
|
15692
|
+
if (!this._cache.authToken && !this._cache.authBasic)
|
|
15687
15693
|
throw new Error('Authentication failed');
|
|
15688
15694
|
return [3 /*break*/, 5];
|
|
15689
15695
|
case 4:
|
|
@@ -15716,14 +15722,14 @@
|
|
|
15716
15722
|
return [2 /*return*/];
|
|
15717
15723
|
account = exports.Account.fromObject(jsonAccount);
|
|
15718
15724
|
// Update data
|
|
15719
|
-
this._data
|
|
15720
|
-
this.
|
|
15721
|
-
this.
|
|
15725
|
+
this._data = account;
|
|
15726
|
+
this._cache.mainProfile = PersonUtils.getMainProfile(account.profiles);
|
|
15727
|
+
this._cache.loaded = true;
|
|
15722
15728
|
// Emit event
|
|
15723
|
-
this.onLogin.next(this._data
|
|
15724
|
-
this.onChange.next(this._data
|
|
15729
|
+
this.onLogin.next(this._data);
|
|
15730
|
+
this.onChange.next(this._data);
|
|
15725
15731
|
if (this._debug)
|
|
15726
|
-
console.debug("[account] Account restoration [OK] {pubkey: " + pubkey.substr(0, 8) + "}, {profile: " + this.
|
|
15732
|
+
console.debug("[account] Account restoration [OK] {pubkey: " + pubkey.substr(0, 8) + "}, {profile: " + this._cache.mainProfile + "}");
|
|
15727
15733
|
return [2 /*return*/, account];
|
|
15728
15734
|
}
|
|
15729
15735
|
});
|
|
@@ -15739,12 +15745,12 @@
|
|
|
15739
15745
|
return __generator(this, function (_b) {
|
|
15740
15746
|
switch (_b.label) {
|
|
15741
15747
|
case 0:
|
|
15742
|
-
if (!this.
|
|
15748
|
+
if (!this._cache.pubkey)
|
|
15743
15749
|
throw new Error('User not logged');
|
|
15744
15750
|
if (this._debug)
|
|
15745
|
-
console.debug("[account] Saving account {" + this.
|
|
15746
|
-
json = this._data.
|
|
15747
|
-
seckey = this.
|
|
15751
|
+
console.debug("[account] Saving account {" + this._cache.pubkey.substring(0, 6) + "} in local storage...");
|
|
15752
|
+
json = this._data.asObject({ keepTypename: true });
|
|
15753
|
+
seckey = this._cache.keypair && this._cache.keypair.secretKey && Base58.encode(this._cache.keypair.secretKey) || null;
|
|
15748
15754
|
hasAvatarUrl = json.avatar && !json.avatar.endsWith(DEFAULT_AVATAR_IMAGE) &&
|
|
15749
15755
|
(json.avatar.startsWith('http://') || (json.avatar.startsWith('https://')));
|
|
15750
15756
|
if (!(hasAvatarUrl && this.network.online)) return [3 /*break*/, 2];
|
|
@@ -15767,9 +15773,9 @@
|
|
|
15767
15773
|
case 2:
|
|
15768
15774
|
_b.trys.push([2, 4, , 5]);
|
|
15769
15775
|
return [4 /*yield*/, Promise.all([
|
|
15770
|
-
this.storage.set(PUBKEY_STORAGE_KEY, this.
|
|
15771
|
-
this.storage.set(TOKEN_STORAGE_KEY, this.
|
|
15772
|
-
this.storage.set(ACCOUNT_STORAGE_KEY + "#" + this.
|
|
15776
|
+
this.storage.set(PUBKEY_STORAGE_KEY, this._cache.pubkey),
|
|
15777
|
+
this.storage.set(TOKEN_STORAGE_KEY, this._cache.authToken),
|
|
15778
|
+
this.storage.set(ACCOUNT_STORAGE_KEY + "#" + this._cache.pubkey, json),
|
|
15773
15779
|
// Secret key (optional)
|
|
15774
15780
|
seckey && this.storage.set(SECKEY_STORAGE_KEY, seckey) || this.storage.remove(SECKEY_STORAGE_KEY),
|
|
15775
15781
|
// Remove old storage key
|
|
@@ -15789,6 +15795,30 @@
|
|
|
15789
15795
|
});
|
|
15790
15796
|
});
|
|
15791
15797
|
};
|
|
15798
|
+
AccountService.prototype.saveLocalSettingsRemotely = function (source) {
|
|
15799
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
15800
|
+
var account, settings, hasChanges;
|
|
15801
|
+
return __generator(this, function (_b) {
|
|
15802
|
+
switch (_b.label) {
|
|
15803
|
+
case 0:
|
|
15804
|
+
if (!source || !this.isLogin())
|
|
15805
|
+
return [2 /*return*/]; // Skip
|
|
15806
|
+
account = this.account;
|
|
15807
|
+
settings = exports.UserSettings.fromObject(account.settings) || new exports.UserSettings();
|
|
15808
|
+
hasChanges = settings.merge(source, ['locale', 'latLongFormat', 'properties']);
|
|
15809
|
+
if (!hasChanges) return [3 /*break*/, 2];
|
|
15810
|
+
if (this._debug)
|
|
15811
|
+
console.debug('[account] Save local settings remotely', settings);
|
|
15812
|
+
account.settings = settings;
|
|
15813
|
+
return [4 /*yield*/, this.saveRemotely(account)];
|
|
15814
|
+
case 1:
|
|
15815
|
+
_b.sent();
|
|
15816
|
+
_b.label = 2;
|
|
15817
|
+
case 2: return [2 /*return*/];
|
|
15818
|
+
}
|
|
15819
|
+
});
|
|
15820
|
+
});
|
|
15821
|
+
};
|
|
15792
15822
|
/**
|
|
15793
15823
|
* Create or update an user account
|
|
15794
15824
|
*
|
|
@@ -15846,7 +15876,7 @@
|
|
|
15846
15876
|
return __generator(this, function (_b) {
|
|
15847
15877
|
switch (_b.label) {
|
|
15848
15878
|
case 0:
|
|
15849
|
-
if (!this.
|
|
15879
|
+
if (!this._cache.pubkey)
|
|
15850
15880
|
throw new Error('User not logged');
|
|
15851
15881
|
if (!counter)
|
|
15852
15882
|
console.info('[account] Authentication on pod...');
|
|
@@ -15873,7 +15903,7 @@
|
|
|
15873
15903
|
if (data_1 && data_1.authenticate) {
|
|
15874
15904
|
// Store the token
|
|
15875
15905
|
this.onAuthTokenChange.next(token);
|
|
15876
|
-
console.info("[account] Authentication on pod [OK] {pubkey: '" + this.
|
|
15906
|
+
console.info("[account] Authentication on pod [OK] {pubkey: '" + this._cache.pubkey.substr(0, 8) + "'}");
|
|
15877
15907
|
return [2 /*return*/, token]; // return the token
|
|
15878
15908
|
}
|
|
15879
15909
|
_b.label = 2;
|
|
@@ -15899,10 +15929,10 @@
|
|
|
15899
15929
|
if (!signatureOK) {
|
|
15900
15930
|
console.warn('FIXME: Bad peer signature on auth challenge !', data.authChallenge);
|
|
15901
15931
|
}
|
|
15902
|
-
return [4 /*yield*/, this.cryptoService.sign(data.authChallenge.challenge, this.
|
|
15932
|
+
return [4 /*yield*/, this.cryptoService.sign(data.authChallenge.challenge, this._cache.keypair)];
|
|
15903
15933
|
case 5:
|
|
15904
15934
|
signature = _b.sent();
|
|
15905
|
-
newToken = this.
|
|
15935
|
+
newToken = this._cache.pubkey + ":" + data.authChallenge.challenge + "|" + signature;
|
|
15906
15936
|
return [4 /*yield*/, this.authenticateAndGetToken(newToken, (counter || 1) + 1 /* increment */)];
|
|
15907
15937
|
case 6:
|
|
15908
15938
|
// iterate with the new token
|
|
@@ -16207,94 +16237,42 @@
|
|
|
16207
16237
|
_this.toastController = toastController;
|
|
16208
16238
|
_this.translate = translate;
|
|
16209
16239
|
_this.environment = environment;
|
|
16210
|
-
_this._started = false;
|
|
16211
|
-
_this._subscription = new rxjs.Subscription();
|
|
16212
16240
|
_this.$data = new rxjs.BehaviorSubject(null);
|
|
16213
16241
|
_this._debug = !environment.production;
|
|
16214
16242
|
if (_this._debug)
|
|
16215
16243
|
console.debug('[config] Creating service');
|
|
16216
16244
|
_this._optionDefs = Object.values(Object.assign(Object.assign({}, CORE_CONFIG_OPTIONS), defaultOptionsMap));
|
|
16217
|
-
// Restart if graphql service restart
|
|
16218
|
-
_this.graphql.onStart.subscribe(function () { return _this.restart(); });
|
|
16219
|
-
// Start
|
|
16220
|
-
if (_this.graphql.started) {
|
|
16221
|
-
_this.start();
|
|
16222
|
-
}
|
|
16223
16245
|
return _this;
|
|
16224
16246
|
}
|
|
16225
|
-
Object.defineProperty(ConfigService.prototype, "started", {
|
|
16226
|
-
get: function () {
|
|
16227
|
-
return this._started;
|
|
16228
|
-
},
|
|
16229
|
-
enumerable: false,
|
|
16230
|
-
configurable: true
|
|
16231
|
-
});
|
|
16232
16247
|
Object.defineProperty(ConfigService.prototype, "config", {
|
|
16233
16248
|
get: function () {
|
|
16234
16249
|
// If first call: start loading
|
|
16235
|
-
if (!this.
|
|
16250
|
+
if (!this.started)
|
|
16236
16251
|
this.start();
|
|
16237
16252
|
return this.$data.pipe(operators.filter(isNotNil));
|
|
16238
16253
|
},
|
|
16239
16254
|
enumerable: false,
|
|
16240
16255
|
configurable: true
|
|
16241
16256
|
});
|
|
16242
|
-
ConfigService.prototype.
|
|
16243
|
-
var _this = this;
|
|
16244
|
-
if (this._startPromise)
|
|
16245
|
-
return this._startPromise;
|
|
16246
|
-
if (this._started)
|
|
16247
|
-
return;
|
|
16248
|
-
console.info('[config] Starting configuration...');
|
|
16249
|
-
this._startPromise = this.graphql.ready()
|
|
16250
|
-
.then(function () { return _this.loadOrRestoreLocally(); })
|
|
16251
|
-
.then(function (data) {
|
|
16252
|
-
_this._started = true;
|
|
16253
|
-
_this._startPromise = undefined;
|
|
16254
|
-
_this.$data.next(data);
|
|
16255
|
-
return data;
|
|
16256
|
-
})
|
|
16257
|
-
.catch(function (err) {
|
|
16258
|
-
console.error(err && err.message || err, err);
|
|
16259
|
-
_this._started = false;
|
|
16260
|
-
_this._startPromise = undefined;
|
|
16261
|
-
return null;
|
|
16262
|
-
});
|
|
16263
|
-
return this._startPromise;
|
|
16264
|
-
};
|
|
16265
|
-
ConfigService.prototype.stop = function () {
|
|
16266
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
16267
|
-
return __generator(this, function (_a) {
|
|
16268
|
-
this._subscription.unsubscribe();
|
|
16269
|
-
this._subscription = new rxjs.Subscription();
|
|
16270
|
-
this._started = false;
|
|
16271
|
-
this._startPromise = undefined;
|
|
16272
|
-
return [2 /*return*/];
|
|
16273
|
-
});
|
|
16274
|
-
});
|
|
16275
|
-
};
|
|
16276
|
-
ConfigService.prototype.restart = function () {
|
|
16257
|
+
ConfigService.prototype.ngOnStart = function () {
|
|
16277
16258
|
return __awaiter(this, void 0, void 0, function () {
|
|
16259
|
+
var data;
|
|
16260
|
+
var _this = this;
|
|
16278
16261
|
return __generator(this, function (_a) {
|
|
16279
16262
|
switch (_a.label) {
|
|
16280
16263
|
case 0:
|
|
16281
|
-
|
|
16282
|
-
return [4 /*yield*/, this.
|
|
16264
|
+
console.info('[config] Starting configuration...');
|
|
16265
|
+
return [4 /*yield*/, this.loadOrRestoreLocally()];
|
|
16283
16266
|
case 1:
|
|
16284
|
-
_a.sent();
|
|
16285
|
-
|
|
16286
|
-
|
|
16267
|
+
data = _a.sent();
|
|
16268
|
+
this.$data.next(data);
|
|
16269
|
+
// Restart if graphql service restart
|
|
16270
|
+
this.registerSubscription(this.graphql.onStart.subscribe(function () { return _this.restart(); }));
|
|
16271
|
+
return [2 /*return*/, data];
|
|
16287
16272
|
}
|
|
16288
16273
|
});
|
|
16289
16274
|
});
|
|
16290
16275
|
};
|
|
16291
|
-
ConfigService.prototype.ready = function () {
|
|
16292
|
-
if (this._started)
|
|
16293
|
-
return Promise.resolve(this.$data.value);
|
|
16294
|
-
if (this._startPromise)
|
|
16295
|
-
return this._startPromise;
|
|
16296
|
-
return this.start();
|
|
16297
|
-
};
|
|
16298
16276
|
ConfigService.prototype.loadDefault = function (opts) {
|
|
16299
16277
|
return __awaiter(this, void 0, void 0, function () {
|
|
16300
16278
|
var now, query, variables, res, data;
|
|
@@ -22832,12 +22810,6 @@
|
|
|
22832
22810
|
_this.defaultSortBy = options.defaultSortBy || 'id';
|
|
22833
22811
|
_this.defaultSortDirection = options.defaultSortDirection || 'asc';
|
|
22834
22812
|
_this.watchQueriesUpdatePolicy = options.watchQueriesUpdatePolicy || 'update-cache';
|
|
22835
|
-
platform.ready().then(function () {
|
|
22836
|
-
// No limit for updatable watch queries, if desktop
|
|
22837
|
-
if (!platform.mobile) {
|
|
22838
|
-
_this._mutableWatchQueriesMaxCount = -1;
|
|
22839
|
-
}
|
|
22840
|
-
});
|
|
22841
22813
|
var obj = new dataType();
|
|
22842
22814
|
_this._typename = obj.__typename || 'UnknownVO';
|
|
22843
22815
|
_this._logTypeName = removeEnd(_this._typename, 'VO');
|
|
@@ -23293,6 +23265,17 @@
|
|
|
23293
23265
|
return EntityFilterUtils.fromObject(source, this.filterType);
|
|
23294
23266
|
};
|
|
23295
23267
|
/* -- protected functions -- */
|
|
23268
|
+
BaseEntityService.prototype.ngOnStart = function () {
|
|
23269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
23270
|
+
return __generator(this, function (_b) {
|
|
23271
|
+
// No limit for updatable watch queries, if desktop
|
|
23272
|
+
if (!this.platform.mobile) {
|
|
23273
|
+
this._mutableWatchQueriesMaxCount = -1;
|
|
23274
|
+
}
|
|
23275
|
+
return [2 /*return*/];
|
|
23276
|
+
});
|
|
23277
|
+
});
|
|
23278
|
+
};
|
|
23296
23279
|
BaseEntityService.prototype.fillDefaultProperties = function (source) {
|
|
23297
23280
|
// Can be override by subclasses
|
|
23298
23281
|
};
|