@elastic/ems-client 7.17.2 → 7.17.4

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.
@@ -35,7 +35,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
35
35
  _classCallCheck(this, TMSService);
36
36
  _this = _callSuper(this, TMSService, [config, emsClient, proxyPath]);
37
37
  _defineProperty(_this, "_config", void 0);
38
- _defineProperty(_this, "_getRasterStyleJson", _.once( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
38
+ _defineProperty(_this, "_getRasterStyleJson", _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
39
39
  var rasterUrl, url;
40
40
  return _regeneratorRuntime().wrap(function _callee$(_context) {
41
41
  while (1) switch (_context.prev = _context.next) {
@@ -55,7 +55,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
55
55
  }
56
56
  }, _callee);
57
57
  }))));
58
- _defineProperty(_this, "_getVectorStyleJsonRaw", _.once( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
58
+ _defineProperty(_this, "_getVectorStyleJsonRaw", _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
59
59
  var vectorUrl, url, vectorJson;
60
60
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
61
61
  while (1) switch (_context2.prev = _context2.next) {
@@ -79,7 +79,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
79
79
  }
80
80
  }, _callee2);
81
81
  }))));
82
- _defineProperty(_this, "_getVectorStyleJsonInlined", _.once( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
82
+ _defineProperty(_this, "_getVectorStyleJsonInlined", _.once(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
83
83
  var vectorJson, inlinedSources, sources, _iterator, _step, _sourceName, url, sourceUrl, extendedUrl, sourceJson, extendedTileUrls;
84
84
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
85
85
  while (1) switch (_context3.prev = _context3.next) {
@@ -166,7 +166,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
166
166
  return _createClass(TMSService, [{
167
167
  key: "getDefaultRasterStyle",
168
168
  value: function () {
169
- var _getDefaultRasterStyle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
169
+ var _getDefaultRasterStyle = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
170
170
  var _this2 = this;
171
171
  var tileJson, tiles;
172
172
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
@@ -202,7 +202,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
202
202
  }, {
203
203
  key: "getUrlTemplate",
204
204
  value: function () {
205
- var _getUrlTemplate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
205
+ var _getUrlTemplate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
206
206
  var tileJson, directUrl;
207
207
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
208
208
  while (1) switch (_context5.prev = _context5.next) {
@@ -233,7 +233,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
233
233
  }, {
234
234
  key: "getUrlTemplateForVector",
235
235
  value: function () {
236
- var _getUrlTemplateForVector = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(sourceId) {
236
+ var _getUrlTemplateForVector = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(sourceId) {
237
237
  var tileJson, directUrl;
238
238
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
239
239
  while (1) switch (_context6.prev = _context6.next) {
@@ -270,7 +270,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
270
270
  }, {
271
271
  key: "getVectorStyleSheet",
272
272
  value: function () {
273
- var _getVectorStyleSheet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
273
+ var _getVectorStyleSheet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
274
274
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
275
275
  while (1) switch (_context7.prev = _context7.next) {
276
276
  case 0:
@@ -292,7 +292,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
292
292
  }, {
293
293
  key: "getVectorStyleSheetRaw",
294
294
  value: function () {
295
- var _getVectorStyleSheetRaw = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
295
+ var _getVectorStyleSheetRaw = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
296
296
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
297
297
  while (1) switch (_context8.prev = _context8.next) {
298
298
  case 0:
@@ -314,7 +314,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
314
314
  }, {
315
315
  key: "getSpriteSheetMeta",
316
316
  value: function () {
317
- var _getSpriteSheetMeta = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
317
+ var _getSpriteSheetMeta = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
318
318
  var isRetina,
319
319
  metaUrl,
320
320
  spritePngs,
@@ -362,7 +362,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
362
362
  }, {
363
363
  key: "getSpriteSheetJsonPath",
364
364
  value: function () {
365
- var _getSpriteSheetJsonPath = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
365
+ var _getSpriteSheetJsonPath = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
366
366
  var isRetina,
367
367
  spriteSheetRootPath,
368
368
  suffix,
@@ -397,7 +397,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
397
397
  }, {
398
398
  key: "getSpriteSheetPngPath",
399
399
  value: function () {
400
- var _getSpriteSheetPngPath = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
400
+ var _getSpriteSheetPngPath = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
401
401
  var isRetina,
402
402
  spriteSheetRootPath,
403
403
  suffix,
@@ -437,7 +437,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
437
437
  }, {
438
438
  key: "getMinZoom",
439
439
  value: function () {
440
- var _getMinZoom = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
440
+ var _getMinZoom = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
441
441
  var tileJson;
442
442
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
443
443
  while (1) switch (_context12.prev = _context12.next) {
@@ -467,7 +467,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
467
467
  }, {
468
468
  key: "getMaxZoom",
469
469
  value: function () {
470
- var _getMaxZoom = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
470
+ var _getMaxZoom = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
471
471
  var tileJson;
472
472
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
473
473
  while (1) switch (_context13.prev = _context13.next) {
@@ -518,11 +518,10 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
518
518
  vectorFormats = this._getFormats(formatType, this._emsClient.getDefaultLocale());
519
519
  }
520
520
  if (!vectorFormats.length) {
521
- // eslint-disable-next-line max-len
522
521
  throw new Error("Cannot find ".concat(formatType, " tile layer for locale ").concat(this._emsClient.getLocale(), " or ").concat(this._emsClient.getDefaultLocale()));
523
522
  }
524
523
  var defaultStyle = vectorFormats[0];
525
- if (defaultStyle && defaultStyle.hasOwnProperty('url')) {
524
+ if (defaultStyle && Object.prototype.hasOwnProperty.call(defaultStyle, 'url')) {
526
525
  return defaultStyle.url;
527
526
  }
528
527
  }
@@ -536,7 +535,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
536
535
  }, {
537
536
  key: "_getSpriteSheetRootPath",
538
537
  value: function () {
539
- var _getSpriteSheetRootPath2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
538
+ var _getSpriteSheetRootPath2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
540
539
  var vectorStyleJson;
541
540
  return _regeneratorRuntime().wrap(function _callee14$(_context14) {
542
541
  while (1) switch (_context14.prev = _context14.next) {
@@ -566,7 +565,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
566
565
  }, {
567
566
  key: "_getUrlTemplateForGlyphs",
568
567
  value: function () {
569
- var _getUrlTemplateForGlyphs2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
568
+ var _getUrlTemplateForGlyphs2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
570
569
  var vectorStyleJson;
571
570
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
572
571
  while (1) switch (_context15.prev = _context15.next) {
@@ -1,29 +1,29 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`.getFileLayers[1] - getGeoJson defaults should convert topojson to geojson 1`] = `
4
- Object {
5
- "features": Array [
6
- Object {
7
- "geometry": Object {
8
- "coordinates": Array [
9
- Array [
10
- Array [
4
+ {
5
+ "features": [
6
+ {
7
+ "geometry": {
8
+ "coordinates": [
9
+ [
10
+ [
11
11
  72.77144284428442,
12
12
  62.593,
13
13
  ],
14
- Array [
14
+ [
15
15
  50.625,
16
16
  50.06444104410441,
17
17
  ],
18
- Array [
18
+ [
19
19
  91.7565793579358,
20
20
  35.46,
21
21
  ],
22
- Array [
22
+ [
23
23
  93.867,
24
24
  58.2621401140114,
25
25
  ],
26
- Array [
26
+ [
27
27
  72.77144284428442,
28
28
  62.593,
29
29
  ],
@@ -31,7 +31,7 @@ Object {
31
31
  ],
32
32
  "type": "Polygon",
33
33
  },
34
- "properties": Object {
34
+ "properties": {
35
35
  "foo": "bar",
36
36
  },
37
37
  "type": "Feature",
@@ -42,29 +42,29 @@ Object {
42
42
  `;
43
43
 
44
44
  exports[`.getFileLayers[1] - getGeoJson limited cache 1`] = `
45
- Object {
46
- "features": Array [
47
- Object {
48
- "geometry": Object {
49
- "coordinates": Array [
50
- Array [
51
- Array [
45
+ {
46
+ "features": [
47
+ {
48
+ "geometry": {
49
+ "coordinates": [
50
+ [
51
+ [
52
52
  72.77144284428442,
53
53
  62.593,
54
54
  ],
55
- Array [
55
+ [
56
56
  50.625,
57
57
  50.06444104410441,
58
58
  ],
59
- Array [
59
+ [
60
60
  91.7565793579358,
61
61
  35.46,
62
62
  ],
63
- Array [
63
+ [
64
64
  93.867,
65
65
  58.2621401140114,
66
66
  ],
67
- Array [
67
+ [
68
68
  72.77144284428442,
69
69
  62.593,
70
70
  ],
@@ -72,7 +72,7 @@ Object {
72
72
  ],
73
73
  "type": "Polygon",
74
74
  },
75
- "properties": Object {
75
+ "properties": {
76
76
  "foo": "bar",
77
77
  },
78
78
  "type": "Feature",
@@ -42,7 +42,7 @@ export function getEMSClient(options = {}) {
42
42
 
43
43
  const getManifestMock = jest
44
44
  .spyOn(emsClient, 'getManifest')
45
- .mockImplementation(async (url: string): Promise<any> => {
45
+ .mockImplementation(async (url: string): Promise<object | unknown> => {
46
46
  //simulate network calls
47
47
  if (url.startsWith('https://foobar')) {
48
48
  return EMS_CATALOGUE;
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- /target
package/.eslintrc DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "parser": "@typescript-eslint/parser",
3
- "plugins": ["@typescript-eslint"],
4
- "extends": [
5
- "plugin:@typescript-eslint/recommended",
6
- "prettier/@typescript-eslint",
7
- "plugin:prettier/recommended"
8
- ],
9
- "rules": {
10
- "@typescript-eslint/member-ordering": 2,
11
- "@typescript-eslint/camelcase": 0,
12
- "@typescript-eslint/no-explicit-any": 0,
13
- "@typescript-eslint/no-inferrable-types": 0,
14
- "@typescript-eslint/explicit-function-return-type": 0,
15
- "@typescript-eslint/no-non-null-assertion": 0,
16
- "@typescript-eslint/interface-name-prefix": 0
17
- }
18
- }
@@ -1,318 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.EMSClient = exports.LATEST_API_URL_PATH = void 0;
16
- /*
17
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
18
- * or more contributor license agreements. Licensed under the Elastic License
19
- * 2.0; you may not use this file except in compliance with the Elastic License
20
- * 2.0.
21
- */
22
- const lodash_1 = __importDefault(require("lodash"));
23
- const tms_service_1 = require("./tms_service");
24
- const file_layer_1 = require("./file_layer");
25
- const coerce_1 = __importDefault(require("semver/functions/coerce"));
26
- const valid_1 = __importDefault(require("semver/functions/valid"));
27
- const major_1 = __importDefault(require("semver/functions/major"));
28
- const minor_1 = __importDefault(require("semver/functions/minor"));
29
- const url_1 = require("url");
30
- const utils_1 = require("./utils");
31
- const lru_cache_1 = __importDefault(require("lru-cache"));
32
- const REST_API_REGEX = /\d{4}-\d{2}-\d{2}/;
33
- exports.LATEST_API_URL_PATH = 'latest';
34
- /**
35
- * plugins cannot have upstream dependencies on core/*-kibana.
36
- * Work-around by copy-pasting modifyUrl routine here.
37
- * @param url
38
- * @param block
39
- */
40
- function modifyUrlLocal(url, block) {
41
- const parsed = (0, url_1.parse)(url, true);
42
- // copy over the most specific version of each
43
- // property. By default, the parsed url includes
44
- // several conflicting properties (like path and
45
- // pathname + search, or search and query) and keeping
46
- // track of which property is actually used when they
47
- // are formatted is harder than necessary
48
- const meaningfulParts = {
49
- protocol: parsed.protocol,
50
- slashes: parsed.slashes,
51
- auth: parsed.auth,
52
- hostname: parsed.hostname,
53
- port: parsed.port,
54
- pathname: parsed.pathname,
55
- query: parsed.query || {},
56
- hash: parsed.hash,
57
- };
58
- // the block modifies the meaningfulParts object, or returns a new one
59
- const modifiedParts = block(meaningfulParts) || meaningfulParts;
60
- // format the modified/replaced meaningfulParts back into a url
61
- return (0, url_1.format)({
62
- protocol: modifiedParts.protocol,
63
- slashes: modifiedParts.slashes,
64
- auth: modifiedParts.auth,
65
- hostname: modifiedParts.hostname,
66
- port: modifiedParts.port,
67
- pathname: modifiedParts.pathname,
68
- query: modifiedParts.query,
69
- hash: modifiedParts.hash,
70
- });
71
- }
72
- const extendUrl = (url, props) => modifyUrlLocal(url, (parsed) => lodash_1.default.merge(parsed, props));
73
- /**
74
- * Unescape a url template that was escaped by encodeURI() so leaflet
75
- * will be able to correctly locate the variables in the template
76
- * @param {String} url
77
- * @return {String}
78
- */
79
- const unescapeTemplateVars = (url) => {
80
- const ENCODED_TEMPLATE_VARS_RE = /%7B(\w+?)%7D/g;
81
- return url.replace(ENCODED_TEMPLATE_VARS_RE, (total, varName) => `{${varName}}`);
82
- };
83
- //this is not the default locale from Kibana, but the default locale supported by the Elastic Maps Service
84
- const DEFAULT_LANGUAGE = 'en';
85
- class EMSClient {
86
- constructor(config) {
87
- this.EMS_LOAD_TIMEOUT = 32000;
88
- this._isRestApi = false;
89
- // Remove kbnVersion in 8.0
90
- if ('kbnVersion' in config) {
91
- console.warn('The "kbnVersion" parameter for ems-client is deprecated. Please use "appVersion" instead.');
92
- this._appVersion = config.kbnVersion;
93
- }
94
- else {
95
- this._appVersion = config.appVersion;
96
- }
97
- this._queryParams = {
98
- elastic_tile_service_tos: 'agree',
99
- my_app_name: config.appName || 'kibana',
100
- my_app_version: this._appVersion,
101
- };
102
- this._sanitizer = config.htmlSanitizer ? config.htmlSanitizer : (x) => x;
103
- this._tileApiUrl = config.tileApiUrl;
104
- this._fileApiUrl = config.fileApiUrl;
105
- this._emsVersion = this._getEmsVersion(config.emsVersion);
106
- this._isRestApi = this._emsVersion == config.emsVersion;
107
- this._emsLandingPageUrl = config.landingPageUrl || '';
108
- this._language = config.language || DEFAULT_LANGUAGE;
109
- this._fetchFunction = config.fetchFunction;
110
- this._proxyPath = config.proxyPath || '';
111
- this._cache = new lru_cache_1.default({
112
- max: config.cacheSize || 10,
113
- });
114
- this._invalidateSettings();
115
- }
116
- getDefaultLocale() {
117
- return DEFAULT_LANGUAGE;
118
- }
119
- getLocale() {
120
- return this._language;
121
- }
122
- getValueInLanguage(i18nObject) {
123
- if (!i18nObject) {
124
- return '';
125
- }
126
- return i18nObject[this._language] ? i18nObject[this._language] : i18nObject[DEFAULT_LANGUAGE];
127
- }
128
- /**
129
- * this internal method is overridden by the tests to simulate custom manifest.
130
- */
131
- getManifest(endpointUrl) {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- try {
134
- const url = extendUrl(endpointUrl, { query: this._queryParams });
135
- const response = yield this._fetchWithTimeout(url);
136
- if (!response.ok) {
137
- throw new Error(response.statusText);
138
- }
139
- if (response) {
140
- return (yield response.json());
141
- }
142
- else {
143
- throw new Error('Response not found');
144
- }
145
- }
146
- catch (e) {
147
- if (e instanceof Error) {
148
- throw e;
149
- }
150
- else {
151
- throw new Error('Unknown error');
152
- }
153
- }
154
- });
155
- }
156
- /**
157
- * Add optional query-parameters to all requests
158
- *
159
- * @param additionalQueryParams
160
- */
161
- addQueryParams(additionalQueryParams) {
162
- for (const key in additionalQueryParams) {
163
- if (Object.prototype.hasOwnProperty.call(additionalQueryParams, key)) {
164
- if (additionalQueryParams[key] !== this._queryParams[key]) {
165
- //changes detected.
166
- this._queryParams = lodash_1.default.assign({}, this._queryParams, additionalQueryParams);
167
- this._invalidateSettings();
168
- break;
169
- }
170
- }
171
- }
172
- }
173
- getMainManifest() {
174
- return __awaiter(this, void 0, void 0, function* () {
175
- return yield this._getMainCatalog();
176
- });
177
- }
178
- getDefaultFileManifest() {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- return yield this._getDefaultFileCatalog();
181
- });
182
- }
183
- getDefaultTMSManifest() {
184
- return __awaiter(this, void 0, void 0, function* () {
185
- return yield this._getDefaultTMSCatalog();
186
- });
187
- }
188
- getFileLayers() {
189
- return __awaiter(this, void 0, void 0, function* () {
190
- return yield this._loadFileLayers();
191
- });
192
- }
193
- getTMSServices() {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- return yield this._loadTMSServices();
196
- });
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
- findFileLayerById(id) {
226
- return __awaiter(this, void 0, void 0, function* () {
227
- const fileLayers = yield this.getFileLayers();
228
- for (let i = 0; i < fileLayers.length; i++) {
229
- if (fileLayers[i].hasId(id)) {
230
- return fileLayers[i];
231
- }
232
- }
233
- });
234
- }
235
- findTMSServiceById(id) {
236
- return __awaiter(this, void 0, void 0, function* () {
237
- const tmsServices = yield this.getTMSServices();
238
- for (let i = 0; i < tmsServices.length; i++) {
239
- if (tmsServices[i].hasId(id)) {
240
- return tmsServices[i];
241
- }
242
- }
243
- });
244
- }
245
- _getEmsVersion(version) {
246
- if (version === null || version === void 0 ? void 0 : version.match(REST_API_REGEX)) {
247
- return version;
248
- }
249
- const semverVersion = (0, valid_1.default)((0, coerce_1.default)(version));
250
- if (semverVersion) {
251
- return `v${(0, major_1.default)(semverVersion)}.${(0, minor_1.default)(semverVersion)}`;
252
- }
253
- else {
254
- throw new Error(`Invalid version: ${version}`);
255
- }
256
- }
257
- _fetchWithTimeout(url) {
258
- return new Promise((resolve, reject) => {
259
- const timer = setTimeout(() => reject(new Error(`Request to ${url} timed out`)), this.EMS_LOAD_TIMEOUT);
260
- this._fetchFunction(url).then((response) => {
261
- clearTimeout(timer);
262
- resolve(response);
263
- }, (err) => {
264
- clearTimeout(timer);
265
- reject(err);
266
- });
267
- });
268
- }
269
- _invalidateSettings() {
270
- this._cache.reset();
271
- this._getMainCatalog = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
272
- const services = [];
273
- if (this._tileApiUrl) {
274
- const version = this._isRestApi ? exports.LATEST_API_URL_PATH : this._emsVersion;
275
- services.push({
276
- type: 'tms',
277
- manifest: (0, utils_1.toAbsoluteUrl)(this._tileApiUrl, `${version}/manifest`),
278
- });
279
- }
280
- if (this._fileApiUrl) {
281
- const version = this._isRestApi ? exports.LATEST_API_URL_PATH : this._emsVersion;
282
- services.push({
283
- type: 'file',
284
- manifest: (0, utils_1.toAbsoluteUrl)(this._fileApiUrl, `${version}/manifest`),
285
- });
286
- }
287
- return { services: services };
288
- }));
289
- this._getDefaultTMSCatalog = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
290
- const catalogue = yield this._getMainCatalog();
291
- const firstService = catalogue.services.find((service) => service.type === 'tms');
292
- if (!firstService) {
293
- return { services: [] };
294
- }
295
- const url = this._proxyPath + firstService.manifest;
296
- return yield this.getManifest(url);
297
- }));
298
- this._getDefaultFileCatalog = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
299
- const catalogue = yield this._getMainCatalog();
300
- const firstService = catalogue.services.find((service) => service.type === 'file');
301
- if (!firstService) {
302
- return { layers: [] };
303
- }
304
- const url = this._proxyPath + firstService.manifest;
305
- return yield this.getManifest(url);
306
- }));
307
- //Cache the actual instances of TMSService as these in turn cache sub-manifests for the style-files
308
- this._loadTMSServices = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
309
- const tmsManifest = yield this._getDefaultTMSCatalog();
310
- return tmsManifest.services.map((serviceConfig) => new tms_service_1.TMSService(serviceConfig, this, this._proxyPath));
311
- }));
312
- this._loadFileLayers = lodash_1.default.once(() => __awaiter(this, void 0, void 0, function* () {
313
- const fileManifest = yield this._getDefaultFileCatalog();
314
- return fileManifest.layers.map((layerConfig) => new file_layer_1.FileLayer(layerConfig, this, this._proxyPath));
315
- }));
316
- }
317
- }
318
- exports.EMSClient = EMSClient;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
- * or more contributor license agreements. Licensed under the Elastic License
5
- * 2.0; you may not use this file except in compliance with the Elastic License
6
- * 2.0.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AbstractEmsService = void 0;
10
- const utils_1 = require("./utils");
11
- class AbstractEmsService {
12
- constructor(config, emsClient, proxyPath) {
13
- /**
14
- * Checks if url is absolute. If not, prepend the basePath.
15
- */
16
- this._getAbsoluteUrl = (url) => {
17
- if (/^https?:\/\//.test(url)) {
18
- return url;
19
- }
20
- else {
21
- return (0, utils_1.toAbsoluteUrl)(this.getApiUrl(), url);
22
- }
23
- };
24
- this._config = config;
25
- this._emsClient = emsClient;
26
- this._proxyPath = proxyPath;
27
- }
28
- getAttributions() {
29
- return this._config.attribution.map((attribution) => {
30
- const url = this._emsClient.getValueInLanguage(attribution.url);
31
- const label = this._emsClient.getValueInLanguage(attribution.label);
32
- return {
33
- url: url,
34
- label: label,
35
- };
36
- });
37
- }
38
- getMarkdownAttribution() {
39
- const attributions = this._config.attribution.map((attribution) => {
40
- const url = this._emsClient.getValueInLanguage(attribution.url);
41
- const label = this._emsClient.getValueInLanguage(attribution.label);
42
- return `[${label}](${url})`;
43
- });
44
- return attributions.join('|');
45
- }
46
- }
47
- exports.AbstractEmsService = AbstractEmsService;