eservices-core 1.0.521 → 1.0.522

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +228 -220
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * eservices-core v1.0.521
2
+ * eservices-core v1.0.522
3
3
  * (c) 2023 ESERVICES
4
4
  */
5
5
  'use strict';
@@ -1903,6 +1903,8 @@ class CoreError extends Error {
1903
1903
  Please try again later or submit a feedback if problem doesn't go.`);
1904
1904
  }
1905
1905
  static AuthServiceError(message, errors) {
1906
+ if (!message && !errors)
1907
+ return CoreError.ApiNotAvailable();
1906
1908
  return new CoreError(message || 'Authorization Error', errors);
1907
1909
  }
1908
1910
  static ApiResponseParseFailed() {
@@ -1965,6 +1967,225 @@ function ErrorModel(message, details = []) {
1965
1967
  };
1966
1968
  }
1967
1969
 
1970
+ class clientService {
1971
+ static getClientData() {
1972
+ return Request('/close-api/client-content');
1973
+ }
1974
+ }
1975
+
1976
+ /*!
1977
+ * jenesius-event-emitter v1.0.2
1978
+ * (c) 2022 Jenesius
1979
+ * @license MIT
1980
+ */
1981
+ const _on = function (name, callback) {
1982
+ if (!(name in this.events))
1983
+ this.events[name] = [];
1984
+ this.events[name].push(callback);
1985
+ return this.off.bind(this, name, callback);
1986
+ };
1987
+ const _emit = function (name, data) {
1988
+ if (!(name in this.events))
1989
+ return;
1990
+ this.events[name].forEach(cl => cl(data));
1991
+ };
1992
+ const _off = function (name, callback) {
1993
+ const arr = this.events[name];
1994
+ if (!arr)
1995
+ return;
1996
+ const index = arr.indexOf(callback);
1997
+ if (index === -1)
1998
+ return;
1999
+ arr.splice(index, 1);
2000
+ };
2001
+ const _cleanEvents = function () {
2002
+ this.events = {};
2003
+ };
2004
+ class EventEmitter {
2005
+ constructor() {
2006
+ this.events = {};
2007
+ }
2008
+ on(name, callback) {
2009
+ return _on.call(this, name, callback);
2010
+ }
2011
+ emit(name, data) {
2012
+ return _emit.call(this, name, data);
2013
+ }
2014
+ off(name, callback) {
2015
+ return _off.call(this, name, callback);
2016
+ }
2017
+ cleanEvents() {
2018
+ _cleanEvents.call(this);
2019
+ }
2020
+ static on(name, callback) {
2021
+ return _on.call(EventEmitter, name, callback);
2022
+ }
2023
+ static emit(name, data) {
2024
+ return _emit.call(EventEmitter, name, data);
2025
+ }
2026
+ static off(name, callback) {
2027
+ return _off.call(EventEmitter, name, callback);
2028
+ }
2029
+ static cleanEvents() {
2030
+ _cleanEvents.call(EventEmitter);
2031
+ }
2032
+ }
2033
+ /**
2034
+ * ONLY FOR GLOBAL USING!
2035
+ * */
2036
+ EventEmitter.events = {};
2037
+
2038
+ var _router, _type, _ready;
2039
+ class ApplicationManager extends EventEmitter {
2040
+ constructor() {
2041
+ super(...arguments);
2042
+ _router.set(this, void 0);
2043
+ /**
2044
+ * @description Office type. By Default is front
2045
+ * */
2046
+ _type.set(this, 'front');
2047
+ /**
2048
+ * @description List of organizations
2049
+ */
2050
+ this.organizations = [];
2051
+ /**
2052
+ * @description Flag witch show that application was load the main user data. By Default - false;
2053
+ */
2054
+ _ready.set(this, false);
2055
+ }
2056
+ get contextType() {
2057
+ var _a;
2058
+ if (!this.contextId)
2059
+ return undefined;
2060
+ if (((_a = this.person) === null || _a === void 0 ? void 0 : _a.id) === this.contextId)
2061
+ return 'person';
2062
+ return 'organization';
2063
+ }
2064
+ set router(v) {
2065
+ __classPrivateFieldSet(this, _router, v);
2066
+ }
2067
+ /**
2068
+ * @description VueRouter of Application
2069
+ * */
2070
+ get router() {
2071
+ if (!__classPrivateFieldGet(this, _router))
2072
+ throw new Error('Router was not founded. Please set router: Manager.router = router: VueRouter');
2073
+ return __classPrivateFieldGet(this, _router);
2074
+ }
2075
+ set type(type) {
2076
+ __classPrivateFieldSet(this, _type, type);
2077
+ }
2078
+ get type() {
2079
+ return __classPrivateFieldGet(this, _type);
2080
+ }
2081
+ get isBack() {
2082
+ return this.type === 'back';
2083
+ }
2084
+ get isFront() {
2085
+ return this.type === 'front';
2086
+ }
2087
+ set ready(v) {
2088
+ __classPrivateFieldSet(this, _ready, v);
2089
+ this.emit(ApplicationManager.EVENT_READY_UPDATE, v);
2090
+ }
2091
+ get ready() {
2092
+ return __classPrivateFieldGet(this, _ready);
2093
+ }
2094
+ onReady(callback) {
2095
+ return this.on(ApplicationManager.EVENT_READY_UPDATE, callback);
2096
+ }
2097
+ onupdateContext(callback) {
2098
+ return this.on(ApplicationManager.EVENT_CONTEXT_UPDATE, callback);
2099
+ }
2100
+ onupdateData(callback) {
2101
+ return this.on(ApplicationManager.EVENT_DATA_UPDATE, callback);
2102
+ }
2103
+ /**
2104
+ * @description Method for update current context. After success emit event[EVENT_UPDATE_CONTEXT]
2105
+ */
2106
+ setCurrentContext(id) {
2107
+ if (this.contextId === id)
2108
+ return console.log(`[application-manager] The current context has already been installed.`);
2109
+ this.contextId = Number(id);
2110
+ localStorage.setItem(ApplicationManager.CURRENT_CONTEXT_KEY, String(id));
2111
+ this.emit(ApplicationManager.EVENT_CONTEXT_UPDATE, id);
2112
+ console.log(`Current context id %c${id}`, 'color: purple');
2113
+ }
2114
+ /**
2115
+ * @description Initialization of ApplicationManager
2116
+ */
2117
+ init() {
2118
+ return __awaiter(this, void 0, void 0, function* () {
2119
+ try {
2120
+ const data = yield this.loadCustomerData();
2121
+ this.person = data;
2122
+ this.organizations = data.organizations;
2123
+ this.user = data.user;
2124
+ this.ready = true;
2125
+ const savedContext = Number.parseInt(localStorage.getItem(ApplicationManager.CURRENT_CONTEXT_KEY) || "");
2126
+ if (!Number.isNaN(savedContext) && this.validateContextId(Number(savedContext)))
2127
+ this.setCurrentContext(savedContext);
2128
+ else
2129
+ this.setCurrentContext(Number(data.id));
2130
+ }
2131
+ catch (e) {
2132
+ NotificationSystem.add('error', CoreError.ApiNotAvailable().message);
2133
+ }
2134
+ });
2135
+ }
2136
+ loadCustomerData() {
2137
+ return clientService.getClientData();
2138
+ }
2139
+ /**
2140
+ * @description The main method of application. Load the main information about user.
2141
+ * @deprecated
2142
+ */
2143
+ updateFullClientData() {
2144
+ return __awaiter(this, void 0, void 0, function* () {
2145
+ return this.init();
2146
+ });
2147
+ }
2148
+ /**
2149
+ * @description Method using for validate provided ID, Checking with existing person ID and each organization ID.
2150
+ * */
2151
+ validateContextId(id) {
2152
+ var _a;
2153
+ if (((_a = this.person) === null || _a === void 0 ? void 0 : _a.id) == id)
2154
+ return true;
2155
+ return !!this.organizations.find(org => org.id === id);
2156
+ }
2157
+ getListKeyById(id) {
2158
+ return `list-information-${id}`;
2159
+ }
2160
+ getListInformationFromLocalStorage(id) {
2161
+ const data = localStorage.getItem(this.getListKeyById(id));
2162
+ return !!data ? JSON.parse(data) : data;
2163
+ }
2164
+ setListInformationToLocalStorage(id, info) {
2165
+ localStorage.setItem(this.getListKeyById(id), JSON.stringify(info));
2166
+ }
2167
+ }
2168
+ _router = new WeakMap(), _type = new WeakMap(), _ready = new WeakMap();
2169
+ ApplicationManager.EVENT_CONTEXT_UPDATE = 'event:context-update';
2170
+ ApplicationManager.EVENT_READY_UPDATE = 'event:ready-update';
2171
+ ApplicationManager.EVENT_DATA_UPDATE = 'event:data-update';
2172
+ /**
2173
+ * @description Key for localStorage, saving current context ID. using after user login to system
2174
+ * */
2175
+ ApplicationManager.CURRENT_CONTEXT_KEY = 'CurrentContext';
2176
+ const Manager = new ApplicationManager();
2177
+ function useManagerState() {
2178
+ const state = vue.reactive({
2179
+ contextType: Manager.contextType,
2180
+ contextId: Manager.contextId
2181
+ });
2182
+ Manager.onupdateContext(() => {
2183
+ state.contextType = Manager.contextType;
2184
+ state.contextId = Manager.contextId;
2185
+ });
2186
+ return state;
2187
+ }
2188
+
1968
2189
  function parseData(res) {
1969
2190
  return res.text()
1970
2191
  .then(res => {
@@ -1980,6 +2201,12 @@ function parseData(res) {
1980
2201
  * @description Функция для запросов, имеет встроенные обработчик для ошибок на самом низком уровне
1981
2202
  * */
1982
2203
  function Request(url, params = {}) {
2204
+ if (Manager.isFront) {
2205
+ if (!params.headers)
2206
+ params.headers = {};
2207
+ // @ts-ignore
2208
+ params.headers["Context-Id"] = Manager.contextId;
2209
+ }
1983
2210
  return fetch(url, params)
1984
2211
  .catch(() => {
1985
2212
  throw CoreError.ApiNotAvailable();
@@ -2285,68 +2512,6 @@ var types = /*#__PURE__*/Object.freeze({
2285
2512
  __proto__: null
2286
2513
  });
2287
2514
 
2288
- /*!
2289
- * jenesius-event-emitter v1.0.2
2290
- * (c) 2022 Jenesius
2291
- * @license MIT
2292
- */
2293
- const _on = function (name, callback) {
2294
- if (!(name in this.events))
2295
- this.events[name] = [];
2296
- this.events[name].push(callback);
2297
- return this.off.bind(this, name, callback);
2298
- };
2299
- const _emit = function (name, data) {
2300
- if (!(name in this.events))
2301
- return;
2302
- this.events[name].forEach(cl => cl(data));
2303
- };
2304
- const _off = function (name, callback) {
2305
- const arr = this.events[name];
2306
- if (!arr)
2307
- return;
2308
- const index = arr.indexOf(callback);
2309
- if (index === -1)
2310
- return;
2311
- arr.splice(index, 1);
2312
- };
2313
- const _cleanEvents = function () {
2314
- this.events = {};
2315
- };
2316
- class EventEmitter {
2317
- constructor() {
2318
- this.events = {};
2319
- }
2320
- on(name, callback) {
2321
- return _on.call(this, name, callback);
2322
- }
2323
- emit(name, data) {
2324
- return _emit.call(this, name, data);
2325
- }
2326
- off(name, callback) {
2327
- return _off.call(this, name, callback);
2328
- }
2329
- cleanEvents() {
2330
- _cleanEvents.call(this);
2331
- }
2332
- static on(name, callback) {
2333
- return _on.call(EventEmitter, name, callback);
2334
- }
2335
- static emit(name, data) {
2336
- return _emit.call(EventEmitter, name, data);
2337
- }
2338
- static off(name, callback) {
2339
- return _off.call(EventEmitter, name, callback);
2340
- }
2341
- static cleanEvents() {
2342
- _cleanEvents.call(EventEmitter);
2343
- }
2344
- }
2345
- /**
2346
- * ONLY FOR GLOBAL USING!
2347
- * */
2348
- EventEmitter.events = {};
2349
-
2350
2515
  class dataService {
2351
2516
  static anonymousGetList(entity) {
2352
2517
  return __awaiter(this, void 0, void 0, function* () {
@@ -4742,163 +4907,6 @@ class ActionService {
4742
4907
  }
4743
4908
  }
4744
4909
 
4745
- class clientService {
4746
- static getClientData() {
4747
- return Request('/close-api/client-content');
4748
- }
4749
- }
4750
-
4751
- var _router, _type, _ready;
4752
- class ApplicationManager extends EventEmitter {
4753
- constructor() {
4754
- super(...arguments);
4755
- _router.set(this, void 0);
4756
- /**
4757
- * @description Office type. By Default is front
4758
- * */
4759
- _type.set(this, 'front');
4760
- /**
4761
- * @description List of organizations
4762
- */
4763
- this.organizations = [];
4764
- /**
4765
- * @description Flag witch show that application was load the main user data. By Default - false;
4766
- */
4767
- _ready.set(this, false);
4768
- }
4769
- get contextType() {
4770
- var _a;
4771
- if (!this.contextId)
4772
- return undefined;
4773
- if (((_a = this.person) === null || _a === void 0 ? void 0 : _a.id) === this.contextId)
4774
- return 'person';
4775
- return 'organization';
4776
- }
4777
- set router(v) {
4778
- __classPrivateFieldSet(this, _router, v);
4779
- }
4780
- /**
4781
- * @description VueRouter of Application
4782
- * */
4783
- get router() {
4784
- if (!__classPrivateFieldGet(this, _router))
4785
- throw new Error('Router was not founded. Please set router: Manager.router = router: VueRouter');
4786
- return __classPrivateFieldGet(this, _router);
4787
- }
4788
- set type(type) {
4789
- __classPrivateFieldSet(this, _type, type);
4790
- }
4791
- get type() {
4792
- return __classPrivateFieldGet(this, _type);
4793
- }
4794
- get isBack() {
4795
- return this.type === 'back';
4796
- }
4797
- get isFront() {
4798
- return this.type === 'front';
4799
- }
4800
- set ready(v) {
4801
- __classPrivateFieldSet(this, _ready, v);
4802
- this.emit(ApplicationManager.EVENT_READY_UPDATE, v);
4803
- }
4804
- get ready() {
4805
- return __classPrivateFieldGet(this, _ready);
4806
- }
4807
- onReady(callback) {
4808
- return this.on(ApplicationManager.EVENT_READY_UPDATE, callback);
4809
- }
4810
- onupdateContext(callback) {
4811
- return this.on(ApplicationManager.EVENT_CONTEXT_UPDATE, callback);
4812
- }
4813
- onupdateData(callback) {
4814
- return this.on(ApplicationManager.EVENT_DATA_UPDATE, callback);
4815
- }
4816
- /**
4817
- * @description Method for update current context. After success emit event[EVENT_UPDATE_CONTEXT]
4818
- */
4819
- setCurrentContext(id) {
4820
- if (this.contextId === id)
4821
- return console.log(`[application-manager] The current context has already been installed.`);
4822
- this.contextId = Number(id);
4823
- localStorage.setItem(ApplicationManager.CURRENT_CONTEXT_KEY, String(id));
4824
- this.emit(ApplicationManager.EVENT_CONTEXT_UPDATE, id);
4825
- console.log(`Current context id %c${id}`, 'color: purple');
4826
- }
4827
- /**
4828
- * @description Initialization of ApplicationManager
4829
- */
4830
- init() {
4831
- return __awaiter(this, void 0, void 0, function* () {
4832
- try {
4833
- const data = yield this.loadCustomerData();
4834
- this.person = data;
4835
- this.organizations = data.organizations;
4836
- this.user = data.user;
4837
- this.ready = true;
4838
- const savedContext = Number.parseInt(localStorage.getItem(ApplicationManager.CURRENT_CONTEXT_KEY) || "");
4839
- if (!Number.isNaN(savedContext) && this.validateContextId(Number(savedContext)))
4840
- this.setCurrentContext(savedContext);
4841
- else
4842
- this.setCurrentContext(Number(data.id));
4843
- }
4844
- catch (e) {
4845
- NotificationSystem.add('error', CoreError.ApiNotAvailable().message);
4846
- }
4847
- });
4848
- }
4849
- loadCustomerData() {
4850
- return clientService.getClientData();
4851
- }
4852
- /**
4853
- * @description The main method of application. Load the main information about user.
4854
- * @deprecated
4855
- */
4856
- updateFullClientData() {
4857
- return __awaiter(this, void 0, void 0, function* () {
4858
- return this.init();
4859
- });
4860
- }
4861
- /**
4862
- * @description Method using for validate provided ID, Checking with existing person ID and each organization ID.
4863
- * */
4864
- validateContextId(id) {
4865
- var _a;
4866
- if (((_a = this.person) === null || _a === void 0 ? void 0 : _a.id) == id)
4867
- return true;
4868
- return !!this.organizations.find(org => org.id === id);
4869
- }
4870
- getListKeyById(id) {
4871
- return `list-information-${id}`;
4872
- }
4873
- getListInformationFromLocalStorage(id) {
4874
- const data = localStorage.getItem(this.getListKeyById(id));
4875
- return !!data ? JSON.parse(data) : data;
4876
- }
4877
- setListInformationToLocalStorage(id, info) {
4878
- localStorage.setItem(this.getListKeyById(id), JSON.stringify(info));
4879
- }
4880
- }
4881
- _router = new WeakMap(), _type = new WeakMap(), _ready = new WeakMap();
4882
- ApplicationManager.EVENT_CONTEXT_UPDATE = 'event:context-update';
4883
- ApplicationManager.EVENT_READY_UPDATE = 'event:ready-update';
4884
- ApplicationManager.EVENT_DATA_UPDATE = 'event:data-update';
4885
- /**
4886
- * @description Key for localStorage, saving current context ID. using after user login to system
4887
- * */
4888
- ApplicationManager.CURRENT_CONTEXT_KEY = 'CurrentContext';
4889
- const Manager = new ApplicationManager();
4890
- function useManagerState() {
4891
- const state = vue.reactive({
4892
- contextType: Manager.contextType,
4893
- contextId: Manager.contextId
4894
- });
4895
- Manager.onupdateContext(() => {
4896
- state.contextType = Manager.contextType;
4897
- state.contextId = Manager.contextId;
4898
- });
4899
- return state;
4900
- }
4901
-
4902
4910
  /**
4903
4911
  * @description Используется для работы с конфигурацией списка. При работе делает копию, после чего её можно будет установить
4904
4912
  * как конфигурацию по умолчанию
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eservices-core",
3
- "version": "1.0.521",
3
+ "version": "1.0.522",
4
4
  "description": "Core library",
5
5
  "author": "",
6
6
  "scripts": {