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