Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add appName and appVersion parameters #18

Merged
merged 2 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Yarn
import { EMSClient } from '@elastic/ems-client';

const emsClient = new EMSClient({
kbnVersion: '7.6.0',
appVersion: '7.6.0',
appName: 'kibana',
tileApiUrl: 'https://tiles.maps.elastic.co',
fileApiUrl: 'https://vector.maps.elastic.co',
emsVersion: '7.6',
Expand Down
11 changes: 9 additions & 2 deletions src/ems_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export class EMSClient {

constructor({
kbnVersion,
appVersion,
appName,
manifestServiceUrl,
tileApiUrl,
fileApiUrl,
Expand All @@ -104,11 +106,16 @@ export class EMSClient {
proxyPath,
}) {

// Remove kbnVersion in 8.0
if (kbnVersion) {
console.warn('The "kbnVersion" parameter for ems-client is deprecated. Please use "appVersion" instead.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx. I guess we'll need corresponding Kibana update then as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx. I guess we'll need corresponding Kibana update then as well?

Yup. This will be part of the changes we need when we bump the ems-client dependency in Kibana and ems-landing-page for 7.7.

appVersion = appVersion || kbnVersion;
}

this._queryParams = {
elastic_tile_service_tos: 'agree',
my_app_name: 'kibana',
my_app_version: kbnVersion,
my_app_name: appName || 'kibana',
my_app_version: appVersion,
};

this._sanitizer = htmlSanitizer ? htmlSanitizer : x => x;
Expand Down
20 changes: 10 additions & 10 deletions test/ems_client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('ems_client', () => {
expect(tiles.length).toBe(3);

const tileService = tiles[0];
expect(await tileService.getUrlTemplate()).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x');
expect(await tileService.getUrlTemplate()).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x');

expect (tileService.getHTMLAttribution()).toBe('<a rel="noreferrer noopener" href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a> | <a rel="noreferrer noopener" href="https://openmaptiles.org">OpenMapTiles</a> | <a rel="noreferrer noopener" href="https://www.maptiler.com">MapTiler</a> | <a rel="noreferrer noopener" href="https://www.elastic.co/elastic-maps-service">Elastic Maps Service</a>');
expect (await tileService.getMinZoom()).toBe(0);
Expand All @@ -57,7 +57,7 @@ describe('ems_client', () => {
expect(tiles.length).toBe(3);

const tileService = tiles[0];
expect(await tileService.getUrlTemplate()).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x');
expect(await tileService.getUrlTemplate()).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x');

expect (tileService.getHTMLAttribution()).toBe('<a rel="noreferrer noopener" href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a> | <a rel="noreferrer noopener" href="https://openmaptiles.org">OpenMapTiles</a> | <a rel="noreferrer noopener" href="https://www.maptiler.com">MapTiler</a> | <a rel="noreferrer noopener" href="https://www.elastic.co/elastic-maps-service">Elastic Maps Service</a>');
expect (await tileService.getMinZoom()).toBe(0);
Expand All @@ -76,22 +76,22 @@ describe('ems_client', () => {

const tilesBefore = await emsClient.getTMSServices();
const urlBefore = await tilesBefore[0].getUrlTemplate();
expect(urlBefore).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x');
expect(urlBefore).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x');

emsClient.addQueryParams({
'foo': 'bar'
});
let tiles = await emsClient.getTMSServices();
let url = await tiles[0].getUrlTemplate();
expect(url).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x&foo=bar');
expect(url).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x&foo=bar');

emsClient.addQueryParams({
'foo': 'schmoo',
'bar': 'foo'
});
tiles = await emsClient.getTMSServices();
url = await tiles[0].getUrlTemplate();
expect(url).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x&foo=schmoo&bar=foo');
expect(url).toBe('https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x&foo=schmoo&bar=foo');


});
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('ems_client', () => {
{ name: 'name', description: 'nom', type: 'property' } ]);

expect(layer.getDefaultFormatType()).toBe('geojson');
expect(layer.getDefaultFormatUrl()).toBe('https://files.foobar/files/world_countries_v1.geo.json?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x&foo=bar');
expect(layer.getDefaultFormatUrl()).toBe('https://files.foobar/files/world_countries_v1.geo.json?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x&foo=bar');


});
Expand Down Expand Up @@ -237,12 +237,12 @@ describe('ems_client', () => {
return EMS_STYLE_BRIGHT_PROXIED;
};
const urlTemplate = await tmsServices[0].getUrlTemplate();
expect(urlTemplate).toBe('http://proxy.com/foobar/tiles/raster/osm_bright/{x}/{y}/{z}.jpg?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x');
expect(urlTemplate).toBe('http://proxy.com/foobar/tiles/raster/osm_bright/{x}/{y}/{z}.jpg?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x');

const fileLayers = await emsClient.getFileLayers();
expect(fileLayers.length).toBe(1);
const fileLayer = fileLayers[0];
expect(fileLayer.getDefaultFormatUrl()).toBe('http://proxy.com/foobar/vector/files/world_countries.json?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x');
expect(fileLayer.getDefaultFormatUrl()).toBe('http://proxy.com/foobar/vector/files/world_countries.json?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x');

});

Expand All @@ -263,7 +263,7 @@ describe('ems_client', () => {
expect(styleSheet.layers.length).toBe(111);
expect(styleSheet.sprite).toBe('https://tiles.foobar/styles/osm-bright/sprite');
expect(styleSheet.sources.openmaptiles.tiles.length).toBe(1);
expect(styleSheet.sources.openmaptiles.tiles[0]).toBe('https://tiles.foobar/data/v3/{z}/{x}/{y}.pbf?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x');
expect(styleSheet.sources.openmaptiles.tiles[0]).toBe('https://tiles.foobar/data/v3/{z}/{x}/{y}.pbf?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x');

});

Expand All @@ -288,7 +288,7 @@ describe('ems_client', () => {
expect(styleSheet.layers.length).toBe(111);
expect(styleSheet.sprite).toBe('http://proxy.com/foobar/tiles/styles/osm-bright/sprite');
expect(styleSheet.sources.openmaptiles.tiles.length).toBe(1);
expect(styleSheet.sources.openmaptiles.tiles[0]).toBe('http://proxy.com/foobar/tiles/data/v3/{z}/{x}/{y}.pbf?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x');
expect(styleSheet.sources.openmaptiles.tiles[0]).toBe('http://proxy.com/foobar/tiles/data/v3/{z}/{x}/{y}.pbf?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x');

});

Expand Down
3 changes: 2 additions & 1 deletion test/ems_client_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export function getEMSClient(options = {}) {

const emsClient = new EMSClient({
language: 'en',
kbnVersion: '7.x.x',
appVersion: '7.x.x',
appName: 'tester',
htmlSanitizer: x => x,
landingPageUrl: 'https://landing.foobar',
...options
Expand Down