@elastic/ems-client 8.7.0 → 8.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,3 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
3
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
4
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
5
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
6
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
7
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
8
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
9
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
10
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
11
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
12
1
  /*
13
2
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
14
3
  * or more contributor license agreements. Licensed under the Elastic License
@@ -17,16 +6,17 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
17
6
  */
18
7
  import _ from 'lodash';
19
8
  import { TMSService } from './tms_service';
20
- import { FileLayer } from './file_layer';
9
+ import { EMSFormatType, FileLayer } from './file_layer';
21
10
  import semverCoerce from 'semver/functions/coerce';
22
11
  import semverValid from 'semver/functions/valid';
23
12
  import semverMajor from 'semver/functions/major';
24
13
  import semverMinor from 'semver/functions/minor';
25
- import { format as formatUrl, parse as parseUrl } from 'url';
14
+ import { format as formatUrl, parse as parseUrl, UrlObject } from 'url';
26
15
  import { toAbsoluteUrl } from './utils';
16
+ import { ParsedUrlQueryInput } from 'querystring';
27
17
  import { LRUCache } from 'lru-cache';
28
- var REST_API_REGEX = /\d{4}-\d{2}-\d{2}/;
29
- export var LATEST_API_URL_PATH = 'latest';
18
+ const REST_API_REGEX = /\d{4}-\d{2}-\d{2}/;
19
+ export const LATEST_API_URL_PATH = 'latest';
30
20
  /**
31
21
  * plugins cannot have upstream dependencies on core/*-kibana.
32
22
  * Work-around by copy-pasting modifyUrl routine here.
@@ -34,7 +24,7 @@ export var LATEST_API_URL_PATH = 'latest';
34
24
  * @param block
35
25
  */
