zavadil-ts-common 1.1.47 → 1.1.49

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.
@@ -5,5 +5,5 @@ export declare class CacheAsync<T> {
5
5
  private expires?;
6
6
  constructor(supplier: () => Promise<T>, maxAgeMs?: number);
7
7
  get(): Promise<T>;
8
- set(v: T): void;
8
+ set(v: T, expires?: Date): void;
9
9
  }
@@ -1,12 +1,13 @@
1
- import { HashCacheStats } from "../type/Stats";
1
+ import { HashCacheStats } from "../type";
2
+ import { CacheAsync } from "./CacheAsync";
2
3
  export declare class HashCacheAsync<K, V> {
3
4
  private cache;
4
5
  private supplier;
5
6
  private maxSize;
6
7
  constructor(supplier: (k: K) => Promise<V>, maxSize?: number);
7
- private obtainCache;
8
+ protected obtainCache(k: K): CacheAsync<V>;
8
9
  get(k: K): Promise<V>;
9
- set(k: K, v: V): void;
10
+ set(k: K, v: V, expires?: Date): void;
10
11
  reset(k?: K): void;
11
12
  getSize(): number;
12
13
  getMaxSize(): number;
@@ -1,6 +1,7 @@
1
1
  export declare class LazyAsync<T> {
2
2
  private cache?;
3
3
  private supplier;
4
+ private promise?;
4
5
  constructor(supplier: () => Promise<T>);
5
6
  get(): Promise<T>;
6
7
  reset(): void;
@@ -7,10 +7,10 @@ export declare class RestClient {
7
7
  /**
8
8
  * Override this to customize http headers.
9
9
  */
10
- getHeaders(): Promise<RestClientHeaders>;
10
+ getHeaders(url: string): Promise<RestClientHeaders>;
11
11
  paramsToQueryString(params?: any): string;
12
12
  getUrl(endpoint: string, params?: any): string;
13
- getRequestOptions(method?: string, data?: object | null): Promise<RequestInit>;
13
+ getRequestOptions(url: string, method?: string, data?: object | null): Promise<RequestInit>;
14
14
  processRequest(endpoint: string, requestOptions?: RequestInit): Promise<Response>;
15
15
  processRequestJson(url: string, requestOptions?: object | undefined): Promise<any>;
16
16
  getJson(url: string, params?: any): Promise<any>;
package/dist/index.d.ts CHANGED
@@ -5,9 +5,39 @@ declare class CacheAsync<T> {
5
5
  private expires?;
6
6
  constructor(supplier: () => Promise<T>, maxAgeMs?: number);
7
7
  get(): Promise<T>;
8
- set(v: T): void;
8
+ set(v: T, expires?: Date): void;
9
9
  }
10
10
 
11
+ type SortingField = {
12
+ name: string;
13
+ desc?: boolean;
14
+ nullsLast?: boolean;
15
+ };
16
+ type SortingRequest = Array<SortingField>;
17
+ type PagingRequest = {
18
+ page: number;
19
+ size: number;
20
+ search?: string | null;
21
+ sorting?: SortingRequest | null;
22
+ };
23
+ type Page<Type> = {
24
+ totalItems: number;
25
+ pageSize: number;
26
+ pageNumber: number;
27
+ content: Array<Type>;
28
+ };
29
+
30
+ declare enum UserAlertType {
31
+ info = "info",
32
+ warning = "warning",
33
+ error = "danger"
34
+ }
35
+ type UserAlert = {
36
+ time: Date;
37
+ type: UserAlertType;
38
+ message: string;
39
+ };
40
+
11
41
  type JavaHeapStats = {
12
42
  heapSize: number;
13
43
  heapMaxSize: number;
@@ -30,9 +60,9 @@ declare class HashCacheAsync<K, V> {
30
60
  private supplier;
31
61
  private maxSize;
32
62
  constructor(supplier: (k: K) => Promise<V>, maxSize?: number);
33
- private obtainCache;
63
+ protected obtainCache(k: K): CacheAsync<V>;
34
64
  get(k: K): Promise<V>;
35
- set(k: K, v: V): void;
65
+ set(k: K, v: V, expires?: Date): void;
36
66
  reset(k?: K): void;
37
67
  getSize(): number;
38
68
  getMaxSize(): number;
@@ -50,6 +80,7 @@ declare class Lazy<T> {
50
80
  declare class LazyAsync<T> {
51
81
  private cache?;
52
82
  private supplier;
83
+ private promise?;
53
84
  constructor(supplier: () => Promise<T>);
54
85
  get(): Promise<T>;
55
86
  reset(): void;
@@ -61,36 +92,6 @@ type EntityBase = {
61
92
  last_update_on?: Date;
62
93
  };
63
94
 
64
- type SortingField = {
65
- name: string;
66
- desc?: boolean;
67
- nullsLast?: boolean;
68
- };
69
- type SortingRequest = Array<SortingField>;
70
- type PagingRequest = {
71
- page: number;
72
- size: number;
73
- search?: string | null;
74
- sorting?: SortingRequest | null;
75
- };
76
- type Page<Type> = {
77
- totalItems: number;
78
- pageSize: number;
79
- pageNumber: number;
80
- content: Array<Type>;
81
- };
82
-
83
- declare enum UserAlertType {
84
- info = "info",
85
- warning = "warning",
86
- error = "danger"
87
- }
88
- type UserAlert = {
89
- time: Date;
90
- type: UserAlertType;
91
- message: string;
92
- };
93
-
94
95
  type RestClientHeaders = {};
95
96
  declare class RestClient {
96
97
  private baseUrl;
@@ -99,10 +100,10 @@ declare class RestClient {
99
100
  /**
100
101
  * Override this to customize http headers.
101
102
  */
102
- getHeaders(): Promise<RestClientHeaders>;
103
+ getHeaders(url: string): Promise<RestClientHeaders>;
103
104
  paramsToQueryString(params?: any): string;
104
105
  getUrl(endpoint: string, params?: any): string;
105
- getRequestOptions(method?: string, data?: object | null): Promise<RequestInit>;
106
+ getRequestOptions(url: string, method?: string, data?: object | null): Promise<RequestInit>;
106
107
  processRequest(endpoint: string, requestOptions?: RequestInit): Promise<Response>;
107
108
  processRequestJson(url: string, requestOptions?: object | undefined): Promise<any>;
108
109
  getJson(url: string, params?: any): Promise<any>;
@@ -196,6 +197,7 @@ type TokenRequestPayloadBase = {
196
197
  };
197
198
  type RequestAccessTokenPayload = TokenRequestPayloadBase & {
198
199
  idToken: string;
200
+ privilege: string;
199
201
  };
200
202
  type RequestIdTokenFromPrevTokenPayload = {
201
203
  idToken: string;
@@ -213,7 +215,6 @@ type IdTokenPayload = TokenResponsePayloadBase & {
213
215
  };
214
216
  type AccessTokenPayload = TokenResponsePayloadBase & {
215
217
  accessToken: string;
216
- refreshToken: string;
217
218
  };
218
219
  type JwKeyPayload = {
219
220
  kty: string;
@@ -226,11 +227,12 @@ type JwksPayload = {
226
227
  };
227
228
  /**
228
229
  * This implements rest client for OAuth server - https://github.com/lotcz/oauth-server
229
- * Provide basic url, /api/oauth prefix will be added automatically
230
+ * Provide basic url, /api/oauth path prefix will be added automatically
230
231
  */
231
232
  declare class OAuthRestClient extends RestClient {
232
233
  constructor(oauthUrl: string);
233
234
  jwks(): Promise<JwksPayload>;
235
+ verifyIdToken(idToken: string): Promise<IdTokenPayload>;
234
236
  requestIdTokenFromLogin(request: RequestIdTokenFromLoginPayload): Promise<IdTokenPayload>;
235
237
  refreshIdToken(request: RequestIdTokenFromPrevTokenPayload): Promise<IdTokenPayload>;
236
238
  requestAccessToken(request: RequestAccessTokenPayload): Promise<AccessTokenPayload>;
@@ -240,22 +242,26 @@ declare class OAuthRestClient extends RestClient {
240
242
  * Manages refresh of id and access tokens.
241
243
  */
242
244
  declare class OAuthTokenManager {
245
+ private eventManager;
243
246
  oAuthServer: OAuthRestClient;
244
247
  audience: string;
245
248
  idToken?: IdTokenPayload;
246
- accessToken?: AccessTokenPayload;
249
+ accessTokens: Map<string, AccessTokenPayload>;
247
250
  constructor(oAuthServerBaseUrl: string, targetAudience: string);
251
+ addIdTokenChangedHandler(handler: (t: IdTokenPayload) => any): void;
248
252
  isTokenExpired(expires?: Date | null): boolean;
249
253
  isTokenReadyForRefresh(issuedAt: Date, expires?: Date | null): boolean;
250
254
  isValidIdToken(idToken?: IdTokenPayload): boolean;
251
255
  hasValidIdToken(): boolean;
252
256
  isValidAccessToken(accessToken?: AccessTokenPayload): boolean;
253
- hasValidAccessToken(): boolean;
257
+ hasValidAccessToken(privilege: string): boolean;
254
258
  reset(): void;
255
259
  getIdToken(): Promise<string>;
256
- setIdToken(token: IdTokenPayload): void;
260
+ setIdToken(token?: IdTokenPayload): void;
261
+ verifyIdToken(token: string): Promise<boolean>;
257
262
  login(login: string, password: string): Promise<boolean>;
258
- getAccessToken(): Promise<string>;
263
+ private getAccessTokenInternal;
264
+ getAccessToken(privilege: string): Promise<string>;
259
265
  }
260
266
 
261
267
  declare class OAuthSubject {
@@ -273,15 +279,28 @@ type ServerOAuthInfoPayload = {
273
279
  version: string;
274
280
  };
275
281
  declare class RestClientWithOAuth extends RestClient {
276
- private tokenManager?;
277
- private serverInfo?;
278
282
  private insecureClient;
279
- constructor(url: string);
283
+ private tokenManager;
284
+ private serverInfo;
285
+ private defaultPrivilege;
286
+ constructor(url: string, defaultPrivilege?: string);
287
+ /**
288
+ * Override this if a different privilege is needed for different endpoints
289
+ * @param url
290
+ */
291
+ getPrivilege(url: string): string;
292
+ getIdTokenFromUrl(): string | null;
293
+ getIdTokenFromLocalStorage(): IdTokenPayload | null;
294
+ saveIdTokenToLocalStorage(token: IdTokenPayload | null): void;
295
+ addIdTokenChangedHandler(handler: () => any): void;
296
+ private getServerInfoInternal;
280
297
  getServerInfo(): Promise<ServerOAuthInfoPayload>;
298
+ private getTokenManagerInternal;
281
299
  getTokenManager(): Promise<OAuthTokenManager>;
282
300
  login(login: string, password: string): Promise<boolean>;
283
301
  setIdToken(token: IdTokenPayload): Promise<boolean>;
284
- getHeaders(): Promise<RestClientHeaders>;
302
+ setIdTokenRaw(token: string): Promise<boolean>;
303
+ getHeaders(url: string): Promise<RestClientHeaders>;
285
304
  }
286
305
 
287
306
  declare class ObjectUtil {
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- var t=function(){function t(t,e){this.supplier=t,this.maxAgeMs=e}return t.prototype.get=function(){var t=this;return void 0===this.cache||this.expires&&this.expires>new Date?this.supplier().then((function(e){return t.set(e),e})):Promise.resolve(this.cache)},t.prototype.set=function(t){this.cache=t,this.maxAgeMs&&(this.expires=new Date((new Date).getTime()+this.maxAgeMs))},t}(),e=function(){function e(t,e){this.cache=new Map,this.maxSize=100,this.supplier=t,e&&(this.maxSize=e)}return e.prototype.obtainCache=function(e){var n=this,r=this.cache.get(e);return r||(r=new t((function(){return n.supplier(e)})),this.cache.set(e,r)),r},e.prototype.get=function(t){return this.obtainCache(t).get()},e.prototype.set=function(t,e){this.obtainCache(t).set(e)},e.prototype.reset=function(t){t?this.cache.delete(t):this.cache.clear()},e.prototype.getSize=function(){return this.cache.size},e.prototype.getMaxSize=function(){return this.maxSize},e.prototype.getStats=function(){return{cachedItems:this.getSize(),capacity:this.getMaxSize()}},e}(),n=function(){function t(t){this.supplier=t}return t.prototype.get=function(){return void 0===this.cache&&(this.cache=this.supplier()),this.cache},t.prototype.reset=function(){this.cache=void 0},t}(),r=function(){function t(t){this.supplier=t}return t.prototype.get=function(){var t=this;return void 0===this.cache?this.supplier().then((function(e){return t.cache=e,e})):Promise.resolve(this.cache)},t.prototype.reset=function(){this.cache=void 0},t}(),o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},o(t,e)};function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var s=function(){return s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},s.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var u,c=function(){function t(){}return t.isEmpty=function(t){return null==t},t.notEmpty=function(e){return!t.isEmpty(e)},t.clone=function(t){if(null===t)throw new Error("Null cannot be cloned!");if("object"!=typeof t)throw new Error("Not an object, cannot be cloned!");return s({},t)},t}(),a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.isEmpty=function(t){return c.isEmpty(t)||0===(null==t?void 0:t.trim().length)},e.notEmpty=function(t){return!e.isEmpty(t)},e.substr=function(t,e,n){return this.isEmpty(t)?"":t.substring(e,n)},e.replace=function(t,e,n){return this.isEmpty(t)||this.isEmpty(e)?"":t.replace(e,String(n))},e.containsLineBreaks=function(t){return null!=t&&0!==t.trim().length&&t.includes("\n")},e.trimLeadingSlashes=function(t){return this.isEmpty(t)?"":t.replace(/^\//g,"")},e.trimTrailingSlashes=function(t){return this.isEmpty(t)?"":t.replace(/\/$/g,"")},e.trimSlashes=function(t){return this.isEmpty(t)?"":t.replace(/^\/|\/$/g,"")},e.safeTruncate=function(t,n,r){return void 0===r&&(r=""),e.isEmpty(t)||!t?"":t.length<=n?String(t):t.substring(0,n-r.length)+r},e.ellipsis=function(t,n,r){return void 0===r&&(r="..."),e.safeTruncate(t,n,r)},e.safeTrim=function(t){return e.isEmpty(t)||!t?"":t.trim()},e.safeLowercase=function(t){return e.isEmpty(t)||!t?"":t.toLowerCase()},e.safeUppercase=function(t){return e.isEmpty(t)||!t?"":t.toUpperCase()},e.toBigInt=function(t){return this.isEmpty(t)?null:BigInt(t)},e.getNonEmpty=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.find((function(t){return e.notEmpty(t)}))||""},e}(c),h=function(){function t(){}return t.isEmpty=function(t){return c.isEmpty(t)||0===t.length},t.notEmpty=function(e){return!t.isEmpty(e)},t.remove=function(e,n){return t.isEmpty(e)?[]:null==e?void 0:e.filter((function(t){return t!==n}))},t}(),p=function(){function t(){}return t.sleep=function(t){return new Promise((function(e){return setTimeout(e,t)}))},t}(),f=function(){function t(){}return t.formatByteSize=function(t){var e=Number(t);if(null===e||Number.isNaN(e))return"";if(0===e)return"0";var n=Math.floor(Math.log(e)/Math.log(1024));return 1*+(e/Math.pow(1024,n)).toFixed(2)+" "+["B","kB","MB","GB","TB"][n]},t}(),l={page:0,size:10},g=function(){function t(){}return t.sortingFieldToString=function(t){if(!t)return"";var e=[];return e.push(t.name),e.push(t.desc?"desc":""),e.push(t.nullsLast?"nl":""),e.join("-")},t.sortingFieldFromString=function(t){var e=t.split("-");return{name:e[0],desc:e.length>1&&"desc"===a.safeLowercase(e[1]),nullsLast:e.length>2&&"nl"===a.safeLowercase(e[2])}},t.sortingRequestToString=function(e){return e.map((function(e){return t.sortingFieldToString(e)})).join("+")},t.sortingRequestFromString=function(e){return e?e.split("+").map((function(e){return t.sortingFieldFromString(e)})):[]},t.pagingRequestToQueryParams=function(e){if(e){var n={page:e.page,size:e.size};return e.search&&(n.search=e.search),e.sorting&&(n.sorting=t.sortingRequestToString(e.sorting)),n}},t.pagingRequestToString=function(e){if(!e)return"";var n=[];return n.push(String(e.page)),n.push(String(e.size)),n.push(a.safeTrim(e.search)),n.push(e.sorting?t.sortingRequestToString(e.sorting):""),n.join(":")},t.pagingRequestFromString=function(e){if(!e||a.isEmpty(e))return s({},l);var n=e.split(":");return n.length<4?s({},l):{page:Number(n[0]),size:Number(n[1]),search:String(n[2]),sorting:a.isEmpty(n[3])?void 0:t.sortingRequestFromString(n[3])}},t}(),d=function(){function t(){}return t.formatNumber=function(t,e){return void 0===e&&(e=2),String(t).padStart(e,"0")},t.parseDate=function(t){if(t)return"string"==typeof t?new Date(t):t},t.formatDateForHumans=function(e,n){if(void 0===n&&(n=!1),!(e=t.parseDate(e)))return"";var r=e.getFullYear(),o=t.formatNumber(e.getMonth()+1),i=t.formatNumber(e.getDate()),s="".concat(r,"-").concat(o,"-").concat(i);if(!n)return s;var u=t.formatNumber(e.getHours()),c=t.formatNumber(e.getMinutes()),a=t.formatNumber(e.getSeconds());return"".concat(s," ").concat(u,":").concat(c,":").concat(a)},t.formatDateTimeForHumans=function(e){return t.formatDateForHumans(e,!0)},t.formatDateForInput=function(e){var n=t.parseDate(e);if(void 0===n)return"";var r=n.getFullYear(),o=t.formatNumber(n.getMonth()+1),i=t.formatNumber(n.getDate());return"".concat(r,"-").concat(o,"-").concat(i)},t.getDurationMs=function(e,n){if(e=t.parseDate(e),n=t.parseDate(n),c.isEmpty(e)||c.isEmpty(n))return null;try{return n.getTime()-e.getTime()}catch(t){return null}},t.getSinceDurationMs=function(e){return t.getDurationMs(e,new Date)},t.formatDuration=function(t){if(!t)return"";var e=Math.floor(t/1e3);t-=1e3*e;var n=Math.floor(e/60);e-=60*n;var r=Math.floor(n/60);n-=60*r;var o=Math.floor(r/24);r-=24*o;var i=[];return o>0&&i.push("".concat(o,"d")),r>0&&i.push("".concat(r,"h")),n>0&&i.push("".concat(n,"m")),e>0&&0===o&&0===r&&i.push("".concat(e,"s")),t>0&&0===o&&0===r&&0===n&&i.push("".concat(t,"ms")),i.join(" ")},t}(),y=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.parseNumber=function(t){if(!t)return null;var e=Number(t);return Number.isNaN(e)?null:e},e.round=function(t,e){e||(e=0);var n=Math.pow(10,e);return Math.round(t*n)/n},e.portionToPercent=function(t,n){if(null==t)return"";var r=e.round(100*t,n);return"".concat(r,"%")},e}(c),m=function(){function t(t){this.baseUrl=t}return t.pagingRequestToQueryParams=function(t){return g.pagingRequestToQueryParams(t)},t.prototype.getHeaders=function(){return Promise.resolve({"Content-Type":"application/json"})},t.prototype.paramsToQueryString=function(t){if(!t)return"";var e=new URLSearchParams(t),n=new URLSearchParams;e.forEach((function(t,e){""!==t&&void 0!==t&&"undefined"!==t&&n.set(e,t)}));var r=n.toString();return a.isEmpty(r)?"":"?".concat(r)},t.prototype.getUrl=function(t,e){var n=[a.trimTrailingSlashes(this.baseUrl),a.trimLeadingSlashes(t)].join("/");return e&&(n="".concat(n).concat(this.paramsToQueryString(e))),n},t.prototype.getRequestOptions=function(t,e){return void 0===t&&(t="GET"),void 0===e&&(e=null),this.getHeaders().then((function(n){return{method:t,headers:n,body:null===e?null:e instanceof FormData?e:JSON.stringify(e)}}))},t.prototype.processRequest=function(t,e){return fetch(this.getUrl(t),e).then((function(t){if(!t.ok){var e={cause:t.status};return"application/json"===t.headers.get("Content-Type")?t.json().then((function(n){if(n.message)throw new Error(n.message,e);if(n.error)throw new Error(n.error,e);throw new Error(t.statusText,e)}),(function(){throw new Error(t.statusText,e)})):t.text().then((function(n){throw a.isEmpty(n)?new Error(t.statusText,e):new Error(n,e)}),(function(){throw new Error(t.statusText,e)}))}return t}))},t.prototype.processRequestJson=function(t,e){return this.processRequest(t,e).then((function(t){return t.json()}))},t.prototype.getJson=function(t,e){var n=this;return e&&(t="".concat(t).concat(this.paramsToQueryString(e))),this.getRequestOptions().then((function(e){return n.processRequestJson(t,e)}))},t.prototype.postJson=function(t,e){var n=this;return void 0===e&&(e=null),this.getRequestOptions("POST",e).then((function(e){return n.processRequestJson(t,e)}))},t.prototype.putJson=function(t,e){var n=this;return void 0===e&&(e=null),this.getRequestOptions("PUT",e).then((function(e){return n.processRequestJson(t,e)}))},t.prototype.get=function(t){var e=this;return this.getRequestOptions().then((function(n){return e.processRequest(t,n)}))},t.prototype.del=function(t){var e=this;return this.getRequestOptions("DELETE").then((function(n){return e.processRequest(t,n)}))},t.prototype.post=function(t,e){var n=this;return void 0===e&&(e=null),this.getRequestOptions("POST",e).then((function(e){return n.processRequest(t,e)}))},t.prototype.put=function(t,e){var n=this;return void 0===e&&(e=null),this.getRequestOptions("PUT",e).then((function(e){return n.processRequest(t,e)}))},t}(),v=function(){function t(t,e){this.client=t,this.name=e}return t.prototype.loadSingle=function(t){return this.client.getJson("".concat(this.name,"/").concat(t))},t.prototype.loadPage=function(t){return this.client.getJson(this.name,m.pagingRequestToQueryParams(t))},t.prototype.save=function(t){return t.id?this.client.putJson("".concat(this.name,"/").concat(t.id),t):this.client.postJson(this.name,t)},t.prototype.delete=function(t){return this.client.del("".concat(this.name,"/").concat(t))},t}(),T=function(t){function n(n,r,o){var i=t.call(this,n,r)||this;return i.cache=new e((function(e){return t.prototype.loadSingle.call(i,e)}),o),i}return i(n,t),n.prototype.loadSingle=function(t){return this.cache.get(t)},n.prototype.save=function(e){var n=this;return t.prototype.save.call(this,e).then((function(t){return t.id&&n.cache.set(t.id,t),t}))},n.prototype.delete=function(e){var n=this;return t.prototype.delete.call(this,e).then((function(){return n.cache.reset(e)}))},n}(v),w=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.loadSingle=function(t){throw new Error("Use loadSingleStub() instead!")},e.prototype.loadSingleStub=function(t){return this.client.getJson("".concat(this.name,"/").concat(t))},e.prototype.save=function(t){throw new Error("Use saveStub() instead!")},e.prototype.saveStub=function(t){return t.id?this.client.putJson("".concat(this.name,"/").concat(t.id),t):this.client.postJson(this.name,t)},e}(v),S=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.cache=new r((function(){return o.loadAllInternal()})),o}return i(e,t),e.prototype.loadAllInternal=function(){return this.client.getJson("".concat(this.name,"/all"))},e.prototype.loadAll=function(){return this.cache.get()},e.prototype.loadSingle=function(t){var e=this;return this.loadAll().then((function(n){var r=n.find((function(e){return e.id===t}));if(void 0===t)throw new Error("".concat(e.name," id ").concat(t," not found!"));return r}))},e.prototype.save=function(e){var n=this;return t.prototype.save.call(this,e).then((function(t){return n.cache.reset(),t}))},e.prototype.delete=function(e){var n=this;return t.prototype.delete.call(this,e).then((function(){return n.cache.reset()}))},e}(v),k=function(){function t(){this.handlers=new Map}return t.prototype.addEventListener=function(t,e){this.handlers.has(t)||this.handlers.set(t,[]),this.handlers.get(t).push(e)},t.prototype.removeEventListener=function(t,e){var n=this.handlers.get(t);n&&n.splice(n.indexOf(e),1)},t.prototype.triggerEvent=function(t,e){this.handlers.has(t)&&this.handlers.get(t).forEach((function(t){return t(e)}))},t}();!function(t){t.info="info",t.warning="warning",t.error="danger"}(u||(u={}));var E=function(){function t(t){void 0===t&&(t=10),this.maxAlerts=t,this.em=new k,this.alerts=[]}return t.prototype.addOnChangeHandler=function(t){this.em.addEventListener("change",t)},t.prototype.removeOnChangeHandler=function(t){this.em.removeEventListener("change",t)},t.prototype.triggerChange=function(){this.em.triggerEvent("change")},t.prototype.reset=function(){this.alerts=[],this.triggerChange()},t.prototype.remove=function(t){this.alerts.splice(this.alerts.indexOf(t),1),this.triggerChange()},t.prototype.add=function(t){for(this.alerts.push(t);this.alerts.length>this.maxAlerts;)this.alerts.shift();this.triggerChange()},t.prototype.custom=function(t,e){this.add({time:new Date,type:t,message:e})},t.prototype.err=function(t){this.custom(u.error,"string"==typeof t?t:t.toString())},t.prototype.warn=function(t){this.custom(u.warning,t)},t.prototype.info=function(t){this.custom(u.info,t)},t.prototype.getSummary=function(){var t=new Map;Object.values(u).forEach((function(e,n){t.set(e,0)}));for(var e=0;e<this.alerts.length;e++){var n=this.alerts[e],r=t.get(n.type)||0;t.set(n.type,r+1)}return t},t}(),x=function(){function t(t,e){void 0===e&&(e=!1);var n=this;this.isCancelled={value:!1},this.throwWhenCancelled=e,this.promise=new Promise((function(e,r){t.then((function(t){if(!n.isCancelled.value)return e(t)})).catch((function(t){!n.throwWhenCancelled&&n.isCancelled.value||r(t)}))}))}return t.prototype.cancel=function(){this.isCancelled.value=!0},t}(),b=function(t){function e(e){return t.call(this,"".concat(a.trimSlashes(e),"/api/oauth"))||this}return i(e,t),e.prototype.jwks=function(){return this.getJson("jwks.json")},e.prototype.requestIdTokenFromLogin=function(t){return this.postJson("id-tokens/from-login",t)},e.prototype.refreshIdToken=function(t){return this.postJson("id-tokens/refresh",t)},e.prototype.requestAccessToken=function(t){return this.postJson("access-tokens/from-id-token",t)},e}(m),M=function(){function t(t,e){this.audience=e,this.oAuthServer=new b(t)}return t.prototype.isTokenExpired=function(t){if(null==t)return!1;var e=Date.now();return new Date(t).getTime()<e},t.prototype.isTokenReadyForRefresh=function(t,e){return null!=e&&new Date((e.getTime()+t.getTime())/2)<new Date},t.prototype.isValidIdToken=function(t){return void 0!==t&&!this.isTokenExpired(t.expires)},t.prototype.hasValidIdToken=function(){return this.isValidIdToken(this.idToken)},t.prototype.isValidAccessToken=function(t){return void 0!==t&&!this.isTokenExpired(t.expires)},t.prototype.hasValidAccessToken=function(){return this.isValidAccessToken(this.accessToken)},t.prototype.reset=function(){this.idToken=void 0,this.accessToken=void 0},t.prototype.getIdToken=function(){var t=this;return void 0!==this.idToken&&this.hasValidIdToken()?this.isTokenReadyForRefresh(this.idToken.issuedAt,this.idToken.expires)?this.oAuthServer.refreshIdToken({idToken:this.idToken.idToken}).then((function(e){return t.isValidIdToken(e)?(t.idToken=e,e.idToken):Promise.reject("Received ID token is not valid!")})):Promise.resolve(this.idToken.idToken):Promise.reject("No valid ID token!")},t.prototype.setIdToken=function(t){if(!this.isValidIdToken(t))throw new Error("Received ID token is not valid!");this.idToken=t},t.prototype.login=function(t,e){var n=this;return this.reset(),this.oAuthServer.requestIdTokenFromLogin({login:t,password:e,targetAudience:this.audience}).then((function(t){return n.setIdToken(t),!0}))},t.prototype.getAccessToken=function(){var t,e=this;return this.hasValidAccessToken()?Promise.resolve(String(null===(t=this.accessToken)||void 0===t?void 0:t.accessToken)):this.getIdToken().then((function(t){return e.oAuthServer.requestAccessToken({idToken:t,targetAudience:e.audience}).then((function(t){return e.isValidAccessToken(t)?(e.accessToken=t,t.accessToken):Promise.reject("Received access token is not valid!")}))}))},t}(),R=function(){function t(t){this.value=t}return t.prototype.getSubjectType=function(){return a.isEmpty(this.value)?null:this.value.split(":")[0]},t.prototype.getSubjectContent=function(){if(a.isEmpty(this.value))return null;var t=this.value.split("//");return t.length>1?t[1]:null},t.prototype.toString=function(){return this.value},t}(),q=function(t){function e(e){var n=t.call(this,e)||this;return n.insecureClient=new m(e),n}return i(e,t),e.prototype.getServerInfo=function(){var t=this;return void 0!==this.serverInfo?Promise.resolve(this.serverInfo):this.insecureClient.getJson("status/info").then((function(e){return t.serverInfo=e,t.serverInfo}))},e.prototype.getTokenManager=function(){return void 0!==this.tokenManager?Promise.resolve(this.tokenManager):this.getServerInfo().then((function(t){return new M(t.oauthServerUrl,t.targetAudience)}))},e.prototype.login=function(t,e){return this.getTokenManager().then((function(n){return n.login(t,e)}))},e.prototype.setIdToken=function(t){return this.getTokenManager().then((function(e){return e.setIdToken(t)})).then((function(){return!0}))},e.prototype.getHeaders=function(){return this.getTokenManager().then((function(t){return t.getAccessToken()})).then((function(t){return{"Content-Type":"application/json",Authorization:"Bearer ".concat(t)}}))},e}(m),A=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.distanceTo=function(t){return Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},t.prototype.equalsTo=function(t){return!!t&&(this.x===t.x&&this.y===t.y)},t.prototype.size=function(){return this.distanceTo(new t(0,0))},t.prototype.inSize=function(e){var n=this.size();if(0!==n){var r=e/n;return new t(this.x*r,this.y*r)}return this},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.multiply=function(e){return new t(this.x*e,this.y*e)},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y)},t.prototype.sub=function(t){return this.subtract(t)},t.prototype.toArray=function(){return[this.x,this.y]},t.fromArray=function(e){if("object"==typeof e&&2===e.length)return new t(e[0],e[1])},t.prototype.clone=function(){return new t(this.x,this.y)},t.prototype.getAngleToYAxis=function(t){var e=t.subtract(this),n=e.y<0,r=e.x/e.size(),o=Math.asin(r);return(n?Math.PI-o:o)||0},t.prototype.getNeighborPositions=function(e,n){void 0===e&&(e=1),void 0===n&&(n=!1);for(var r=[],o=this.x+e,i=this.x-e;i<=o;i++)for(var s=this.y+e,u=this.y-e;u<=s;u++){var c=new t(i,u);!n&&this.equalsTo(c)||r.push(c)}return r},t.prototype.getClosest=function(t){if(!t||0===t.length)return null;if(1===t.length)return t[0];for(var e=t[0],n=this.distanceTo(e),r=1,o=t.length;r<o;r++){var i=this.distanceTo(t[r]);i<n&&(e=t[r],n=i)}return e},t.prototype.toString=function(t){return void 0===t&&(t=2),"[".concat(y.round(this.x,t),",").concat(y.round(this.y,t),"]")},t}();export{h as ArrayUtil,p as AsyncUtil,f as ByteUtil,t as CacheAsync,x as CancellablePromise,d as DateUtil,T as EntityCachedClient,v as EntityClient,w as EntityClientWithStub,k as EventManager,e as HashCacheAsync,n as Lazy,r as LazyAsync,S as LookupClient,y as NumberUtil,b as OAuthRestClient,R as OAuthSubject,M as OAuthTokenManager,c as ObjectUtil,g as PagingUtil,m as RestClient,q as RestClientWithOAuth,a as StringUtil,u as UserAlertType,E as UserAlerts,A as Vector2};
1
+ var t=function(){function t(t,e){this.supplier=t,this.maxAgeMs=e}return t.prototype.get=function(){var t=this;return void 0===this.cache||this.expires&&this.expires>new Date?this.supplier().then((function(e){return t.set(e),e})):Promise.resolve(this.cache)},t.prototype.set=function(t,e){this.cache=t,this.expires=e,this.maxAgeMs&&void 0===this.expires&&(this.expires=new Date((new Date).getTime()+this.maxAgeMs))},t}(),e=function(){function e(t,e){this.cache=new Map,this.maxSize=100,this.supplier=t,e&&(this.maxSize=e)}return e.prototype.obtainCache=function(e){var n=this,r=this.cache.get(e);return r||(r=new t((function(){return n.supplier(e)})),this.cache.set(e,r)),r},e.prototype.get=function(t){return this.obtainCache(t).get()},e.prototype.set=function(t,e,n){this.obtainCache(t).set(e,n)},e.prototype.reset=function(t){t?this.cache.delete(t):this.cache.clear()},e.prototype.getSize=function(){return this.cache.size},e.prototype.getMaxSize=function(){return this.maxSize},e.prototype.getStats=function(){return{cachedItems:this.getSize(),capacity:this.getMaxSize()}},e}(),n=function(){function t(t){this.supplier=t}return t.prototype.get=function(){return void 0===this.cache&&(this.cache=this.supplier()),this.cache},t.prototype.reset=function(){this.cache=void 0},t}(),r=function(){function t(t){this.supplier=t}return t.prototype.get=function(){var t=this;return void 0!==this.cache?Promise.resolve(this.cache):(void 0===this.promise&&(this.promise=this.supplier().then((function(e){return t.cache=e,t.promise=void 0,e}))),this.promise)},t.prototype.reset=function(){this.cache=void 0},t}(),o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},o(t,e)};function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var s=function(){return s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},s.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var u,a=function(){function t(){}return t.isEmpty=function(t){return null==t},t.notEmpty=function(e){return!t.isEmpty(e)},t.clone=function(t){if(null===t)throw new Error("Null cannot be cloned!");if("object"!=typeof t)throw new Error("Not an object, cannot be cloned!");return s({},t)},t}(),c=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.isEmpty=function(t){return a.isEmpty(t)||0===(null==t?void 0:t.trim().length)},e.notEmpty=function(t){return!e.isEmpty(t)},e.substr=function(t,e,n){return this.isEmpty(t)?"":t.substring(e,n)},e.replace=function(t,e,n){return this.isEmpty(t)||this.isEmpty(e)?"":t.replace(e,String(n))},e.containsLineBreaks=function(t){return null!=t&&0!==t.trim().length&&t.includes("\n")},e.trimLeadingSlashes=function(t){return this.isEmpty(t)?"":t.replace(/^\//g,"")},e.trimTrailingSlashes=function(t){return this.isEmpty(t)?"":t.replace(/\/$/g,"")},e.trimSlashes=function(t){return this.isEmpty(t)?"":t.replace(/^\/|\/$/g,"")},e.safeTruncate=function(t,n,r){return void 0===r&&(r=""),e.isEmpty(t)||!t?"":t.length<=n?String(t):t.substring(0,n-r.length)+r},e.ellipsis=function(t,n,r){return void 0===r&&(r="..."),e.safeTruncate(t,n,r)},e.safeTrim=function(t){return e.isEmpty(t)||!t?"":t.trim()},e.safeLowercase=function(t){return e.isEmpty(t)||!t?"":t.toLowerCase()},e.safeUppercase=function(t){return e.isEmpty(t)||!t?"":t.toUpperCase()},e.toBigInt=function(t){return this.isEmpty(t)?null:BigInt(t)},e.getNonEmpty=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.find((function(t){return e.notEmpty(t)}))||""},e}(a),h=function(){function t(){}return t.isEmpty=function(t){return a.isEmpty(t)||0===t.length},t.notEmpty=function(e){return!t.isEmpty(e)},t.remove=function(e,n){return t.isEmpty(e)?[]:null==e?void 0:e.filter((function(t){return t!==n}))},t}(),p=function(){function t(){}return t.sleep=function(t){return new Promise((function(e){return setTimeout(e,t)}))},t}(),f=function(){function t(){}return t.formatByteSize=function(t){var e=Number(t);if(null===e||Number.isNaN(e))return"";if(0===e)return"0";var n=Math.floor(Math.log(e)/Math.log(1024));return 1*+(e/Math.pow(1024,n)).toFixed(2)+" "+["B","kB","MB","GB","TB"][n]},t}(),l={page:0,size:10},g=function(){function t(){}return t.sortingFieldToString=function(t){if(!t)return"";var e=[];return e.push(t.name),e.push(t.desc?"desc":""),e.push(t.nullsLast?"nl":""),e.join("-")},t.sortingFieldFromString=function(t){var e=t.split("-");return{name:e[0],desc:e.length>1&&"desc"===c.safeLowercase(e[1]),nullsLast:e.length>2&&"nl"===c.safeLowercase(e[2])}},t.sortingRequestToString=function(e){return e.map((function(e){return t.sortingFieldToString(e)})).join("+")},t.sortingRequestFromString=function(e){return e?e.split("+").map((function(e){return t.sortingFieldFromString(e)})):[]},t.pagingRequestToQueryParams=function(e){if(e){var n={page:e.page,size:e.size};return e.search&&(n.search=e.search),e.sorting&&(n.sorting=t.sortingRequestToString(e.sorting)),n}},t.pagingRequestToString=function(e){if(!e)return"";var n=[];return n.push(String(e.page)),n.push(String(e.size)),n.push(c.safeTrim(e.search)),n.push(e.sorting?t.sortingRequestToString(e.sorting):""),n.join(":")},t.pagingRequestFromString=function(e){if(!e||c.isEmpty(e))return s({},l);var n=e.split(":");return n.length<4?s({},l):{page:Number(n[0]),size:Number(n[1]),search:String(n[2]),sorting:c.isEmpty(n[3])?void 0:t.sortingRequestFromString(n[3])}},t}(),d=function(){function t(){}return t.formatNumber=function(t,e){return void 0===e&&(e=2),String(t).padStart(e,"0")},t.parseDate=function(t){if(t)return"string"==typeof t?new Date(t):t},t.formatDateForHumans=function(e,n){if(void 0===n&&(n=!1),!(e=t.parseDate(e)))return"";var r=e.getFullYear(),o=t.formatNumber(e.getMonth()+1),i=t.formatNumber(e.getDate()),s="".concat(r,"-").concat(o,"-").concat(i);if(!n)return s;var u=t.formatNumber(e.getHours()),a=t.formatNumber(e.getMinutes()),c=t.formatNumber(e.getSeconds());return"".concat(s," ").concat(u,":").concat(a,":").concat(c)},t.formatDateTimeForHumans=function(e){return t.formatDateForHumans(e,!0)},t.formatDateForInput=function(e){var n=t.parseDate(e);if(void 0===n)return"";var r=n.getFullYear(),o=t.formatNumber(n.getMonth()+1),i=t.formatNumber(n.getDate());return"".concat(r,"-").concat(o,"-").concat(i)},t.getDurationMs=function(e,n){if(e=t.parseDate(e),n=t.parseDate(n),a.isEmpty(e)||a.isEmpty(n))return null;try{return n.getTime()-e.getTime()}catch(t){return null}},t.getSinceDurationMs=function(e){return t.getDurationMs(e,new Date)},t.formatDuration=function(t){if(!t)return"";var e=Math.floor(t/1e3);t-=1e3*e;var n=Math.floor(e/60);e-=60*n;var r=Math.floor(n/60);n-=60*r;var o=Math.floor(r/24);r-=24*o;var i=[];return o>0&&i.push("".concat(o,"d")),r>0&&i.push("".concat(r,"h")),n>0&&i.push("".concat(n,"m")),e>0&&0===o&&0===r&&i.push("".concat(e,"s")),t>0&&0===o&&0===r&&0===n&&i.push("".concat(t,"ms")),i.join(" ")},t}(),y=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.parseNumber=function(t){if(!t)return null;var e=Number(t);return Number.isNaN(e)?null:e},e.round=function(t,e){e||(e=0);var n=Math.pow(10,e);return Math.round(t*n)/n},e.portionToPercent=function(t,n){if(null==t)return"";var r=e.round(100*t,n);return"".concat(r,"%")},e}(a),v=function(){function t(t){this.baseUrl=t}return t.pagingRequestToQueryParams=function(t){return g.pagingRequestToQueryParams(t)},t.prototype.getHeaders=function(t){return Promise.resolve({"Content-Type":"application/json"})},t.prototype.paramsToQueryString=function(t){if(!t)return"";var e=new URLSearchParams(t),n=new URLSearchParams;e.forEach((function(t,e){""!==t&&void 0!==t&&"undefined"!==t&&n.set(e,t)}));var r=n.toString();return c.isEmpty(r)?"":"?".concat(r)},t.prototype.getUrl=function(t,e){var n=[c.trimTrailingSlashes(this.baseUrl),c.trimLeadingSlashes(t)].join("/");return e&&(n="".concat(n).concat(this.paramsToQueryString(e))),n},t.prototype.getRequestOptions=function(t,e,n){return void 0===e&&(e="GET"),void 0===n&&(n=null),this.getHeaders(t).then((function(t){return{method:e,headers:t,body:null===n?null:n instanceof FormData?n:JSON.stringify(n)}}))},t.prototype.processRequest=function(t,e){return fetch(this.getUrl(t),e).then((function(t){if(!t.ok){var e={cause:t.status};return"application/json"===t.headers.get("Content-Type")?t.json().then((function(n){if(n.message)throw new Error(n.message,e);if(n.error)throw new Error(n.error,e);throw new Error(t.statusText,e)}),(function(){throw new Error(t.statusText,e)})):t.text().then((function(n){throw c.isEmpty(n)?new Error(t.statusText,e):new Error(n,e)}),(function(){throw new Error(t.statusText,e)}))}return t}))},t.prototype.processRequestJson=function(t,e){return this.processRequest(t,e).then((function(t){return t.json()}))},t.prototype.getJson=function(t,e){var n=this;return e&&(t="".concat(t).concat(this.paramsToQueryString(e))),this.getRequestOptions(t).then((function(e){return n.processRequestJson(t,e)}))},t.prototype.postJson=function(t,e){var n=this;return void 0===e&&(e=null),this.getRequestOptions(t,"POST",e).then((function(e){return n.processRequestJson(t,e)}))},t.prototype.putJson=function(t,e){var n=this;return void 0===e&&(e=null),this.getRequestOptions(t,"PUT",e).then((function(e){return n.processRequestJson(t,e)}))},t.prototype.get=function(t){var e=this;return this.getRequestOptions(t).then((function(n){return e.processRequest(t,n)}))},t.prototype.del=function(t){var e=this;return this.getRequestOptions(t,"DELETE").then((function(n){return e.processRequest(t,n)}))},t.prototype.post=function(t,e){var n=this;return void 0===e&&(e=null),this.getRequestOptions(t,"POST",e).then((function(e){return n.processRequest(t,e)}))},t.prototype.put=function(t,e){var n=this;return void 0===e&&(e=null),this.getRequestOptions(t,"PUT",e).then((function(e){return n.processRequest(t,e)}))},t}(),m=function(){function t(t,e){this.client=t,this.name=e}return t.prototype.loadSingle=function(t){return this.client.getJson("".concat(this.name,"/").concat(t))},t.prototype.loadPage=function(t){return this.client.getJson(this.name,v.pagingRequestToQueryParams(t))},t.prototype.save=function(t){return t.id?this.client.putJson("".concat(this.name,"/").concat(t.id),t):this.client.postJson(this.name,t)},t.prototype.delete=function(t){return this.client.del("".concat(this.name,"/").concat(t))},t}(),T=function(t){function n(n,r,o){var i=t.call(this,n,r)||this;return i.cache=new e((function(e){return t.prototype.loadSingle.call(i,e)}),o),i}return i(n,t),n.prototype.loadSingle=function(t){return this.cache.get(t)},n.prototype.save=function(e){var n=this;return t.prototype.save.call(this,e).then((function(t){return t.id&&n.cache.set(t.id,t),t}))},n.prototype.delete=function(e){var n=this;return t.prototype.delete.call(this,e).then((function(){return n.cache.reset(e)}))},n}(m),k=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.loadSingle=function(t){throw new Error("Use loadSingleStub() instead!")},e.prototype.loadSingleStub=function(t){return this.client.getJson("".concat(this.name,"/").concat(t))},e.prototype.save=function(t){throw new Error("Use saveStub() instead!")},e.prototype.saveStub=function(t){return t.id?this.client.putJson("".concat(this.name,"/").concat(t.id),t):this.client.postJson(this.name,t)},e}(m),w=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.cache=new r((function(){return o.loadAllInternal()})),o}return i(e,t),e.prototype.loadAllInternal=function(){return this.client.getJson("".concat(this.name,"/all"))},e.prototype.loadAll=function(){return this.cache.get()},e.prototype.loadSingle=function(t){var e=this;return this.loadAll().then((function(n){var r=n.find((function(e){return e.id===t}));if(void 0===t)throw new Error("".concat(e.name," id ").concat(t," not found!"));return r}))},e.prototype.save=function(e){var n=this;return t.prototype.save.call(this,e).then((function(t){return n.cache.reset(),t}))},e.prototype.delete=function(e){var n=this;return t.prototype.delete.call(this,e).then((function(){return n.cache.reset()}))},e}(m),S=function(){function t(){this.handlers=new Map}return t.prototype.addEventListener=function(t,e){this.handlers.has(t)||this.handlers.set(t,[]),this.handlers.get(t).push(e)},t.prototype.removeEventListener=function(t,e){var n=this.handlers.get(t);n&&n.splice(n.indexOf(e),1)},t.prototype.triggerEvent=function(t,e){this.handlers.has(t)&&this.handlers.get(t).forEach((function(t){return t(e)}))},t}();!function(t){t.info="info",t.warning="warning",t.error="danger"}(u||(u={}));var E=function(){function t(t){void 0===t&&(t=10),this.maxAlerts=t,this.em=new S,this.alerts=[]}return t.prototype.addOnChangeHandler=function(t){this.em.addEventListener("change",t)},t.prototype.removeOnChangeHandler=function(t){this.em.removeEventListener("change",t)},t.prototype.triggerChange=function(){this.em.triggerEvent("change")},t.prototype.reset=function(){this.alerts=[],this.triggerChange()},t.prototype.remove=function(t){this.alerts.splice(this.alerts.indexOf(t),1),this.triggerChange()},t.prototype.add=function(t){for(this.alerts.push(t);this.alerts.length>this.maxAlerts;)this.alerts.shift();this.triggerChange()},t.prototype.custom=function(t,e){this.add({time:new Date,type:t,message:e})},t.prototype.err=function(t){this.custom(u.error,"string"==typeof t?t:t.toString())},t.prototype.warn=function(t){this.custom(u.warning,t)},t.prototype.info=function(t){this.custom(u.info,t)},t.prototype.getSummary=function(){var t=new Map;Object.values(u).forEach((function(e,n){t.set(e,0)}));for(var e=0;e<this.alerts.length;e++){var n=this.alerts[e],r=t.get(n.type)||0;t.set(n.type,r+1)}return t},t}(),I=function(){function t(t,e){void 0===e&&(e=!1);var n=this;this.isCancelled={value:!1},this.throwWhenCancelled=e,this.promise=new Promise((function(e,r){t.then((function(t){if(!n.isCancelled.value)return e(t)})).catch((function(t){!n.throwWhenCancelled&&n.isCancelled.value||r(t)}))}))}return t.prototype.cancel=function(){this.isCancelled.value=!0},t}(),x=function(t){function e(e){return t.call(this,"".concat(c.trimSlashes(e),"/api/oauth"))||this}return i(e,t),e.prototype.jwks=function(){return this.getJson("jwks.json")},e.prototype.verifyIdToken=function(t){return this.getJson("id-tokens/verify/".concat(t))},e.prototype.requestIdTokenFromLogin=function(t){return this.postJson("id-tokens/from-login",t)},e.prototype.refreshIdToken=function(t){return this.postJson("id-tokens/refresh",t)},e.prototype.requestAccessToken=function(t){return this.postJson("access-tokens/from-id-token",t)},e}(v),b=function(){function t(t,e){this.eventManager=new S,this.audience=e,this.oAuthServer=new x(t),this.accessTokens=new Map}return t.prototype.addIdTokenChangedHandler=function(t){this.eventManager.addEventListener("id-token-changed",t)},t.prototype.isTokenExpired=function(t){if(null==t)return!1;var e=Date.now();return new Date(t).getTime()<e},t.prototype.isTokenReadyForRefresh=function(t,e){return null!=e&&new Date((e.getTime()+t.getTime())/2)<new Date},t.prototype.isValidIdToken=function(t){return void 0!==t&&!this.isTokenExpired(t.expires)},t.prototype.hasValidIdToken=function(){return this.isValidIdToken(this.idToken)},t.prototype.isValidAccessToken=function(t){return void 0!==t&&!this.isTokenExpired(t.expires)},t.prototype.hasValidAccessToken=function(t){return this.isValidAccessToken(this.accessTokens.get(t))},t.prototype.reset=function(){this.setIdToken(void 0),this.accessTokens.clear()},t.prototype.getIdToken=function(){var t=this;return void 0!==this.idToken&&this.hasValidIdToken()?this.isTokenReadyForRefresh(this.idToken.issuedAt,this.idToken.expires)?this.oAuthServer.refreshIdToken({idToken:this.idToken.idToken}).then((function(e){return t.setIdToken(e),e.idToken})):Promise.resolve(this.idToken.idToken):Promise.reject("No valid ID token!")},t.prototype.setIdToken=function(t){if(!this.isValidIdToken(t))throw new Error("Received ID token is not valid!");this.idToken=t,this.eventManager.triggerEvent("id-token-changed",t)},t.prototype.verifyIdToken=function(t){var e=this;return this.oAuthServer.verifyIdToken(t).then((function(t){return e.setIdToken(t)})).then((function(){return!0}))},t.prototype.login=function(t,e){var n=this;return this.reset(),this.oAuthServer.requestIdTokenFromLogin({login:t,password:e,targetAudience:this.audience}).then((function(t){return n.setIdToken(t),!0}))},t.prototype.getAccessTokenInternal=function(t){var e=this;return this.getIdToken().then((function(n){return e.oAuthServer.requestAccessToken({idToken:n,targetAudience:e.audience,privilege:t}).then((function(n){return e.isValidAccessToken(n)?(e.accessTokens.set(t,n),n):Promise.reject("Received access token is not valid!")}))}))},t.prototype.getAccessToken=function(t){var e=this.accessTokens.get(t);return void 0!==e&&this.isValidAccessToken(e)?(this.isTokenReadyForRefresh(e.issuedAt,e.expires)&&this.getAccessTokenInternal(t),Promise.resolve(e.accessToken)):this.getAccessTokenInternal(t).then((function(t){return t.accessToken}))},t}(),M=function(){function t(t){this.value=t}return t.prototype.getSubjectType=function(){return c.isEmpty(this.value)?null:this.value.split(":")[0]},t.prototype.getSubjectContent=function(){if(c.isEmpty(this.value))return null;var t=this.value.split("//");return t.length>1?t[1]:null},t.prototype.toString=function(){return this.value},t}(),R=function(t){function e(e,n){void 0===n&&(n="*");var o=t.call(this,e)||this;o.defaultPrivilege=n,o.insecureClient=new v(e),o.serverInfo=new r((function(){return o.getServerInfoInternal()})),o.tokenManager=new r((function(){return o.getTokenManagerInternal()}));var i=o.getIdTokenFromUrl();if(null!==i)o.setIdTokenRaw(i);else{var s=o.getIdTokenFromLocalStorage();s&&o.setIdToken(s)}return o}return i(e,t),e.prototype.getPrivilege=function(t){return this.defaultPrivilege},e.prototype.getIdTokenFromUrl=function(){return new URLSearchParams(document.location.search).get("token")},e.prototype.getIdTokenFromLocalStorage=function(){var t=localStorage.getItem("id-token");return t?JSON.parse(t):null},e.prototype.saveIdTokenToLocalStorage=function(t){var e=t?JSON.stringify(t):null;null!==e?localStorage.setItem("id-token",e):localStorage.removeItem("id-token")},e.prototype.addIdTokenChangedHandler=function(t){this.getTokenManager().then((function(e){return e.addIdTokenChangedHandler(t)}))},e.prototype.getServerInfoInternal=function(){return this.insecureClient.getJson("status/info")},e.prototype.getServerInfo=function(){return this.serverInfo.get()},e.prototype.getTokenManagerInternal=function(){var t=this;return this.getServerInfo().then((function(e){var n=new b(e.oauthServerUrl,e.targetAudience);return n.addIdTokenChangedHandler((function(e){return t.saveIdTokenToLocalStorage(e)})),n}))},e.prototype.getTokenManager=function(){return this.tokenManager.get()},e.prototype.login=function(t,e){return this.getTokenManager().then((function(n){return n.login(t,e)}))},e.prototype.setIdToken=function(t){return this.getTokenManager().then((function(e){return e.setIdToken(t)})).then((function(){return!0}))},e.prototype.setIdTokenRaw=function(t){return this.getTokenManager().then((function(e){return e.verifyIdToken(t)}))},e.prototype.getHeaders=function(t){var e=this;return this.getTokenManager().then((function(n){return n.getAccessToken(e.getPrivilege(t))})).then((function(t){return{"Content-Type":"application/json",Authorization:"Bearer ".concat(t)}}))},e}(v),A=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.distanceTo=function(t){return Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},t.prototype.equalsTo=function(t){return!!t&&(this.x===t.x&&this.y===t.y)},t.prototype.size=function(){return this.distanceTo(new t(0,0))},t.prototype.inSize=function(e){var n=this.size();if(0!==n){var r=e/n;return new t(this.x*r,this.y*r)}return this},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.multiply=function(e){return new t(this.x*e,this.y*e)},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y)},t.prototype.sub=function(t){return this.subtract(t)},t.prototype.toArray=function(){return[this.x,this.y]},t.fromArray=function(e){if("object"==typeof e&&2===e.length)return new t(e[0],e[1])},t.prototype.clone=function(){return new t(this.x,this.y)},t.prototype.getAngleToYAxis=function(t){var e=t.subtract(this),n=e.y<0,r=e.x/e.size(),o=Math.asin(r);return(n?Math.PI-o:o)||0},t.prototype.getNeighborPositions=function(e,n){void 0===e&&(e=1),void 0===n&&(n=!1);for(var r=[],o=this.x+e,i=this.x-e;i<=o;i++)for(var s=this.y+e,u=this.y-e;u<=s;u++){var a=new t(i,u);!n&&this.equalsTo(a)||r.push(a)}return r},t.prototype.getClosest=function(t){if(!t||0===t.length)return null;if(1===t.length)return t[0];for(var e=t[0],n=this.distanceTo(e),r=1,o=t.length;r<o;r++){var i=this.distanceTo(t[r]);i<n&&(e=t[r],n=i)}return e},t.prototype.toString=function(t){return void 0===t&&(t=2),"[".concat(y.round(this.x,t),",").concat(y.round(this.y,t),"]")},t}();export{h as ArrayUtil,p as AsyncUtil,f as ByteUtil,t as CacheAsync,I as CancellablePromise,d as DateUtil,T as EntityCachedClient,m as EntityClient,k as EntityClientWithStub,S as EventManager,e as HashCacheAsync,n as Lazy,r as LazyAsync,w as LookupClient,y as NumberUtil,x as OAuthRestClient,M as OAuthSubject,b as OAuthTokenManager,a as ObjectUtil,g as PagingUtil,v as RestClient,R as RestClientWithOAuth,c as StringUtil,u as UserAlertType,E as UserAlerts,A as Vector2};
2
2
  //# sourceMappingURL=index.esm.js.map