@elastic/ems-client 8.4.0 → 8.5.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.
- package/.backportrc.json +5 -17
- package/.buildkite/build.sh +16 -0
- package/.buildkite/pipeline.yml +6 -0
- package/.buildkite/pull-requests.json +30 -0
- package/.nvmrc +1 -0
- package/CHANGELOG.md +7 -0
- package/CONTRIBUTING.md +18 -0
- package/catalog-info.yaml +68 -0
- package/package.json +5 -2
- package/src/ems_client.ts +33 -32
- package/src/index.ts +1 -1
- package/target/ems_client.d.ts +2 -2
- package/target/index.d.ts +1 -1
- package/target/node/ems_client.js +41 -39
- package/target/node/ems_service.js +9 -5
- package/target/node/file_layer.js +10 -5
- package/target/node/index.js +6 -0
- package/target/node/tms_service.js +15 -12
- package/target/node/utils.js +5 -0
- package/target/origin.d.ts +4 -0
- package/target/web/ems_client.js +262 -317
- package/target/web/ems_service.js +3 -4
- package/target/web/file_layer.js +48 -50
- package/target/web/index.js +1 -1
- package/target/web/tms_service.js +380 -412
- package/target/web/utils.js +5 -0
- package/test/ems_client.test.ts +33 -0
- package/.ci/jobs/defaults.yml +0 -67
- package/.ci/jobs/elastic+ems-client+master.yml +0 -18
- package/.ci/jobs/elastic+ems-client+pull-request.yml +0 -19
package/.backportrc.json
CHANGED
|
@@ -2,25 +2,13 @@
|
|
|
2
2
|
"upstream": "elastic/ems-client",
|
|
3
3
|
"branches": [
|
|
4
4
|
{
|
|
5
|
-
"name": "8.
|
|
5
|
+
"name": "8.4",
|
|
6
6
|
"checked": true
|
|
7
7
|
},
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"7.16",
|
|
13
|
-
"7.16",
|
|
14
|
-
"7.15",
|
|
15
|
-
"7.14",
|
|
16
|
-
"7.12",
|
|
17
|
-
"7.11",
|
|
18
|
-
"7.10",
|
|
19
|
-
"7.9",
|
|
20
|
-
"7.8",
|
|
21
|
-
"7.7",
|
|
22
|
-
"7.6",
|
|
23
|
-
"7.2"
|
|
8
|
+
{
|
|
9
|
+
"name": "7.17",
|
|
10
|
+
"checked": true
|
|
11
|
+
}
|
|
24
12
|
],
|
|
25
13
|
"labels": [
|
|
26
14
|
"backport"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
# or more contributor license agreements. Licensed under the Elastic License;
|
|
4
|
+
# you may not use this file except in compliance with the Elastic License.
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
set -eu
|
|
8
|
+
|
|
9
|
+
echo "--- :yarn: Installing dependencies"
|
|
10
|
+
yarn install
|
|
11
|
+
|
|
12
|
+
echo "--- :alembic: Running tests"
|
|
13
|
+
yarn test
|
|
14
|
+
|
|
15
|
+
echo "--- :gear: Building"
|
|
16
|
+
yarn build
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jobs": [
|
|
3
|
+
{
|
|
4
|
+
"repoOwner": "elastic",
|
|
5
|
+
"repoName": "ems-client",
|
|
6
|
+
"enabled": true,
|
|
7
|
+
"pipeline_slug": "ems-client",
|
|
8
|
+
"allow_org_users": true,
|
|
9
|
+
"allowed_repo_permissions": [
|
|
10
|
+
"admin",
|
|
11
|
+
"write"
|
|
12
|
+
],
|
|
13
|
+
"allowed_list": [
|
|
14
|
+
"dependabot"
|
|
15
|
+
],
|
|
16
|
+
"build_on_commit": true,
|
|
17
|
+
"build_on_comment": true,
|
|
18
|
+
"trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:build|test)\\W+(?:this|it))",
|
|
19
|
+
"always_trigger_comment_regex": "^(?:(?:buildkite\\W+)?(?:build|test)\\W+(?:this|it))",
|
|
20
|
+
"skip_ci_labels": [
|
|
21
|
+
"skip-ci"
|
|
22
|
+
],
|
|
23
|
+
"skip_ci_on_only_changed": [
|
|
24
|
+
"\\.md$",
|
|
25
|
+
"^.ci/.+\\.yml$",
|
|
26
|
+
"^\\.buildkite/pull_requests\\.json$"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lts/hydrogen
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
5
5
|
|
|
6
|
+
## [8.5.0] - TBD
|
|
7
|
+
|
|
8
|
+
- Migration from Jenkins to Buildkite for automatic testing #145 #147
|
|
9
|
+
- Detached the releases of EMS Client from the services consumed #185
|
|
10
|
+
- Updated the client to support date based versions #185
|
|
11
|
+
- Update dependencies #159 #165 #173 #176 #181 #184
|
|
12
|
+
|
|
6
13
|
## [8.4.0] - 2023-01-11
|
|
7
14
|
|
|
8
15
|
- Default EMS version is 8.4
|
package/CONTRIBUTING.md
CHANGED
|
@@ -19,3 +19,21 @@ If you have access to make releases, the process is as follows:
|
|
|
19
19
|
1. Update the latest major branch on upstream with `git push upstream <major_branch>`
|
|
20
20
|
1. Build the targets with `yarn build`
|
|
21
21
|
1. Publish to npm with `npm publish --access public`
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Continuous Integration
|
|
25
|
+
|
|
26
|
+
This repository is tracked by Elastic [Buildkite infrastructure](https://buildkite.com/elastic) to ensure the tests suite passes and a build is successfully generated. The pipeline is located at [`.buildkite/pipeline.yml`](.buildkite/pipeline.yml), and defines the execution of the `test` and `build` scripts from `package.json`.
|
|
27
|
+
|
|
28
|
+
Builds are **triggered** on the following conditions:
|
|
29
|
+
|
|
30
|
+
* Any push to `master`
|
|
31
|
+
* Any Pull Request coming from a branch in the `elastic/ems-client` repository
|
|
32
|
+
* It will run automatically on `master` on a weekly basis
|
|
33
|
+
* Comments from Elastic team members on a Pull Request like: `buildkite test this`
|
|
34
|
+
|
|
35
|
+
Builds will be **skipped** on:
|
|
36
|
+
|
|
37
|
+
* Pull Requests from forks from users that don't have write/admin permissions on the upstream repository (`elastic/ems-client`) or are not part of the Elastic GitHub organization.
|
|
38
|
+
* Pull Requests with the `skip-ci` label
|
|
39
|
+
* Pull Requests with all files modified matching any of the regular expressions in `.buildkite/pull-requests.json => skip_ci_on_only_changed`
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
# yaml-language-server: $schema=https://json.schemastore.org/catalog-info.json
|
|
3
|
+
apiVersion: backstage.io/v1alpha1
|
|
4
|
+
kind: Component
|
|
5
|
+
metadata:
|
|
6
|
+
name: ems-client
|
|
7
|
+
description: JavaScript library to interact with the Elastic Maps Service
|
|
8
|
+
|
|
9
|
+
annotations:
|
|
10
|
+
backstage.io/source-location: url:https://github.com/elastic/ems-client/
|
|
11
|
+
github.com/project-slug: elastic/ems-client
|
|
12
|
+
github.com/team-slug: elastic/ems
|
|
13
|
+
buildkite.com/project-slug: elastic/ems-client
|
|
14
|
+
|
|
15
|
+
tags:
|
|
16
|
+
- nodejs
|
|
17
|
+
- ems
|
|
18
|
+
- kibana
|
|
19
|
+
|
|
20
|
+
links:
|
|
21
|
+
- title: Releases (npm)
|
|
22
|
+
url: https://www.npmjs.com/@elastic/ems-client
|
|
23
|
+
- title: Documentation
|
|
24
|
+
url: https://github.com/elastic/ems-client/blob/master/README.md
|
|
25
|
+
- title: EMS License
|
|
26
|
+
url: https://www.elastic.co/elastic-maps-service-terms
|
|
27
|
+
|
|
28
|
+
spec:
|
|
29
|
+
type: library
|
|
30
|
+
owner: group:ems
|
|
31
|
+
lifecycle: production
|
|
32
|
+
---
|
|
33
|
+
# yaml-language-server: $schema=https://gist.githubusercontent.com/elasticmachine/988b80dae436cafea07d9a4a460a011d/raw/e57ee3bed7a6f73077a3f55a38e76e40ec87a7cf/rre.schema.json
|
|
34
|
+
apiVersion: backstage.io/v1alpha1
|
|
35
|
+
kind: Resource
|
|
36
|
+
metadata:
|
|
37
|
+
name: buildkite-pipeline-ems-client
|
|
38
|
+
description: Buildkite Pipeline for ems-client
|
|
39
|
+
links:
|
|
40
|
+
- title: Pipeline
|
|
41
|
+
url: https://buildkite.com/elastic/ems-client
|
|
42
|
+
|
|
43
|
+
spec:
|
|
44
|
+
type: buildkite-pipeline
|
|
45
|
+
owner: group:ems
|
|
46
|
+
system: buildkite
|
|
47
|
+
implementation:
|
|
48
|
+
apiVersion: buildkite.elastic.dev/v1
|
|
49
|
+
kind: Pipeline
|
|
50
|
+
metadata:
|
|
51
|
+
name: EMS Client
|
|
52
|
+
description: Pipeline to run the EMS Client tests suite on
|
|
53
|
+
spec:
|
|
54
|
+
repository: elastic/ems-client
|
|
55
|
+
pipeline_file: ".buildkite/pipeline.yml"
|
|
56
|
+
default_branch: master
|
|
57
|
+
env:
|
|
58
|
+
ELASTIC_PR_COMMENTS_ENABLED: 'true'
|
|
59
|
+
teams: # Who has access to the pipeline.
|
|
60
|
+
ems: {}
|
|
61
|
+
everyone:
|
|
62
|
+
access_level: READ_ONLY
|
|
63
|
+
provider_settings:
|
|
64
|
+
publish_commit_status: true
|
|
65
|
+
schedules:
|
|
66
|
+
Weekly build on master branch:
|
|
67
|
+
cronline: "@weekly"
|
|
68
|
+
message: "Weekly tests and build"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/ems-client",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.0",
|
|
4
4
|
"description": "JavaScript client library for the Elastic Maps Service",
|
|
5
5
|
"main": "target/node/index.js",
|
|
6
6
|
"browser": "target/web/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"chroma-js": "^2.1.0",
|
|
43
43
|
"lodash": "^4.17.15",
|
|
44
44
|
"lru-cache": "^6.0.0",
|
|
45
|
-
"semver": "
|
|
45
|
+
"semver": "7.5.4",
|
|
46
46
|
"topojson-client": "^3.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
@@ -70,5 +70,8 @@
|
|
|
70
70
|
"prettier": "^2.0.5",
|
|
71
71
|
"ts-jest": "^26.2.0",
|
|
72
72
|
"typescript": "4.6.3"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=16 <=18"
|
|
73
76
|
}
|
|
74
77
|
}
|
package/src/ems_client.ts
CHANGED
|
@@ -9,13 +9,19 @@ import { TMSService } from './tms_service';
|
|
|
9
9
|
import { EMSFormatType, FileLayer } from './file_layer';
|
|
10
10
|
import { FeatureCollection } from 'geojson';
|
|
11
11
|
import { Response } from 'node-fetch';
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
import semverCoerce from 'semver/functions/coerce';
|
|
14
|
+
import semverValid from 'semver/functions/valid';
|
|
15
|
+
import semverMajor from 'semver/functions/major';
|
|
16
|
+
import semverMinor from 'semver/functions/minor';
|
|
17
|
+
|
|
13
18
|
import { format as formatUrl, parse as parseUrl, UrlObject } from 'url';
|
|
14
19
|
import { toAbsoluteUrl } from './utils';
|
|
15
20
|
import { ParsedUrlQueryInput } from 'querystring';
|
|
16
21
|
import LRUCache from 'lru-cache';
|
|
17
22
|
|
|
18
|
-
const
|
|
23
|
+
const REST_API_REGEX = /\d{4}-\d{2}-\d{2}/;
|
|
24
|
+
export const LATEST_API_URL_PATH = 'latest';
|
|
19
25
|
|
|
20
26
|
type URLMeaningfulParts = {
|
|
21
27
|
auth?: string | null;
|
|
@@ -205,7 +211,6 @@ export class EMSClient {
|
|
|
205
211
|
private readonly _appVersion: string;
|
|
206
212
|
private readonly _fetchFunction: Function;
|
|
207
213
|
private readonly _sanitizer: Function;
|
|
208
|
-
private readonly _manifestServiceUrl?: string;
|
|
209
214
|
private readonly _fileApiUrl: string;
|
|
210
215
|
private readonly _tileApiUrl: string;
|
|
211
216
|
private readonly _emsVersion: string;
|
|
@@ -213,6 +218,7 @@ export class EMSClient {
|
|
|
213
218
|
private readonly _language: string;
|
|
214
219
|
private readonly _proxyPath: string;
|
|
215
220
|
private readonly _cache: LRUCache<string, FeatureCollection>;
|
|
221
|
+
private readonly _isRestApi: boolean = false;
|
|
216
222
|
|
|
217
223
|
/**
|
|
218
224
|
* these methods are assigned outside the constructor
|
|
@@ -241,10 +247,12 @@ export class EMSClient {
|
|
|
241
247
|
};
|
|
242
248
|
|
|
243
249
|
this._sanitizer = config.htmlSanitizer ? config.htmlSanitizer : (x: string) => x;
|
|
244
|
-
this._manifestServiceUrl = config.manifestServiceUrl;
|
|
245
250
|
this._tileApiUrl = config.tileApiUrl;
|
|
246
251
|
this._fileApiUrl = config.fileApiUrl;
|
|
252
|
+
|
|
247
253
|
this._emsVersion = this._getEmsVersion(config.emsVersion);
|
|
254
|
+
this._isRestApi = this._emsVersion == config.emsVersion;
|
|
255
|
+
|
|
248
256
|
this._emsLandingPageUrl = config.landingPageUrl || '';
|
|
249
257
|
this._language = config.language || DEFAULT_LANGUAGE;
|
|
250
258
|
|
|
@@ -382,10 +390,13 @@ export class EMSClient {
|
|
|
382
390
|
}
|
|
383
391
|
|
|
384
392
|
private _getEmsVersion(version: string | undefined): string {
|
|
385
|
-
|
|
386
|
-
|
|
393
|
+
if (version?.match(REST_API_REGEX)) {
|
|
394
|
+
return version;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const semverVersion = semverValid(semverCoerce(version));
|
|
387
398
|
if (semverVersion) {
|
|
388
|
-
return `v${
|
|
399
|
+
return `v${semverMajor(semverVersion)}.${semverMinor(semverVersion)}`;
|
|
389
400
|
} else {
|
|
390
401
|
throw new Error(`Invalid version: ${version}`);
|
|
391
402
|
}
|
|
@@ -410,35 +421,25 @@ export class EMSClient {
|
|
|
410
421
|
});
|
|
411
422
|
}
|
|
412
423
|
|
|
413
|
-
private async _getManifestWithParams<T>(url: string): Promise<T> {
|
|
414
|
-
const extendedUrl = this.extendUrlWithParams(url);
|
|
415
|
-
return await this.getManifest(extendedUrl);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
424
|
private _invalidateSettings(): void {
|
|
419
425
|
this._cache.reset();
|
|
420
426
|
this._getMainCatalog = _.once(async (): Promise<EmsCatalogManifest> => {
|
|
421
|
-
|
|
422
|
-
if (this.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
services.push({
|
|
436
|
-
type: 'file',
|
|
437
|
-
manifest: toAbsoluteUrl(this._fileApiUrl, `${this._emsVersion}/manifest`),
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
return { services: services };
|
|
427
|
+
const services = [];
|
|
428
|
+
if (this._tileApiUrl) {
|
|
429
|
+
const version = this._isRestApi ? LATEST_API_URL_PATH : this._emsVersion;
|
|
430
|
+
services.push({
|
|
431
|
+
type: 'tms',
|
|
432
|
+
manifest: toAbsoluteUrl(this._tileApiUrl, `${version}/manifest`),
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
if (this._fileApiUrl) {
|
|
436
|
+
const version = this._isRestApi ? LATEST_API_URL_PATH : this._emsVersion;
|
|
437
|
+
services.push({
|
|
438
|
+
type: 'file',
|
|
439
|
+
manifest: toAbsoluteUrl(this._fileApiUrl, `${version}/manifest`),
|
|
440
|
+
});
|
|
441
441
|
}
|
|
442
|
+
return { services: services };
|
|
442
443
|
});
|
|
443
444
|
|
|
444
445
|
this._getDefaultTMSCatalog = _.once(async (): Promise<EmsTmsCatalog> => {
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 2.0.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export { EMSClient, FileLayerField } from './ems_client';
|
|
8
|
+
export { EMSClient, FileLayerField, LATEST_API_URL_PATH } from './ems_client';
|
|
9
9
|
export { FileLayer } from './file_layer';
|
|
10
10
|
export { TMSService, EmsSprite, EmsSpriteSheet } from './tms_service';
|
|
11
11
|
export { blendMode } from './utils';
|
package/target/ems_client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TMSService } from './tms_service';
|
|
2
2
|
import { EMSFormatType, FileLayer } from './file_layer';
|
|
3
3
|
import { FeatureCollection } from 'geojson';
|
|
4
|
+
export declare const LATEST_API_URL_PATH = "latest";
|
|
4
5
|
declare type LocalizedStrings = {
|
|
5
6
|
[key: string]: string;
|
|
6
7
|
};
|
|
@@ -95,7 +96,6 @@ export declare class EMSClient {
|
|
|
95
96
|
private readonly _appVersion;
|
|
96
97
|
private readonly _fetchFunction;
|
|
97
98
|
private readonly _sanitizer;
|
|
98
|
-
private readonly _manifestServiceUrl?;
|
|
99
99
|
private readonly _fileApiUrl;
|
|
100
100
|
private readonly _tileApiUrl;
|
|
101
101
|
private readonly _emsVersion;
|
|
@@ -103,6 +103,7 @@ export declare class EMSClient {
|
|
|
103
103
|
private readonly _language;
|
|
104
104
|
private readonly _proxyPath;
|
|
105
105
|
private readonly _cache;
|
|
106
|
+
private readonly _isRestApi;
|
|
106
107
|
/**
|
|
107
108
|
* these methods are assigned outside the constructor
|
|
108
109
|
*/
|
|
@@ -145,7 +146,6 @@ export declare class EMSClient {
|
|
|
145
146
|
findTMSServiceById(id: string): Promise<TMSService | undefined>;
|
|
146
147
|
private _getEmsVersion;
|
|
147
148
|
private _fetchWithTimeout;
|
|
148
|
-
private _getManifestWithParams;
|
|
149
149
|
private _invalidateSettings;
|
|
150
150
|
}
|
|
151
151
|
export {};
|
package/target/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { EMSClient, FileLayerField } from './ems_client';
|
|
1
|
+
export { EMSClient, FileLayerField, LATEST_API_URL_PATH } from './ems_client';
|
|
2
2
|
export { FileLayer } from './file_layer';
|
|
3
3
|
export { TMSService, EmsSprite, EmsSpriteSheet } from './tms_service';
|
|
4
4
|
export { blendMode } from './utils';
|
|
@@ -3,19 +3,29 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.EMSClient = void 0;
|
|
6
|
+
exports.LATEST_API_URL_PATH = exports.EMSClient = void 0;
|
|
7
7
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
8
|
var _tms_service = require("./tms_service");
|
|
9
9
|
var _file_layer = require("./file_layer");
|
|
10
|
-
var
|
|
10
|
+
var _coerce = _interopRequireDefault(require("semver/functions/coerce"));
|
|
11
|
+
var _valid = _interopRequireDefault(require("semver/functions/valid"));
|
|
12
|
+
var _major = _interopRequireDefault(require("semver/functions/major"));
|
|
13
|
+
var _minor = _interopRequireDefault(require("semver/functions/minor"));
|
|
11
14
|
var _url = require("url");
|
|
12
15
|
var _utils = require("./utils");
|
|
13
16
|
var _lruCache = _interopRequireDefault(require("lru-cache"));
|
|
14
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
18
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
19
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
|
-
|
|
20
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
|
|
21
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
22
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
23
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
24
|
+
* 2.0.
|
|
25
|
+
*/
|
|
26
|
+
const REST_API_REGEX = /\d{4}-\d{2}-\d{2}/;
|
|
27
|
+
const LATEST_API_URL_PATH = 'latest';
|
|
28
|
+
exports.LATEST_API_URL_PATH = LATEST_API_URL_PATH;
|
|
19
29
|
/**
|
|
20
30
|
* plugins cannot have upstream dependencies on core/*-kibana.
|
|
21
31
|
* Work-around by copy-pasting modifyUrl routine here.
|
|
@@ -72,17 +82,12 @@ const unescapeTemplateVars = url => {
|
|
|
72
82
|
//this is not the default locale from Kibana, but the default locale supported by the Elastic Maps Service
|
|
73
83
|
const DEFAULT_LANGUAGE = 'en';
|
|
74
84
|
class EMSClient {
|
|
75
|
-
/**
|
|
76
|
-
* these methods are assigned outside the constructor
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
85
|
constructor(config) {
|
|
80
86
|
_defineProperty(this, "EMS_LOAD_TIMEOUT", 32000);
|
|
81
87
|
_defineProperty(this, "_queryParams", void 0);
|
|
82
88
|
_defineProperty(this, "_appVersion", void 0);
|
|
83
89
|
_defineProperty(this, "_fetchFunction", void 0);
|
|
84
90
|
_defineProperty(this, "_sanitizer", void 0);
|
|
85
|
-
_defineProperty(this, "_manifestServiceUrl", void 0);
|
|
86
91
|
_defineProperty(this, "_fileApiUrl", void 0);
|
|
87
92
|
_defineProperty(this, "_tileApiUrl", void 0);
|
|
88
93
|
_defineProperty(this, "_emsVersion", void 0);
|
|
@@ -90,6 +95,10 @@ class EMSClient {
|
|
|
90
95
|
_defineProperty(this, "_language", void 0);
|
|
91
96
|
_defineProperty(this, "_proxyPath", void 0);
|
|
92
97
|
_defineProperty(this, "_cache", void 0);
|
|
98
|
+
_defineProperty(this, "_isRestApi", false);
|
|
99
|
+
/**
|
|
100
|
+
* these methods are assigned outside the constructor
|
|
101
|
+
*/
|
|
93
102
|
_defineProperty(this, "_getMainCatalog", void 0);
|
|
94
103
|
_defineProperty(this, "_getDefaultTMSCatalog", void 0);
|
|
95
104
|
_defineProperty(this, "_getDefaultFileCatalog", void 0);
|
|
@@ -108,10 +117,10 @@ class EMSClient {
|
|
|
108
117
|
my_app_version: this._appVersion
|
|
109
118
|
};
|
|
110
119
|
this._sanitizer = config.htmlSanitizer ? config.htmlSanitizer : x => x;
|
|
111
|
-
this._manifestServiceUrl = config.manifestServiceUrl;
|
|
112
120
|
this._tileApiUrl = config.tileApiUrl;
|
|
113
121
|
this._fileApiUrl = config.fileApiUrl;
|
|
114
122
|
this._emsVersion = this._getEmsVersion(config.emsVersion);
|
|
123
|
+
this._isRestApi = this._emsVersion == config.emsVersion;
|
|
115
124
|
this._emsLandingPageUrl = config.landingPageUrl || '';
|
|
116
125
|
this._language = config.language || DEFAULT_LANGUAGE;
|
|
117
126
|
this._fetchFunction = config.fetchFunction;
|
|
@@ -229,10 +238,12 @@ class EMSClient {
|
|
|
229
238
|
}
|
|
230
239
|
}
|
|
231
240
|
_getEmsVersion(version) {
|
|
232
|
-
|
|
233
|
-
|
|
241
|
+
if (version?.match(REST_API_REGEX)) {
|
|
242
|
+
return version;
|
|
243
|
+
}
|
|
244
|
+
const semverVersion = (0, _valid.default)((0, _coerce.default)(version));
|
|
234
245
|
if (semverVersion) {
|
|
235
|
-
return `v${
|
|
246
|
+
return `v${(0, _major.default)(semverVersion)}.${(0, _minor.default)(semverVersion)}`;
|
|
236
247
|
} else {
|
|
237
248
|
throw new Error(`Invalid version: ${version}`);
|
|
238
249
|
}
|
|
@@ -249,36 +260,27 @@ class EMSClient {
|
|
|
249
260
|
});
|
|
250
261
|
});
|
|
251
262
|
}
|
|
252
|
-
async _getManifestWithParams(url) {
|
|
253
|
-
const extendedUrl = this.extendUrlWithParams(url);
|
|
254
|
-
return await this.getManifest(extendedUrl);
|
|
255
|
-
}
|
|
256
263
|
_invalidateSettings() {
|
|
257
264
|
this._cache.reset();
|
|
258
265
|
this._getMainCatalog = _lodash.default.once(async () => {
|
|
259
|
-
|
|
260
|
-
if (this.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
services.push({
|
|
274
|
-
type: 'file',
|
|
275
|
-
manifest: (0, _utils.toAbsoluteUrl)(this._fileApiUrl, `${this._emsVersion}/manifest`)
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
return {
|
|
279
|
-
services: services
|
|
280
|
-
};
|
|
266
|
+
const services = [];
|
|
267
|
+
if (this._tileApiUrl) {
|
|
268
|
+
const version = this._isRestApi ? LATEST_API_URL_PATH : this._emsVersion;
|
|
269
|
+
services.push({
|
|
270
|
+
type: 'tms',
|
|
271
|
+
manifest: (0, _utils.toAbsoluteUrl)(this._tileApiUrl, `${version}/manifest`)
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
if (this._fileApiUrl) {
|
|
275
|
+
const version = this._isRestApi ? LATEST_API_URL_PATH : this._emsVersion;
|
|
276
|
+
services.push({
|
|
277
|
+
type: 'file',
|
|
278
|
+
manifest: (0, _utils.toAbsoluteUrl)(this._fileApiUrl, `${version}/manifest`)
|
|
279
|
+
});
|
|
281
280
|
}
|
|
281
|
+
return {
|
|
282
|
+
services: services
|
|
283
|
+
};
|
|
282
284
|
});
|
|
283
285
|
this._getDefaultTMSCatalog = _lodash.default.once(async () => {
|
|
284
286
|
const catalogue = await this._getMainCatalog();
|
|
@@ -7,12 +7,20 @@ exports.AbstractEmsService = void 0;
|
|
|
7
7
|
var _utils = require("./utils");
|
|
8
8
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
9
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
10
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
|
|
11
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
12
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
13
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
14
|
+
* 2.0.
|
|
15
|
+
*/
|
|
11
16
|
class AbstractEmsService {
|
|
12
17
|
constructor(config, emsClient, proxyPath) {
|
|
13
18
|
_defineProperty(this, "_emsClient", void 0);
|
|
14
19
|
_defineProperty(this, "_config", void 0);
|
|
15
20
|
_defineProperty(this, "_proxyPath", void 0);
|
|
21
|
+
/**
|
|
22
|
+
* Checks if url is absolute. If not, prepend the basePath.
|
|
23
|
+
*/
|
|
16
24
|
_defineProperty(this, "_getAbsoluteUrl", url => {
|
|
17
25
|
if (/^https?:\/\//.test(url)) {
|
|
18
26
|
return url;
|
|
@@ -42,9 +50,5 @@ class AbstractEmsService {
|
|
|
42
50
|
});
|
|
43
51
|
return attributions.join('|');
|
|
44
52
|
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Checks if url is absolute. If not, prepend the basePath.
|
|
48
|
-
*/
|
|
49
53
|
}
|
|
50
54
|
exports.AbstractEmsService = AbstractEmsService;
|
|
@@ -12,13 +12,18 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
14
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*
|
|
16
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
17
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
18
|
+
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
19
|
+
* 2.0.
|
|
20
|
+
*/
|
|
21
|
+
let EMSFormatType = /*#__PURE__*/function (EMSFormatType) {
|
|
19
22
|
EMSFormatType["geojson"] = "geojson";
|
|
20
23
|
EMSFormatType["topojson"] = "topojson";
|
|
21
|
-
|
|
24
|
+
return EMSFormatType;
|
|
25
|
+
}({});
|
|
26
|
+
exports.EMSFormatType = EMSFormatType;
|
|
22
27
|
class FileLayer extends _ems_service.AbstractEmsService {
|
|
23
28
|
constructor(config, emsClient, proxyPath) {
|
|
24
29
|
super(config, emsClient, proxyPath);
|
package/target/node/index.js
CHANGED
|
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "FileLayerField", {
|
|
|
33
33
|
return _ems_client.FileLayerField;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "LATEST_API_URL_PATH", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _ems_client.LATEST_API_URL_PATH;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
36
42
|
Object.defineProperty(exports, "TMSService", {
|
|
37
43
|
enumerable: true,
|
|
38
44
|
get: function () {
|