36
26
  function modifyUrlLocal(url, block) {
37
- var parsed = parseUrl(url, true);
27
+ const parsed = parseUrl(url, true);
38
28
 
39
29
  // copy over the most specific version of each
40
30
  // property. By default, the parsed url includes
@@ -42,7 +32,7 @@ function modifyUrlLocal(url, block) {
42
32
  // pathname + search, or search and query) and keeping
43
33
  // track of which property is actually used when they
44
34
  // are formatted is harder than necessary
45
- var meaningfulParts = {
35
+ const meaningfulParts = {
46
36
  protocol: parsed.protocol,
47
37
  slashes: parsed.slashes,
48
38
  auth: parsed.auth,
@@ -54,7 +44,7 @@ function modifyUrlLocal(url, block) {
54
44
  };
55
45
 
56
46
  // the block modifies the meaningfulParts object, or returns a new one
57
- var modifiedParts = block(meaningfulParts) || meaningfulParts;
47
+ const modifiedParts = block(meaningfulParts) || meaningfulParts;
58
48
 
59
49
  // format the modified/replaced meaningfulParts back into a url
60
50
  return formatUrl({
@@ -68,11 +58,7 @@ function modifyUrlLocal(url, block) {
68
58
  hash: modifiedParts.hash
69
59
  });
70
60
  }
71
- var extendUrl = function extendUrl(url, props) {
72
- return modifyUrlLocal(url, function (parsed) {
73
- return _.merge(parsed, props);
74
- });
75
- };
61
+ const extendUrl = (url, props) => modifyUrlLocal(url, parsed => _.merge(parsed, props));
76
62
 
77
63
  /**
78
64
  * Unescape a url template that was escaped by encodeURI() so leaflet
@@ -80,38 +66,36 @@ var extendUrl = function extendUrl(url, props) {
80
66
  * @param {String} url
81
67
  * @return {String}
82
68
  */
83
- var unescapeTemplateVars = function unescapeTemplateVars(url) {
84
- var ENCODED_TEMPLATE_VARS_RE = /%7B(\w+?)%7D/g;
85
- return url.replace(ENCODED_TEMPLATE_VARS_RE, function (total, varName) {
86
- return "{".concat(varName, "}");
87
- });
69
+ const unescapeTemplateVars = url => {
70
+ const ENCODED_TEMPLATE_VARS_RE = /%7B(\w+?)%7D/g;
71
+ return url.replace(ENCODED_TEMPLATE_VARS_RE, (total, varName) => `{${varName}}`);
88
72
  };
89
73
  //this is not the default locale from Kibana, but the default locale supported by the Elastic Maps Service
90
- var DEFAULT_LANGUAGE = 'en';
91
- export var EMSClient = /*#__PURE__*/function () {
92
- function EMSClient(config) {
93
- _classCallCheck(this, EMSClient);
94
- _defineProperty(this, "EMS_LOAD_TIMEOUT", 32000);
95
- _defineProperty(this, "_queryParams", void 0);
96
- _defineProperty(this, "_appVersion", void 0);
97
- _defineProperty(this, "_fetchFunction", void 0);
98
- _defineProperty(this, "_sanitizer", void 0);
99
- _defineProperty(this, "_fileApiUrl", void 0);
100
- _defineProperty(this, "_tileApiUrl", void 0);
101
- _defineProperty(this, "_emsVersion", void 0);
102
- _defineProperty(this, "_emsLandingPageUrl", void 0);
103
- _defineProperty(this, "_language", void 0);
104
- _defineProperty(this, "_proxyPath", void 0);
105
- _defineProperty(this, "_cache", void 0);
106
- _defineProperty(this, "_isRestApi", false);
107
- /**
108
- * these methods are assigned outside the constructor
109
- */
110
- _defineProperty(this, "_getMainCatalog", void 0);
111
- _defineProperty(this, "_getDefaultTMSCatalog", void 0);
112
- _defineProperty(this, "_getDefaultFileCatalog", void 0);
113
- _defineProperty(this, "_loadTMSServices", void 0);
114
- _defineProperty(this, "_loadFileLayers", void 0);
74
+ const DEFAULT_LANGUAGE = 'en';
75
+ export class EMSClient {
76
+ EMS_LOAD_TIMEOUT = 32000;
77
+ _queryParams;
78
+ _appVersion;
79
+ _fetchFunction;
80
+ _sanitizer;
81
+ _fileApiUrl;
82
+ _tileApiUrl;
83
+ _emsVersion;
84
+ _emsLandingPageUrl;
85
+ _language;
86
+ _proxyPath;
87
+ _cache;
88
+ _isRestApi = false;
89
+
90
+ /**
91
+ * these methods are assigned outside the constructor
92
+ */
93
+ _getMainCatalog;
94
+ _getDefaultTMSCatalog;
95
+ _getDefaultFileCatalog;
96
+ _loadTMSServices;
97
+ _loadFileLayers;
98
+ constructor(config) {
115
99
  // Remove kbnVersion in 8.0
116
100
  if ('kbnVersion' in config) {
117
101
  console.warn('The "kbnVersion" parameter for ems-client is deprecated. Please use "appVersion" instead.');
@@ -124,9 +108,7 @@ export var EMSClient = /*#__PURE__*/function () {
124
108
  my_app_name: config.appName || 'kibana',
125
109
  my_app_version: this._appVersion
126
110
  };
127
- this._sanitizer = config.htmlSanitizer ? config.htmlSanitizer : function (x) {
128
- return x;
129
- };
111
+ this._sanitizer = config.htmlSanitizer ? config.htmlSanitizer : x => x;
130
112
  this._tileApiUrl = config.tileApiUrl;
131
113
  this._fileApiUrl = config.fileApiUrl;
132
114
  this._emsVersion = this._getEmsVersion(config.emsVersion);
@@ -140,466 +122,198 @@ export var EMSClient = /*#__PURE__*/function () {
140
122
  });
141
123
  this._invalidateSettings();
142
124
  }
143
- return _createClass(EMSClient, [{
144
- key: "getDefaultLocale",
145
- value: function getDefaultLocale() {
146
- return DEFAULT_LANGUAGE;
147
- }
148
- }, {
149
- key: "getLocale",
150
- value: function getLocale() {
151
- return this._language;
125
+ getDefaultLocale() {
126
+ return DEFAULT_LANGUAGE;
127
+ }
128
+ getLocale() {
129
+ return this._language;
130
+ }
131
+ getValueInLanguage(i18nObject) {
132
+ if (!i18nObject) {
133
+ return '';
152
134
  }
153
- }, {
154
- key: "getValueInLanguage",
155
- value: function getValueInLanguage(i18nObject) {
156
- if (!i18nObject) {
157
- return '';
135
+ return i18nObject[this._language] ? i18nObject[this._language] : i18nObject[DEFAULT_LANGUAGE];
136
+ }
137
+
138
+ /**
139
+ * this internal method is overridden by the tests to simulate custom manifest.
140
+ */
141
+ async getManifest(endpointUrl) {
142
+ try {
143
+ const url = extendUrl(endpointUrl, {
144
+ query: this._queryParams
145
+ });
146
+ const response = await this._fetchWithTimeout(url);
147
+ if (!response.ok) {
148
+ throw new Error(response.statusText);
149
+ }
150
+ if (response) {
151
+ return await response.json();
152
+ } else {
153
+ throw new Error('Response not found');
154
+ }
155
+ } catch (e) {
156
+ if (e instanceof Error) {
157
+ throw e;
158
+ } else {
159
+ throw new Error('Unknown error', {
160
+ cause: e
161
+ });
158
162
  }
159
- return i18nObject[this._language] ? i18nObject[this._language] : i18nObject[DEFAULT_LANGUAGE];
160
163
  }
164
+ }
161
165
 
162
- /**
163
- * this internal method is overridden by the tests to simulate custom manifest.
164
- */
165
- }, {
166
- key: "getManifest",
167
- value: (function () {
168
- var _getManifest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(endpointUrl) {
169
- var url, response, _t;
170
- return _regenerator().w(function (_context) {
171
- while (1) switch (_context.p = _context.n) {
172
- case 0:
173
- _context.p = 0;
174
- url = extendUrl(endpointUrl, {
175
- query: this._queryParams
176
- });
177
- _context.n = 1;
178
- return this._fetchWithTimeout(url);
179
- case 1:
180
- response = _context.v;
181
- if (response.ok) {
182
- _context.n = 2;
183
- break;
184
- }
185
- throw new Error(response.statusText);
186
- case 2:
187
- if (!response) {
188
- _context.n = 4;
189
- break;
190
- }
191
- _context.n = 3;
192
- return response.json();
193
- case 3:
194
- return _context.a(2, _context.v);
195
- case 4:
196
- throw new Error('Response not found');
197
- case 5:
198
- _context.n = 8;
199
- break;
200
- case 6:
201
- _context.p = 6;
202
- _t = _context.v;
203
- if (!(_t instanceof Error)) {
204
- _context.n = 7;
205
- break;
206
- }
207
- throw _t;
208
- case 7:
209
- throw new Error('Unknown error', {
210
- cause: _t
211
- });
212
- case 8:
213
- return _context.a(2);
214
- }
215
- }, _callee, this, [[0, 6]]);
216
- }));
217
- function getManifest(_x) {
218
- return _getManifest.apply(this, arguments);
219
- }
220
- return getManifest;
221
- }()
222
- /**
223
- * Add optional query-parameters to all requests
224
- *
225
- * @param additionalQueryParams
226
- */
227
- )
228
- }, {
229
- key: "addQueryParams",
230
- value: function addQueryParams(additionalQueryParams) {
231
- for (var _key in additionalQueryParams) {
232
- if (Object.prototype.hasOwnProperty.call(additionalQueryParams, _key)) {
233
- if (additionalQueryParams[_key] !== this._queryParams[_key]) {
234
- //changes detected.
235
- this._queryParams = _.assign({}, this._queryParams, additionalQueryParams);
236
- this._invalidateSettings();
237
- break;
238
- }
166
+ /**
167
+ * Add optional query-parameters to all requests
168
+ *
169
+ * @param additionalQueryParams
170
+ */
171
+ addQueryParams(additionalQueryParams) {
172
+ for (const key in additionalQueryParams) {
173
+ if (Object.prototype.hasOwnProperty.call(additionalQueryParams, key)) {
174
+ if (additionalQueryParams[key] !== this._queryParams[key]) {
175
+ //changes detected.
176
+ this._queryParams = _.assign({}, this._queryParams, additionalQueryParams);
177
+ this._invalidateSettings();
178
+ break;
239
179
  }
240
180
  }
241
181
  }
242
- }, {
243
- key: "getMainManifest",
244
- value: function () {
245
- var _getMainManifest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
246
- return _regenerator().w(function (_context2) {
247
- while (1) switch (_context2.n) {
248
- case 0:
249
- _context2.n = 1;
250
- return this._getMainCatalog();
251
- case 1:
252
- return _context2.a(2, _context2.v);
253
- }
254
- }, _callee2, this);
255
- }));
256
- function getMainManifest() {
257
- return _getMainManifest.apply(this, arguments);
258
- }
259
- return getMainManifest;
260
- }()
261
- }, {
262
- key: "getDefaultFileManifest",
263
- value: function () {
264
- var _getDefaultFileManifest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
265
- return _regenerator().w(function (_context3) {
266
- while (1) switch (_context3.n) {
267
- case 0:
268
- _context3.n = 1;
269
- return this._getDefaultFileCatalog();
270
- case 1:
271
- return _context3.a(2, _context3.v);
272
- }
273
- }, _callee3, this);
274
- }));
275
- function getDefaultFileManifest() {
276
- return _getDefaultFileManifest.apply(this, arguments);
277
- }
278
- return getDefaultFileManifest;
279
- }()
280
- }, {
281
- key: "getDefaultTMSManifest",
282
- value: function () {
283
- var _getDefaultTMSManifest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
284
- return _regenerator().w(function (_context4) {
285
- while (1) switch (_context4.n) {
286
- case 0:
287
- _context4.n = 1;
288
- return this._getDefaultTMSCatalog();
289
- case 1:
290
- return _context4.a(2, _context4.v);
291
- }
292
- }, _callee4, this);
293
- }));
294
- function getDefaultTMSManifest() {
295
- return _getDefaultTMSManifest.apply(this, arguments);
296
- }
297
- return getDefaultTMSManifest;
298
- }()
299
- }, {
300
- key: "getFileLayers",
301
- value: function () {
302
- var _getFileLayers = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
303
- return _regenerator().w(function (_context5) {
304
- while (1) switch (_context5.n) {
305
- case 0:
306
- _context5.n = 1;
307
- return this._loadFileLayers();
308
- case 1:
309
- return _context5.a(2, _context5.v);
310
- }
311
- }, _callee5, this);
312
- }));
313
- function getFileLayers() {
314
- return _getFileLayers.apply(this, arguments);
315
- }
316
- return getFileLayers;
317
- }()
318
- }, {
319
- key: "getTMSServices",
320
- value: function () {
321
- var _getTMSServices = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
322
- return _regenerator().w(function (_context6) {
323
- while (1) switch (_context6.n) {
324
- case 0:
325
- _context6.n = 1;
326
- return this._loadTMSServices();
327
- case 1:
328
- return _context6.a(2, _context6.v);
329
- }
330
- }, _callee6, this);
331
- }));
332
- function getTMSServices() {
333
- return _getTMSServices.apply(this, arguments);
182
+ }
183
+ async getMainManifest() {
184
+ return await this._getMainCatalog();
185
+ }
186
+ async getDefaultFileManifest() {
187
+ return await this._getDefaultFileCatalog();
188
+ }
189
+ async getDefaultTMSManifest() {
190
+ return await this._getDefaultTMSCatalog();
191
+ }
192
+ async getFileLayers() {
193
+ return await this._loadFileLayers();
194
+ }
195
+ async getTMSServices() {
196
+ return await this._loadTMSServices();
197
+ }
198
+ cacheGeoJson(layerId, geoJson) {
199
+ this._cache.set(layerId, geoJson);
200
+ return;
201
+ }
202
+ getCachedGeoJson(layerId) {
203
+ return this._cache.get(layerId);
204
+ }
205
+ getEmsVersion() {
206
+ return this._emsVersion;
207
+ }
208
+ getTileApiUrl() {
209
+ return this._tileApiUrl;
210
+ }
211
+ getFileApiUrl() {
212
+ return this._fileApiUrl;
213
+ }
214
+ getLandingPageUrl() {
215
+ return this._emsLandingPageUrl;
216
+ }
217
+ sanitizeHtml(html) {
218
+ return this._sanitizer(html);
219
+ }
220
+ extendUrlWithParams(url) {
221
+ return unescapeTemplateVars(extendUrl(url, {
222
+ query: this._queryParams
223
+ }));
224
+ }
225
+ async findFileLayerById(id) {
226
+ const fileLayers = await this.getFileLayers();
227
+ for (let i = 0; i < fileLayers.length; i++) {
228
+ if (fileLayers[i].hasId(id)) {
229
+ return fileLayers[i];
334
230
  }
335
- return getTMSServices;
336
- }()
337
- }, {
338
- key: "cacheGeoJson",
339
- value: function cacheGeoJson(layerId, geoJson) {
340
- this._cache.set(layerId, geoJson);
341
- return;
342
- }
343
- }, {
344
- key: "getCachedGeoJson",
345
- value: function getCachedGeoJson(layerId) {
346
- return this._cache.get(layerId);
347
- }
348
- }, {
349
- key: "getEmsVersion",
350
- value: function getEmsVersion() {
351
- return this._emsVersion;
352
- }
353
- }, {
354
- key: "getTileApiUrl",
355
- value: function getTileApiUrl() {
356
- return this._tileApiUrl;
357
231
  }
358
- }, {
359
- key: "getFileApiUrl",
360
- value: function getFileApiUrl() {
361
- return this._fileApiUrl;
362
- }
363
- }, {
364
- key: "getLandingPageUrl",
365
- value: function getLandingPageUrl() {
366
- return this._emsLandingPageUrl;
232
+ }
233
+ async findTMSServiceById(id) {
234
+ const tmsServices = await this.getTMSServices();
235
+ for (let i = 0; i < tmsServices.length; i++) {
236
+ if (tmsServices[i].hasId(id)) {
237
+ return tmsServices[i];
238
+ }
367
239
  }
368
- }, {
369
- key: "sanitizeHtml",
370
- value: function sanitizeHtml(html) {
371
- return this._sanitizer(html);
240
+ }
241
+ _getEmsVersion(version) {
242
+ if (version?.match(REST_API_REGEX)) {
243
+ return version;
372
244
  }
373
- }, {
374
- key: "extendUrlWithParams",
375
- value: function extendUrlWithParams(url) {
376
- return unescapeTemplateVars(extendUrl(url, {
377
- query: this._queryParams
378
- }));
245
+ const semverVersion = semverValid(semverCoerce(version));
246
+ if (semverVersion) {
247
+ return `v${semverMajor(semverVersion)}.${semverMinor(semverVersion)}`;
248
+ } else {
249
+ throw new Error(`Invalid version: ${version}`);
379
250
  }
380
- }, {
381
- key: "findFileLayerById",
382
- value: function () {
383
- var _findFileLayerById = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(id) {
384
- var fileLayers, i;
385
- return _regenerator().w(function (_context7) {
386
- while (1) switch (_context7.n) {
387
- case 0:
388
- _context7.n = 1;
389
- return this.getFileLayers();
390
- case 1:
391
- fileLayers = _context7.v;
392
- i = 0;
393
- case 2:
394
- if (!(i < fileLayers.length)) {
395
- _context7.n = 4;
396
- break;
397
- }
398
- if (!fileLayers[i].hasId(id)) {
399
- _context7.n = 3;
400
- break;
401
- }
402
- return _context7.a(2, fileLayers[i]);
403
- case 3:
404
- i++;
405
- _context7.n = 2;
406
- break;
407
- case 4:
408
- return _context7.a(2);
409
- }
410
- }, _callee7, this);
411
- }));
412
- function findFileLayerById(_x2) {
413
- return _findFileLayerById.apply(this, arguments);
251
+ }
252
+ _fetchWithTimeout(url) {
253
+ return new Promise((resolve, reject) => {
254
+ const timer = setTimeout(() => reject(new Error(`Request to ${url} timed out`)), this.EMS_LOAD_TIMEOUT);
255
+ this._fetchFunction(url).then(response => {
256
+ clearTimeout(timer);
257
+ resolve(response);
258
+ }, err => {
259
+ clearTimeout(timer);
260
+ reject(err);
261
+ });
262
+ });
263
+ }
264
+ _invalidateSettings() {
265
+ this._cache.clear();
266
+ this._getMainCatalog = _.once(async () => {
267
+ const services = [];
268
+ if (this._tileApiUrl) {
269
+ const version = this._isRestApi ? LATEST_API_URL_PATH : this._emsVersion;
270
+ services.push({
271
+ type: 'tms',
272
+ manifest: toAbsoluteUrl(this._tileApiUrl, `${version}/manifest`)
273
+ });
414
274
  }
415
- return findFileLayerById;
416
- }()
417
- }, {
418
- key: "findTMSServiceById",
419
- value: function () {
420
- var _findTMSServiceById = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(id) {
421
- var tmsServices, i;
422
- return _regenerator().w(function (_context8) {
423
- while (1) switch (_context8.n) {
424
- case 0:
425
- _context8.n = 1;
426
- return this.getTMSServices();
427
- case 1:
428
- tmsServices = _context8.v;
429
- i = 0;
430
- case 2:
431
- if (!(i < tmsServices.length)) {
432
- _context8.n = 4;
433
- break;
434
- }
435
- if (!tmsServices[i].hasId(id)) {
436
- _context8.n = 3;
437
- break;
438
- }
439
- return _context8.a(2, tmsServices[i]);
440
- case 3:
441
- i++;
442
- _context8.n = 2;
443
- break;
444
- case 4:
445
- return _context8.a(2);
446
- }
447
- }, _callee8, this);
448
- }));
449
- function findTMSServiceById(_x3) {
450
- return _findTMSServiceById.apply(this, arguments);
275
+ if (this._fileApiUrl) {
276
+ const version = this._isRestApi ? LATEST_API_URL_PATH : this._emsVersion;
277
+ services.push({
278
+ type: 'file',
279
+ manifest: toAbsoluteUrl(this._fileApiUrl, `${version}/manifest`)
280
+ });
451
281
  }
452
- return findTMSServiceById;
453
- }()
454
- }, {
455
- key: "_getEmsVersion",
456
- value: function _getEmsVersion(version) {
457
- if (version !== null && version !== void 0 && version.match(REST_API_REGEX)) {
458
- return version;
282
+ return {
283
+ services: services
284
+ };
285
+ });
286
+ this._getDefaultTMSCatalog = _.once(async () => {
287
+ const catalogue = await this._getMainCatalog();
288
+ const firstService = catalogue.services.find(service => service.type === 'tms');
289
+ if (!firstService) {
290
+ return {
291
+ services: []
292
+ };
459
293
  }
460
- var semverVersion = semverValid(semverCoerce(version));
461
- if (semverVersion) {
462
- return "v".concat(semverMajor(semverVersion), ".").concat(semverMinor(semverVersion));
463
- } else {
464
- throw new Error("Invalid version: ".concat(version));
294
+ const url = this._proxyPath + firstService.manifest;
295
+ return await this.getManifest(url);
296
+ });
297
+ this._getDefaultFileCatalog = _.once(async () => {
298
+ const catalogue = await this._getMainCatalog();
299
+ const firstService = catalogue.services.find(service => service.type === 'file');
300
+ if (!firstService) {
301
+ return {
302
+ layers: []
303
+ };
465
304
  }
466
- }
467
- }, {
468
- key: "_fetchWithTimeout",
469
- value: function _fetchWithTimeout(url) {
470
- var _this = this;
471
- return new Promise(function (resolve, reject) {
472
- var timer = setTimeout(function () {
473
- return reject(new Error("Request to ".concat(url, " timed out")));
474
- }, _this.EMS_LOAD_TIMEOUT);
475
- _this._fetchFunction(url).then(function (response) {
476
- clearTimeout(timer);
477
- resolve(response);
478
- }, function (err) {
479
- clearTimeout(timer);
480
- reject(err);
481
- });
482
- });
483
- }
484
- }, {
485
- key: "_invalidateSettings",
486
- value: function _invalidateSettings() {
487
- var _this2 = this;
488
- this._cache.clear();
489
- this._getMainCatalog = _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
490
- var services, version, _version;
491
- return _regenerator().w(function (_context9) {
492
- while (1) switch (_context9.n) {
493
- case 0:
494
- services = [];
495
- if (_this2._tileApiUrl) {
496
- version = _this2._isRestApi ? LATEST_API_URL_PATH : _this2._emsVersion;
497
- services.push({
498
- type: 'tms',
499
- manifest: toAbsoluteUrl(_this2._tileApiUrl, "".concat(version, "/manifest"))
500
- });
501
- }
502
- if (_this2._fileApiUrl) {
503
- _version = _this2._isRestApi ? LATEST_API_URL_PATH : _this2._emsVersion;
504
- services.push({
505
- type: 'file',
506
- manifest: toAbsoluteUrl(_this2._fileApiUrl, "".concat(_version, "/manifest"))
507
- });
508
- }
509
- return _context9.a(2, {
510
- services: services
511
- });
512
- }
513
- }, _callee9);
514
- })));
515
- this._getDefaultTMSCatalog = _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
516
- var catalogue, firstService, url;
517
- return _regenerator().w(function (_context0) {
518
- while (1) switch (_context0.n) {
519
- case 0:
520
- _context0.n = 1;
521
- return _this2._getMainCatalog();
522
- case 1:
523
- catalogue = _context0.v;
524
- firstService = catalogue.services.find(function (service) {
525
- return service.type === 'tms';
526
- });
527
- if (firstService) {
528
- _context0.n = 2;
529
- break;
530
- }
531
- return _context0.a(2, {
532
- services: []
533
- });
534
- case 2:
535
- url = _this2._proxyPath + firstService.manifest;
536
- _context0.n = 3;
537
- return _this2.getManifest(url);
538
- case 3:
539
- return _context0.a(2, _context0.v);
540
- }
541
- }, _callee0);
542
- })));
543
- this._getDefaultFileCatalog = _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
544
- var catalogue, firstService, url;
545
- return _regenerator().w(function (_context1) {
546
- while (1) switch (_context1.n) {
547
- case 0:
548
- _context1.n = 1;
549
- return _this2._getMainCatalog();
550
- case 1:
551
- catalogue = _context1.v;
552
- firstService = catalogue.services.find(function (service) {
553
- return service.type === 'file';
554
- });
555
- if (firstService) {
556
- _context1.n = 2;
557
- break;
558
- }
559
- return _context1.a(2, {
560
- layers: []
561
- });
562
- case 2:
563
- url = _this2._proxyPath + firstService.manifest;
564
- _context1.n = 3;
565
- return _this2.getManifest(url);
566
- case 3:
567
- return _context1.a(2, _context1.v);
568
- }
569
- }, _callee1);
570
- })));
305
+ const url = this._proxyPath + firstService.manifest;
306
+ return await this.getManifest(url);
307
+ });
571
308
 
