@nextgis/ngw-connector 1.18.21 → 1.19.6

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/lib/index.d.ts CHANGED
@@ -149,6 +149,12 @@ export declare interface GetRequestItemsResponseMap extends RequestItemKeys {
149
149
  'feature_layer.feature.count': FeatureLayerCount;
150
150
  'pyramid.company_logo': string;
151
151
  'spatial_ref_sys.collection': SrsItem[];
152
+ 'render.legend_symbols': RenderLegendSymbol[];
153
+ }
154
+
155
+ declare interface Icon {
156
+ format: string;
157
+ data: string;
152
158
  }
153
159
 
154
160
  export declare interface IdOnly {
@@ -187,6 +193,7 @@ declare class NgwConnector {
187
193
  emitter: EventEmitter;
188
194
  user?: UserInfo;
189
195
  resources: ResourcesControl;
196
+ private client;
190
197
  private routeStr;
191
198
  private activeRequests;
192
199
  private requestTransform?;
@@ -471,6 +478,11 @@ export declare interface PyramidSettingsPyramidCompanyLogo {
471
478
  enabled: boolean;
472
479
  }
473
480
 
481
+ export declare interface RenderLegendSymbol {
482
+ display_name: string;
483
+ icon: Icon;
484
+ }
485
+
474
486
  export declare interface RequestHeaders {
475
487
  [header: string]: string | undefined;
476
488
  Authorization?: string;
@@ -1,15 +1,71 @@
1
- /** Bundle of @nextgis/ngw-connector; version: 1.18.21; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-connector; version: 1.19.6; author: NextGIS */
2
2
  'use strict';
3
3
 
4
4
  var events = require('events');
5
+ var Cache = require('@nextgis/cache');
5
6
  var CancelablePromise = require('@nextgis/cancelable-promise');
6
7
  var utils = require('@nextgis/utils');
7
- var Cache = require('@nextgis/cache');
8
8
 
9
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
10
10
 
11
- var CancelablePromise__default = /*#__PURE__*/_interopDefaultLegacy(CancelablePromise);
12
11
  var Cache__default = /*#__PURE__*/_interopDefaultLegacy(Cache);
12
+ var CancelablePromise__default = /*#__PURE__*/_interopDefaultLegacy(CancelablePromise);
13
+
14
+ var pkg = {
15
+ name: "@nextgis/ngw-connector",
16
+ version: "1.19.6",
17
+ _priority: 12,
18
+ description: "A lightweight HTTP client optimized for use with NextGIS Web API",
19
+ main: "index.js",
20
+ module: "lib/ngw-connector.esm-bundler.js",
21
+ unpkg: "lib/ngw-connector.global.prod.js",
22
+ jsdelivr: "lib/ngw-connector.global.prod.js",
23
+ types: "lib/index.d.ts",
24
+ dependencies: {
25
+ "@nextgis/cache": "^1.19.0",
26
+ "@nextgis/cancelable-promise": "^1.19.0",
27
+ "@nextgis/utils": "^1.19.0",
28
+ "@types/events": "^3.0.0",
29
+ events: "^3.3.0",
30
+ "form-data": "^4.0.0"
31
+ },
32
+ devDependencies: {
33
+ "@nextgis/build-tools": "^1.19.0"
34
+ },
35
+ scripts: {
36
+ clean: "rimraf ./lib",
37
+ dev: "node ../build-tools/lib/build.js",
38
+ prod: "npm run dev -- --release",
39
+ lint: "eslint ./src/**/*.ts --fix --c ../../.eslintrc",
40
+ watch: "npm run dev -- --watch",
41
+ "gen:types": "node ./scripts/generator"
42
+ },
43
+ buildOptions: {
44
+ name: "NgwConnector",
45
+ formats: [
46
+ "esm-bundler",
47
+ "esm-browser",
48
+ "cjs",
49
+ "global"
50
+ ]
51
+ },
52
+ keywords: [
53
+ "NextGIS",
54
+ "MAP"
55
+ ],
56
+ author: "NextGIS",
57
+ files: [
58
+ "index.js",
59
+ "lib"
60
+ ],
61
+ license: "MIT",
62
+ homepage: "https://github.com/nextgis/nextgis_frontend/tree/master/packages/ngw-connector#readme",
63
+ repository: {
64
+ type: "git",
65
+ url: "git://github.com/nextgis/nextgis_frontend.git"
66
+ },
67
+ gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
68
+ };
13
69
 
14
70
  /**
15
71
  * Thrown when...
@@ -23,219 +79,6 @@ class NgwError extends Error {
23
79
  }
24
80
  }
25
81
 
26
- function isError(error) {
27
- if (utils.isObject(error)) {
28
- return error.status_code && error.exception && error.title;
29
- }
30
- return false;
31
- }
32
-
33
- function isObject(val) {
34
- return Object.prototype.toString.call(val) === '[object Object]';
35
- }
36
-
37
- let loadData;
38
- // @ts-ignore
39
- {
40
- const url = require('url');
41
- const http = require('http');
42
- const https = require('https');
43
- const FormData = require('form-data');
44
- const adapterFor = (inputUrl) => {
45
- const adapters = {
46
- 'http:': http,
47
- 'https:': https,
48
- };
49
- const protocol = url.parse(inputUrl).protocol || 'https:';
50
- return adapters[protocol];
51
- };
52
- loadData = (url, callback, options = {}, error, onCancel) => {
53
- const { file, headers, method, data, responseType } = options;
54
- const request = new Promise((resolve, reject) => {
55
- const adapter = adapterFor(url);
56
- if (adapter) {
57
- const requestOpt = {
58
- headers: headers || {},
59
- method,
60
- };
61
- const body = typeof data === 'string' ? data : JSON.stringify(data);
62
- // https://stackoverflow.com/questions/35589109/node-http-delete-request-no-longer-works-after-upgrading-from-0-10-40
63
- let form;
64
- let uploadedFile = file;
65
- if (file) {
66
- const fileMeta = {};
67
- if (isObject(file) &&
68
- 'file' in file &&
69
- ('filename' in file || 'name' in file)) {
70
- const { file: file_, name, ...fileMeta_ } = file;
71
- if (name && !fileMeta_.filename) {
72
- fileMeta_.filename = name;
73
- }
74
- Object.assign(fileMeta, fileMeta_);
75
- uploadedFile = file_;
76
- }
77
- form = new FormData();
78
- form.append('file', uploadedFile, fileMeta);
79
- if (data) {
80
- for (const d in data) {
81
- form.append(d, data[d]);
82
- }
83
- }
84
- Object.assign(requestOpt.headers, {
85
- // 'content-length': form.getLengthSync(),
86
- ...form.getHeaders(),
87
- });
88
- }
89
- if (body !== undefined) {
90
- Object.assign(requestOpt.headers, {
91
- 'content-type': 'application/json',
92
- 'content-length': Buffer.byteLength(body),
93
- });
94
- }
95
- const req = adapter.request(url, requestOpt, (resp) => {
96
- let data = '';
97
- resp.on('data', (chunk) => {
98
- data += chunk;
99
- });
100
- resp.on('end', () => {
101
- if (data) {
102
- if (responseType === 'blob') {
103
- resolve(data);
104
- }
105
- else {
106
- let json;
107
- try {
108
- json = JSON.parse(data);
109
- if (json && json.status_code && json.status_code) {
110
- reject(json.message);
111
- }
112
- }
113
- catch (er) {
114
- reject(er);
115
- }
116
- if (json !== undefined) {
117
- if (isError(json)) {
118
- reject('extractError(json)');
119
- }
120
- else {
121
- resolve(json);
122
- }
123
- }
124
- }
125
- }
126
- reject('no data');
127
- });
128
- });
129
- if (form) {
130
- form.pipe(req);
131
- }
132
- req.on('error', (err) => {
133
- reject(err);
134
- });
135
- if (body) {
136
- req.write(body);
137
- }
138
- onCancel(() => {
139
- req.abort();
140
- });
141
- req.end();
142
- }
143
- else {
144
- throw new Error(`Given URL '${url}' is not correct`);
145
- }
146
- });
147
- return request
148
- .then((data) => {
149
- if (callback) {
150
- callback(data);
151
- }
152
- return data;
153
- })
154
- .catch((er) => {
155
- if (error) {
156
- error(er);
157
- }
158
- else {
159
- throw new Error(er);
160
- }
161
- });
162
- };
163
- }
164
-
165
- // https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
166
- const templateRe = /\{ *([\w_-]+) *\}/g;
167
- function template(str, data) {
168
- return str.replace(templateRe, (s, key) => {
169
- let value = data[key];
170
- if (value === undefined) {
171
- throw new Error('No value provided for letiable ' + s);
172
- }
173
- else if (typeof value === 'function') {
174
- value = value(data);
175
- }
176
- return value;
177
- });
178
- }
179
-
180
- function apiRequest(opt) {
181
- const params = opt.params;
182
- return new CancelablePromise__default((resolve, reject) => {
183
- opt.connector
184
- .connect()
185
- .then((apiItems) => {
186
- let apiItem = apiItems && apiItems[opt.name];
187
- if (apiItem) {
188
- apiItem = [...apiItem];
189
- let url = apiItem.shift();
190
- if (apiItem.length) {
191
- const replaceParams = {};
192
- for (let fry = 0; fry < apiItem.length; fry++) {
193
- const arg = apiItem[fry];
194
- replaceParams[fry] = '{' + arg + '}';
195
- if (params[arg] === undefined) {
196
- throw new Error('`' + arg + '`' + ' url api argument is not specified');
197
- }
198
- }
199
- if (url) {
200
- url = template(url, replaceParams);
201
- }
202
- }
203
- // Transfer part of the parameters from `params` to the URL string
204
- if (params) {
205
- const paramArray = [];
206
- const paramList = params.paramList;
207
- if (Array.isArray(paramList)) {
208
- delete params.paramList;
209
- paramList.forEach((x) => {
210
- paramArray.push(`${x[0]}=${x[1]}`);
211
- });
212
- }
213
- for (const p in params) {
214
- if (apiItem.indexOf(p) === -1) {
215
- paramArray.push(`${p}=${params[p]}`);
216
- }
217
- }
218
- if (paramArray.length) {
219
- url = url + '?' + paramArray.join('&');
220
- }
221
- }
222
- if (url) {
223
- resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
224
- }
225
- else {
226
- reject(new Error('request url is not set'));
227
- }
228
- }
229
- else {
230
- resolve(undefined);
231
- }
232
- })
233
- .catch((er) => {
234
- reject(er);
235
- });
236
- });
237
- }
238
-
239
82
  /**
240
83
  * Thrown when ...
241
84
  */
@@ -248,42 +91,12 @@ class ResourceNotFoundError extends NgwError {
248
91
  }
249
92
  }
250
93
 
251
- /**
252
- * Thrown when ...
253
- */
254
- class InsufficientPermissionsError extends NgwError {
255
- constructor(obj) {
256
- super(obj);
257
- this.name = 'InsufficientPermissionsError';
258
- this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
259
- Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
260
- }
94
+ function isObject(val) {
95
+ return Object.prototype.toString.call(val) === '[object Object]';
261
96
  }
262
97
 
263
- const CONNECTORS = [];
264
- function addConnector(connector) {
265
- CONNECTORS.push(connector);
266
- }
267
- function findConnector(options) {
268
- return CONNECTORS.find((x) => {
269
- if (x.options.baseUrl === options.baseUrl) {
270
- if (options.auth) {
271
- if (x.options.auth) {
272
- return utils.objectDeepEqual(x.options.auth, options.auth);
273
- }
274
- }
275
- else {
276
- // if auth not in find options; use first connector with same url
277
- return true;
278
- }
279
- }
280
- });
281
- }
282
- function removeConnector(connector) {
283
- const index = CONNECTORS.indexOf(connector);
284
- if (index !== -1) {
285
- CONNECTORS.splice(index, 1);
286
- }
98
+ function resourceCompare(res1, res2) {
99
+ return utils.objectDeepEqual(res1, res2);
287
100
  }
288
101
 
289
102
  const exclude = ['description'];
@@ -319,10 +132,6 @@ function resourceToQuery(resource, prefix = '') {
319
132
  return query;
320
133
  }
321
134
 
322
- function resourceCompare(res1, res2) {
323
- return utils.objectDeepEqual(res1, res2);
324
- }
325
-
326
135
  class ResourcesControl {
327
136
  constructor(connector) {
328
137
  this.connector = connector;
@@ -563,12 +372,260 @@ class ResourcesControl {
563
372
  }
564
373
  }
565
374
 
375
+ const CONNECTORS = [];
376
+ function addConnector(connector) {
377
+ CONNECTORS.push(connector);
378
+ }
379
+ function findConnector(options) {
380
+ return CONNECTORS.find((x) => {
381
+ if (x.options.baseUrl === options.baseUrl) {
382
+ if (options.auth) {
383
+ if (x.options.auth) {
384
+ return utils.objectDeepEqual(x.options.auth, options.auth);
385
+ }
386
+ }
387
+ else {
388
+ // if auth not in find options; use first connector with same url
389
+ return true;
390
+ }
391
+ }
392
+ });
393
+ }
394
+ function removeConnector(connector) {
395
+ const index = CONNECTORS.indexOf(connector);
396
+ if (index !== -1) {
397
+ CONNECTORS.splice(index, 1);
398
+ }
399
+ }
400
+
401
+ /**
402
+ * Thrown when ...
403
+ */
404
+ class InsufficientPermissionsError extends NgwError {
405
+ constructor(obj) {
406
+ super(obj);
407
+ this.name = 'InsufficientPermissionsError';
408
+ this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
409
+ Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
410
+ }
411
+ }
412
+
413
+ // https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
414
+ const templateRe = /\{ *([\w_-]+) *\}/g;
415
+ function template(str, data) {
416
+ return str.replace(templateRe, (s, key) => {
417
+ let value = data[key];
418
+ if (value === undefined) {
419
+ throw new Error('No value provided for letiable ' + s);
420
+ }
421
+ else if (typeof value === 'function') {
422
+ value = value(data);
423
+ }
424
+ return value;
425
+ });
426
+ }
427
+
428
+ function apiRequest(opt) {
429
+ const params = opt.params;
430
+ return new CancelablePromise__default((resolve, reject) => {
431
+ opt.connector
432
+ .connect()
433
+ .then((apiItems) => {
434
+ let apiItem = apiItems && apiItems[opt.name];
435
+ if (apiItem) {
436
+ apiItem = [...apiItem];
437
+ let url = apiItem.shift();
438
+ if (apiItem.length) {
439
+ const replaceParams = {};
440
+ for (let fry = 0; fry < apiItem.length; fry++) {
441
+ const arg = apiItem[fry];
442
+ replaceParams[fry] = '{' + arg + '}';
443
+ if (params[arg] === undefined) {
444
+ throw new Error('`' + arg + '`' + ' url api argument is not specified');
445
+ }
446
+ }
447
+ if (url) {
448
+ url = template(url, replaceParams);
449
+ }
450
+ }
451
+ // Transfer part of the parameters from `params` to the URL string
452
+ if (params) {
453
+ const paramArray = [];
454
+ const paramList = params.paramList;
455
+ if (Array.isArray(paramList)) {
456
+ delete params.paramList;
457
+ paramList.forEach((x) => {
458
+ paramArray.push(`${x[0]}=${x[1]}`);
459
+ });
460
+ }
461
+ for (const p in params) {
462
+ if (apiItem.indexOf(p) === -1) {
463
+ paramArray.push(`${p}=${params[p]}`);
464
+ }
465
+ }
466
+ if (paramArray.length) {
467
+ url = url + '?' + paramArray.join('&');
468
+ }
469
+ }
470
+ if (url) {
471
+ resolve(opt.connector.makeQuery(url, params, opt.requestOptions));
472
+ }
473
+ else {
474
+ reject(new Error('request url is not set'));
475
+ }
476
+ }
477
+ else {
478
+ resolve(undefined);
479
+ }
480
+ })
481
+ .catch((er) => {
482
+ reject(er);
483
+ });
484
+ });
485
+ }
486
+
487
+ function isError(error) {
488
+ if (utils.isObject(error)) {
489
+ return error.status_code && error.exception && error.title;
490
+ }
491
+ return false;
492
+ }
493
+
494
+ let loadData;
495
+ // @ts-ignore
496
+ {
497
+ const url = require('url');
498
+ const http = require('http');
499
+ const https = require('https');
500
+ const FormData = require('form-data');
501
+ const adapterFor = (inputUrl) => {
502
+ const adapters = {
503
+ 'http:': http,
504
+ 'https:': https,
505
+ };
506
+ const protocol = url.parse(inputUrl).protocol || 'https:';
507
+ return adapters[protocol];
508
+ };
509
+ loadData = (url, callback, options = {}, error, onCancel) => {
510
+ const { file, headers, method, data, responseType } = options;
511
+ const request = new Promise((resolve, reject) => {
512
+ const adapter = adapterFor(url);
513
+ if (adapter) {
514
+ const requestOpt = {
515
+ headers: headers || {},
516
+ method,
517
+ };
518
+ const body = typeof data === 'string' ? data : JSON.stringify(data);
519
+ // https://stackoverflow.com/questions/35589109/node-http-delete-request-no-longer-works-after-upgrading-from-0-10-40
520
+ let form;
521
+ let uploadedFile = file;
522
+ if (file) {
523
+ const fileMeta = {};
524
+ if (isObject(file) &&
525
+ 'file' in file &&
526
+ ('filename' in file || 'name' in file)) {
527
+ const { file: file_, name, ...fileMeta_ } = file;
528
+ if (name && !fileMeta_.filename) {
529
+ fileMeta_.filename = name;
530
+ }
531
+ Object.assign(fileMeta, fileMeta_);
532
+ uploadedFile = file_;
533
+ }
534
+ form = new FormData();
535
+ form.append('file', uploadedFile, fileMeta);
536
+ if (data) {
537
+ for (const d in data) {
538
+ form.append(d, data[d]);
539
+ }
540
+ }
541
+ Object.assign(requestOpt.headers, {
542
+ // 'content-length': form.getLengthSync(),
543
+ ...form.getHeaders(),
544
+ });
545
+ }
546
+ if (body !== undefined) {
547
+ Object.assign(requestOpt.headers, {
548
+ 'content-type': 'application/json',
549
+ 'content-length': Buffer.byteLength(body),
550
+ });
551
+ }
552
+ const req = adapter.request(url, requestOpt, (resp) => {
553
+ let data = '';
554
+ resp.on('data', (chunk) => {
555
+ data += chunk;
556
+ });
557
+ resp.on('end', () => {
558
+ if (data) {
559
+ if (responseType === 'blob') {
560
+ resolve(data);
561
+ }
562
+ else {
563
+ let json;
564
+ try {
565
+ json = JSON.parse(data);
566
+ if (json && json.status_code && json.status_code) {
567
+ reject(json.message);
568
+ }
569
+ }
570
+ catch (er) {
571
+ reject(er);
572
+ }
573
+ if (json !== undefined) {
574
+ if (isError(json)) {
575
+ reject('extractError(json)');
576
+ }
577
+ else {
578
+ resolve(json);
579
+ }
580
+ }
581
+ }
582
+ }
583
+ reject('no data');
584
+ });
585
+ });
586
+ if (form) {
587
+ form.pipe(req);
588
+ }
589
+ req.on('error', (err) => {
590
+ reject(err);
591
+ });
592
+ if (body) {
593
+ req.write(body);
594
+ }
595
+ onCancel(() => {
596
+ req.abort();
597
+ });
598
+ req.end();
599
+ }
600
+ else {
601
+ throw new Error(`Given URL '${url}' is not correct`);
602
+ }
603
+ });
604
+ return request
605
+ .then((data) => {
606
+ if (callback) {
607
+ callback(data);
608
+ }
609
+ return data;
610
+ })
611
+ .catch((er) => {
612
+ if (error) {
613
+ error(er);
614
+ }
615
+ else {
616
+ throw new Error(er);
617
+ }
618
+ });
619
+ };
620
+ }
621
+
566
622
  let ID = 0;
567
623
  class NgwConnector$1 {
568
624
  constructor(options) {
569
625
  this.options = options;
570
626
  this.id = ID++;
571
627
  this.emitter = new events.EventEmitter();
628
+ this.client = `NextGIS-NGW-Connector/${pkg.version}`;
572
629
  this.routeStr = '/api/component/pyramid/route';
573
630
  this.activeRequests = [];
574
631
  const exist = findConnector(options);
@@ -620,7 +677,8 @@ class NgwConnector$1 {
620
677
  const auth = this.options.auth;
621
678
  const makeConnect = () => new CancelablePromise__default((resolve, reject) => {
622
679
  const makeQuery = () => {
623
- return this.makeQuery(this.routeStr, {}, {})
680
+ const routeUrl = `${this.routeStr}?client=${this.client}`;
681
+ return this.makeQuery(routeUrl.toString(), {}, {})
624
682
  .then((route) => {
625
683
  resolve(route);
626
684
  })