@elastic/ems-client 8.3.3 → 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 CHANGED
@@ -2,25 +2,13 @@
2
2
  "upstream": "elastic/ems-client",
3
3
  "branches": [
4
4
  {
5
- "name": "8.3",
5
+ "name": "8.4",
6
6
  "checked": true
7
7
  },
8
- "8.2",
9
- "8.1",
10
- "8.0",
11
- "7.17",
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,6 @@
1
+ agents:
2
+ image: "docker.elastic.co/ci-agent-images/ems/buildkite-agent-node18:0.1"
3
+
4
+ steps:
5
+ - label: ":hammer_and_wrench: Test and build"
6
+ command: ".buildkite/build.sh"
@@ -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,19 @@ 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
+
13
+ ## [8.4.0] - 2023-01-11
14
+
15
+ - Default EMS version is 8.4
16
+ - Add types to colorOperationDefaults #123
17
+ - Update dependencies #131 #133 #134 #138
18
+
6
19
  ## [8.3.3] - 2022-05-24
7
20
 
8
21
  - Make percentage an optional parameter #117
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.3",
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",
@@ -35,14 +35,14 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@types/geojson": "^7946.0.7",
38
+ "@types/geojson": "^7946.0.10",
39
39
  "@types/lru-cache": "^5.1.0",
40
- "@types/topojson-client": "^3.0.0",
40
+ "@types/topojson-client": "^3.1.1",
41
41
  "@types/topojson-specification": "^1.0.1",
42
42
  "chroma-js": "^2.1.0",
43
43
  "lodash": "^4.17.15",
44
44
  "lru-cache": "^6.0.0",
45
- "semver": "^7.3.2",
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
@@ -4,19 +4,24 @@
4
4
  * 2.0; you may not use this file except in compliance with the Elastic License
5
5
  * 2.0.
6
6
  */
7
-
8
7
  import _ from 'lodash';
9
8
  import { TMSService } from './tms_service';
10
9
  import { EMSFormatType, FileLayer } from './file_layer';
11
10
  import { FeatureCollection } from 'geojson';
12
11
  import { Response } from 'node-fetch';
13
- import semver from 'semver';
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
+
14
18
  import { format as formatUrl, parse as parseUrl, UrlObject } from 'url';
15
19
  import { toAbsoluteUrl } from './utils';
16
20
  import { ParsedUrlQueryInput } from 'querystring';
17
21
  import LRUCache from 'lru-cache';
18
22
 
19
- const DEFAULT_EMS_VERSION = '8.3';
23
+ const REST_API_REGEX = /\d{4}-\d{2}-\d{2}/;
24
+ export const LATEST_API_URL_PATH = 'latest';
20
25
 
21
26
  type URLMeaningfulParts = {
22
27
  auth?: string | null;
@@ -206,7 +211,6 @@ export class EMSClient {
206
211
  private readonly _appVersion: string;
207
212
  private readonly _fetchFunction: Function;
208
213
  private readonly _sanitizer: Function;
209
- private readonly _manifestServiceUrl?: string;
210
214
  private readonly _fileApiUrl: string;
211
215
  private readonly _tileApiUrl: string;
212
216
  private readonly _emsVersion: string;
@@ -214,6 +218,7 @@ export class EMSClient {
214
218
  private readonly _language: string;
215
219
  private readonly _proxyPath: string;
216
220
  private readonly _cache: LRUCache<string, FeatureCollection>;
221
+ private readonly _isRestApi: boolean = false;
217
222
 
218
223
  /**
219
224
  * these methods are assigned outside the constructor
@@ -242,10 +247,12 @@ export class EMSClient {
242
247
  };
243
248
 
244
249
  this._sanitizer = config.htmlSanitizer ? config.htmlSanitizer : (x: string) => x;
245
- this._manifestServiceUrl = config.manifestServiceUrl;
246
250
  this._tileApiUrl = config.tileApiUrl;
247
251
  this._fileApiUrl = config.fileApiUrl;
252
+
248
253
  this._emsVersion = this._getEmsVersion(config.emsVersion);
254
+ this._isRestApi = this._emsVersion == config.emsVersion;
255
+
249
256
  this._emsLandingPageUrl = config.landingPageUrl || '';
250
257
  this._language = config.language || DEFAULT_LANGUAGE;
251
258
 
@@ -383,10 +390,13 @@ export class EMSClient {
383
390
  }
384
391
 
385
392
  private _getEmsVersion(version: string | undefined): string {
386
- const userVersion = semver.valid(semver.coerce(version));
387
- const semverVersion = userVersion ? userVersion : semver.coerce(DEFAULT_EMS_VERSION);
393
+ if (version?.match(REST_API_REGEX)) {
394
+ return version;
395
+ }
396
+
397
+ const semverVersion = semverValid(semverCoerce(version));
388
398
  if (semverVersion) {
389
- return `v${semver.major(semverVersion)}.${semver.minor(semverVersion)}`;
399
+ return `v${semverMajor(semverVersion)}.${semverMinor(semverVersion)}`;
390
400
  } else {
391
401
  throw new Error(`Invalid version: ${version}`);
392
402
  }
@@ -411,35 +421,25 @@ export class EMSClient {
411
421
  });
412
422
  }
413
423
 
414
- private async _getManifestWithParams<T>(url: string): Promise<T> {
415
- const extendedUrl = this.extendUrlWithParams(url);
416
- return await this.getManifest(extendedUrl);
417
- }
418
-
419
424
  private _invalidateSettings(): void {
420
425
  this._cache.reset();
421
426
  this._getMainCatalog = _.once(async (): Promise<EmsCatalogManifest> => {
422
- // Preserve manifestServiceUrl parameter for backwards compatibility with EMS v7.2
423
- if (this._manifestServiceUrl) {
424
- console.warn(`The "manifestServiceUrl" parameter is deprecated in v7.6.0.
425
- Consider using "tileApiUrl" and "fileApiUrl" instead.`);
426
- return await this._getManifestWithParams(this._manifestServiceUrl);
427
- } else {
428
- const services = [];
429
- if (this._tileApiUrl) {
430
- services.push({
431
- type: 'tms',
432
- manifest: toAbsoluteUrl(this._tileApiUrl, `${this._emsVersion}/manifest`),
433
- });
434
- }
435
- if (this._fileApiUrl) {
436
- services.push({
437
- type: 'file',
438
- manifest: toAbsoluteUrl(this._fileApiUrl, `${this._emsVersion}/manifest`),
439
- });
440
- }
441
- 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
+ });
442
441
  }
442
+ return { services: services };
443
443
  });
444
444
 
445
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';
@@ -124,7 +124,11 @@ export class TMSService extends AbstractEmsService {
124
124
  /*
125
125
  Suggested default operations for the different EMS styles
126
126
  */
127
- public static colorOperationDefaults = [
127
+ public static colorOperationDefaults: {
128
+ style: string;
129
+ operation: blendMode;
130
+ percentage: number;
131
+ }[] = [
128
132
  { style: 'road_map', operation: 'mix', percentage: 0.25 },
129
133
  { style: 'road_map_desaturated', operation: 'screen', percentage: 0.25 },
130
134
  { style: 'dark_map', operation: 'dodge', percentage: 0.25 },
@@ -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';