572
- //Cache the actual instances of TMSService as these in turn cache sub-manifests for the style-files
573
- this._loadTMSServices = _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10() {
574
- var tmsManifest;
575
- return _regenerator().w(function (_context10) {
576
- while (1) switch (_context10.n) {
577
- case 0:
578
- _context10.n = 1;
579
- return _this2._getDefaultTMSCatalog();
580
- case 1:
581
- tmsManifest = _context10.v;
582
- return _context10.a(2, tmsManifest.services.map(function (serviceConfig) {
583
- return new TMSService(serviceConfig, _this2, _this2._proxyPath);
584
- }));
585
- }
586
- }, _callee10);
587
- })));
588
- this._loadFileLayers = _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11() {
589
- var fileManifest;
590
- return _regenerator().w(function (_context11) {
591
- while (1) switch (_context11.n) {
592
- case 0:
593
- _context11.n = 1;
594
- return _this2._getDefaultFileCatalog();
595
- case 1:
596
- fileManifest = _context11.v;
597
- return _context11.a(2, fileManifest.layers.map(function (layerConfig) {
598
- return new FileLayer(layerConfig, _this2, _this2._proxyPath);
599
- }));
600
- }
601
- }, _callee11);
602
- })));
603
- }
604
- }]);
605
- }();
309
+ //Cache the actual instances of TMSService as these in turn cache sub-manifests for the style-files
310
+ this._loadTMSServices = _.once(async () => {
311
+ const tmsManifest = await this._getDefaultTMSCatalog();
312
+ return tmsManifest.services.map(serviceConfig => new TMSService(serviceConfig, this, this._proxyPath));
313
+ });
314
+ this._loadFileLayers = _.once(async () => {
315
+ const fileManifest = await this._getDefaultFileCatalog();
316
+ return fileManifest.layers.map(layerConfig => new FileLayer(layerConfig, this, this._proxyPath));
317
+ });
318
+ }
319
+ }