@itwin/core-frontend 3.0.0-dev.180 → 3.0.0-dev.184
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/CHANGELOG.md +89 -1
- package/lib/cjs/ApproximateTerrainHeights.d.ts.map +1 -1
- package/lib/cjs/ApproximateTerrainHeights.js +6 -2
- package/lib/cjs/ApproximateTerrainHeights.js.map +1 -1
- package/lib/cjs/BackgroundMapGeometry.d.ts +1 -1
- package/lib/cjs/BackgroundMapGeometry.d.ts.map +1 -1
- package/lib/cjs/BackgroundMapGeometry.js +2 -2
- package/lib/cjs/BackgroundMapGeometry.js.map +1 -1
- package/lib/cjs/BingLocation.js +2 -2
- package/lib/cjs/BingLocation.js.map +1 -1
- package/lib/cjs/DisplayStyleState.d.ts +9 -3
- package/lib/cjs/DisplayStyleState.d.ts.map +1 -1
- package/lib/cjs/DisplayStyleState.js +66 -41
- package/lib/cjs/DisplayStyleState.js.map +1 -1
- package/lib/cjs/FrontendLoggerCategory.d.ts +2 -8
- package/lib/cjs/FrontendLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/FrontendLoggerCategory.js +2 -8
- package/lib/cjs/FrontendLoggerCategory.js.map +1 -1
- package/lib/cjs/NativeApp.d.ts +1 -1
- package/lib/cjs/NativeApp.d.ts.map +1 -1
- package/lib/cjs/NativeApp.js +3 -3
- package/lib/cjs/NativeApp.js.map +1 -1
- package/lib/cjs/NotificationManager.d.ts +3 -1
- package/lib/cjs/NotificationManager.d.ts.map +1 -1
- package/lib/cjs/NotificationManager.js +2 -0
- package/lib/cjs/NotificationManager.js.map +1 -1
- package/lib/cjs/RealityDataSource.js +11 -6
- package/lib/cjs/RealityDataSource.js.map +1 -1
- package/lib/cjs/ViewContext.js.map +1 -1
- package/lib/cjs/ViewCreator2d.js +1 -1
- package/lib/cjs/ViewCreator2d.js.map +1 -1
- package/lib/cjs/ViewCreator3d.d.ts +1 -1
- package/lib/cjs/ViewCreator3d.d.ts.map +1 -1
- package/lib/cjs/ViewCreator3d.js +2 -2
- package/lib/cjs/ViewCreator3d.js.map +1 -1
- package/lib/cjs/ViewingSpace.js +1 -1
- package/lib/cjs/ViewingSpace.js.map +1 -1
- package/lib/cjs/core-frontend.d.ts +4 -0
- package/lib/cjs/core-frontend.d.ts.map +1 -1
- package/lib/cjs/core-frontend.js +4 -0
- package/lib/cjs/core-frontend.js.map +1 -1
- package/lib/cjs/render/GraphicBuilder.d.ts +6 -0
- package/lib/cjs/render/GraphicBuilder.d.ts.map +1 -1
- package/lib/cjs/render/GraphicBuilder.js.map +1 -1
- package/lib/cjs/render/primitives/geometry/GeometryAccumulator.d.ts +2 -0
- package/lib/cjs/render/primitives/geometry/GeometryAccumulator.d.ts.map +1 -1
- package/lib/cjs/render/primitives/geometry/GeometryAccumulator.js +2 -1
- package/lib/cjs/render/primitives/geometry/GeometryAccumulator.js.map +1 -1
- package/lib/cjs/render/primitives/geometry/GeometryListBuilder.d.ts.map +1 -1
- package/lib/cjs/render/primitives/geometry/GeometryListBuilder.js +1 -0
- package/lib/cjs/render/primitives/geometry/GeometryListBuilder.js.map +1 -1
- package/lib/cjs/render/primitives/mesh/MeshPrimitives.d.ts +2 -2
- package/lib/cjs/render/primitives/mesh/MeshPrimitives.d.ts.map +1 -1
- package/lib/cjs/render/primitives/mesh/MeshPrimitives.js +3 -3
- package/lib/cjs/render/primitives/mesh/MeshPrimitives.js.map +1 -1
- package/lib/cjs/render/webgl/BranchUniforms.d.ts.map +1 -1
- package/lib/cjs/render/webgl/BranchUniforms.js +8 -5
- package/lib/cjs/render/webgl/BranchUniforms.js.map +1 -1
- package/lib/cjs/render/webgl/SolarShadowMap.js +1 -1
- package/lib/cjs/render/webgl/SolarShadowMap.js.map +1 -1
- package/lib/cjs/render/webgl/System.d.ts +1 -1
- package/lib/cjs/request/Request.d.ts +167 -0
- package/lib/cjs/request/Request.d.ts.map +1 -0
- package/lib/cjs/request/Request.js +315 -0
- package/lib/cjs/request/Request.js.map +1 -0
- package/lib/cjs/tile/internal.d.ts +1 -0
- package/lib/cjs/tile/internal.d.ts.map +1 -1
- package/lib/cjs/tile/internal.js +1 -0
- package/lib/cjs/tile/internal.js.map +1 -1
- package/lib/cjs/tile/map/ArcGISTileMap.d.ts.map +1 -1
- package/lib/cjs/tile/map/ArcGISTileMap.js +6 -2
- package/lib/cjs/tile/map/ArcGISTileMap.js.map +1 -1
- package/lib/cjs/tile/map/ArcGisTokenGenerator.js +3 -3
- package/lib/cjs/tile/map/ArcGisTokenGenerator.js.map +1 -1
- package/lib/cjs/tile/map/ArcGisUtilities.d.ts +1 -1
- package/lib/cjs/tile/map/ArcGisUtilities.d.ts.map +1 -1
- package/lib/cjs/tile/map/ArcGisUtilities.js +18 -10
- package/lib/cjs/tile/map/ArcGisUtilities.js.map +1 -1
- package/lib/cjs/tile/map/BingElevation.js +4 -4
- package/lib/cjs/tile/map/BingElevation.js.map +1 -1
- package/lib/cjs/tile/map/CesiumTerrainProvider.js +3 -3
- package/lib/cjs/tile/map/CesiumTerrainProvider.js.map +1 -1
- package/lib/cjs/tile/map/ImageryProviders/ArcGISMapLayerImageryProvider.js +4 -4
- package/lib/cjs/tile/map/ImageryProviders/ArcGISMapLayerImageryProvider.js.map +1 -1
- package/lib/cjs/tile/map/ImageryProviders/BingImageryProvider.js +2 -2
- package/lib/cjs/tile/map/ImageryProviders/BingImageryProvider.js.map +1 -1
- package/lib/cjs/tile/map/MapLayerAuthentication.d.ts +20 -0
- package/lib/cjs/tile/map/MapLayerAuthentication.d.ts.map +1 -0
- package/lib/cjs/tile/map/MapLayerAuthentication.js +18 -0
- package/lib/cjs/tile/map/MapLayerAuthentication.js.map +1 -0
- package/lib/cjs/tile/map/MapLayerFormatRegistry.d.ts +6 -3
- package/lib/cjs/tile/map/MapLayerFormatRegistry.d.ts.map +1 -1
- package/lib/cjs/tile/map/MapLayerFormatRegistry.js +3 -1
- package/lib/cjs/tile/map/MapLayerFormatRegistry.js.map +1 -1
- package/lib/cjs/tile/map/MapLayerImageryFormats.d.ts +2 -2
- package/lib/cjs/tile/map/MapLayerImageryFormats.d.ts.map +1 -1
- package/lib/cjs/tile/map/MapLayerImageryFormats.js +4 -2
- package/lib/cjs/tile/map/MapLayerImageryFormats.js.map +1 -1
- package/lib/cjs/tile/map/MapLayerImageryProvider.d.ts +2 -2
- package/lib/cjs/tile/map/MapLayerImageryProvider.js +5 -5
- package/lib/cjs/tile/map/MapLayerImageryProvider.js.map +1 -1
- package/lib/cjs/tile/map/MapLayerSources.d.ts +3 -1
- package/lib/cjs/tile/map/MapLayerSources.d.ts.map +1 -1
- package/lib/cjs/tile/map/MapLayerSources.js +5 -3
- package/lib/cjs/tile/map/MapLayerSources.js.map +1 -1
- package/lib/cjs/tile/map/MapTileLoader.js +2 -2
- package/lib/cjs/tile/map/MapTileLoader.js.map +1 -1
- package/lib/cjs/tile/map/TerrainMeshProvider.d.ts +1 -1
- package/lib/cjs/tile/map/TerrainMeshProvider.js.map +1 -1
- package/lib/cjs/tile/map/WmsCapabilities.d.ts +1 -1
- package/lib/cjs/tile/map/WmsCapabilities.js +2 -2
- package/lib/cjs/tile/map/WmsCapabilities.js.map +1 -1
- package/lib/cjs/tile/map/WmtsCapabilities.d.ts +1 -1
- package/lib/cjs/tile/map/WmtsCapabilities.js +2 -2
- package/lib/cjs/tile/map/WmtsCapabilities.js.map +1 -1
- package/lib/esm/ApproximateTerrainHeights.d.ts.map +1 -1
- package/lib/esm/ApproximateTerrainHeights.js +6 -2
- package/lib/esm/ApproximateTerrainHeights.js.map +1 -1
- package/lib/esm/BackgroundMapGeometry.d.ts +1 -1
- package/lib/esm/BackgroundMapGeometry.d.ts.map +1 -1
- package/lib/esm/BackgroundMapGeometry.js +2 -2
- package/lib/esm/BackgroundMapGeometry.js.map +1 -1
- package/lib/esm/BingLocation.js +1 -1
- package/lib/esm/BingLocation.js.map +1 -1
- package/lib/esm/DisplayStyleState.d.ts +9 -3
- package/lib/esm/DisplayStyleState.d.ts.map +1 -1
- package/lib/esm/DisplayStyleState.js +66 -41
- package/lib/esm/DisplayStyleState.js.map +1 -1
- package/lib/esm/FrontendLoggerCategory.d.ts +2 -8
- package/lib/esm/FrontendLoggerCategory.d.ts.map +1 -1
- package/lib/esm/FrontendLoggerCategory.js +2 -8
- package/lib/esm/FrontendLoggerCategory.js.map +1 -1
- package/lib/esm/NativeApp.d.ts +1 -1
- package/lib/esm/NativeApp.d.ts.map +1 -1
- package/lib/esm/NativeApp.js +1 -1
- package/lib/esm/NativeApp.js.map +1 -1
- package/lib/esm/NotificationManager.d.ts +3 -1
- package/lib/esm/NotificationManager.d.ts.map +1 -1
- package/lib/esm/NotificationManager.js +2 -0
- package/lib/esm/NotificationManager.js.map +1 -1
- package/lib/esm/RealityDataSource.js +9 -4
- package/lib/esm/RealityDataSource.js.map +1 -1
- package/lib/esm/ViewContext.js.map +1 -1
- package/lib/esm/ViewCreator2d.js +1 -1
- package/lib/esm/ViewCreator2d.js.map +1 -1
- package/lib/esm/ViewCreator3d.d.ts +1 -1
- package/lib/esm/ViewCreator3d.d.ts.map +1 -1
- package/lib/esm/ViewCreator3d.js +2 -2
- package/lib/esm/ViewCreator3d.js.map +1 -1
- package/lib/esm/ViewingSpace.js +1 -1
- package/lib/esm/ViewingSpace.js.map +1 -1
- package/lib/esm/core-frontend.d.ts +4 -0
- package/lib/esm/core-frontend.d.ts.map +1 -1
- package/lib/esm/core-frontend.js +4 -0
- package/lib/esm/core-frontend.js.map +1 -1
- package/lib/esm/render/GraphicBuilder.d.ts +6 -0
- package/lib/esm/render/GraphicBuilder.d.ts.map +1 -1
- package/lib/esm/render/GraphicBuilder.js.map +1 -1
- package/lib/esm/render/primitives/geometry/GeometryAccumulator.d.ts +2 -0
- package/lib/esm/render/primitives/geometry/GeometryAccumulator.d.ts.map +1 -1
- package/lib/esm/render/primitives/geometry/GeometryAccumulator.js +2 -1
- package/lib/esm/render/primitives/geometry/GeometryAccumulator.js.map +1 -1
- package/lib/esm/render/primitives/geometry/GeometryListBuilder.d.ts.map +1 -1
- package/lib/esm/render/primitives/geometry/GeometryListBuilder.js +1 -0
- package/lib/esm/render/primitives/geometry/GeometryListBuilder.js.map +1 -1
- package/lib/esm/render/primitives/mesh/MeshPrimitives.d.ts +2 -2
- package/lib/esm/render/primitives/mesh/MeshPrimitives.d.ts.map +1 -1
- package/lib/esm/render/primitives/mesh/MeshPrimitives.js +3 -3
- package/lib/esm/render/primitives/mesh/MeshPrimitives.js.map +1 -1
- package/lib/esm/render/webgl/BranchUniforms.d.ts.map +1 -1
- package/lib/esm/render/webgl/BranchUniforms.js +8 -5
- package/lib/esm/render/webgl/BranchUniforms.js.map +1 -1
- package/lib/esm/render/webgl/SolarShadowMap.js +1 -1
- package/lib/esm/render/webgl/SolarShadowMap.js.map +1 -1
- package/lib/esm/render/webgl/System.d.ts +1 -1
- package/lib/esm/request/Request.d.ts +167 -0
- package/lib/esm/request/Request.d.ts.map +1 -0
- package/lib/esm/request/Request.js +289 -0
- package/lib/esm/request/Request.js.map +1 -0
- package/lib/esm/tile/internal.d.ts +1 -0
- package/lib/esm/tile/internal.d.ts.map +1 -1
- package/lib/esm/tile/internal.js +1 -0
- package/lib/esm/tile/internal.js.map +1 -1
- package/lib/esm/tile/map/ArcGISTileMap.d.ts.map +1 -1
- package/lib/esm/tile/map/ArcGISTileMap.js +6 -2
- package/lib/esm/tile/map/ArcGISTileMap.js.map +1 -1
- package/lib/esm/tile/map/ArcGisTokenGenerator.js +1 -1
- package/lib/esm/tile/map/ArcGisTokenGenerator.js.map +1 -1
- package/lib/esm/tile/map/ArcGisUtilities.d.ts +1 -1
- package/lib/esm/tile/map/ArcGisUtilities.d.ts.map +1 -1
- package/lib/esm/tile/map/ArcGisUtilities.js +14 -6
- package/lib/esm/tile/map/ArcGisUtilities.js.map +1 -1
- package/lib/esm/tile/map/BingElevation.js +1 -1
- package/lib/esm/tile/map/BingElevation.js.map +1 -1
- package/lib/esm/tile/map/CesiumTerrainProvider.js +1 -1
- package/lib/esm/tile/map/CesiumTerrainProvider.js.map +1 -1
- package/lib/esm/tile/map/ImageryProviders/ArcGISMapLayerImageryProvider.js +1 -1
- package/lib/esm/tile/map/ImageryProviders/ArcGISMapLayerImageryProvider.js.map +1 -1
- package/lib/esm/tile/map/ImageryProviders/BingImageryProvider.js +1 -1
- package/lib/esm/tile/map/ImageryProviders/BingImageryProvider.js.map +1 -1
- package/lib/esm/tile/map/MapLayerAuthentication.d.ts +20 -0
- package/lib/esm/tile/map/MapLayerAuthentication.d.ts.map +1 -0
- package/lib/esm/tile/map/MapLayerAuthentication.js +15 -0
- package/lib/esm/tile/map/MapLayerAuthentication.js.map +1 -0
- package/lib/esm/tile/map/MapLayerFormatRegistry.d.ts +6 -3
- package/lib/esm/tile/map/MapLayerFormatRegistry.d.ts.map +1 -1
- package/lib/esm/tile/map/MapLayerFormatRegistry.js +3 -1
- package/lib/esm/tile/map/MapLayerFormatRegistry.js.map +1 -1
- package/lib/esm/tile/map/MapLayerImageryFormats.d.ts +2 -2
- package/lib/esm/tile/map/MapLayerImageryFormats.d.ts.map +1 -1
- package/lib/esm/tile/map/MapLayerImageryFormats.js +5 -3
- package/lib/esm/tile/map/MapLayerImageryFormats.js.map +1 -1
- package/lib/esm/tile/map/MapLayerImageryProvider.d.ts +2 -2
- package/lib/esm/tile/map/MapLayerImageryProvider.js +2 -2
- package/lib/esm/tile/map/MapLayerImageryProvider.js.map +1 -1
- package/lib/esm/tile/map/MapLayerSources.d.ts +3 -1
- package/lib/esm/tile/map/MapLayerSources.d.ts.map +1 -1
- package/lib/esm/tile/map/MapLayerSources.js +4 -2
- package/lib/esm/tile/map/MapLayerSources.js.map +1 -1
- package/lib/esm/tile/map/MapTileLoader.js +1 -1
- package/lib/esm/tile/map/MapTileLoader.js.map +1 -1
- package/lib/esm/tile/map/TerrainMeshProvider.d.ts +1 -1
- package/lib/esm/tile/map/TerrainMeshProvider.js.map +1 -1
- package/lib/esm/tile/map/WmsCapabilities.d.ts +1 -1
- package/lib/esm/tile/map/WmsCapabilities.js +1 -1
- package/lib/esm/tile/map/WmsCapabilities.js.map +1 -1
- package/lib/esm/tile/map/WmtsCapabilities.d.ts +1 -1
- package/lib/esm/tile/map/WmtsCapabilities.js +1 -1
- package/lib/esm/tile/map/WmtsCapabilities.js.map +1 -1
- package/package.json +28 -22
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.getJson = exports.request = exports.ResponseError = exports.RequestGlobalOptions = exports.requestIdHeaderName = void 0;
|
|
23
|
+
/*---------------------------------------------------------------------------------------------
|
|
24
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
25
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26
|
+
*--------------------------------------------------------------------------------------------*/
|
|
27
|
+
/** @packageDocumentation
|
|
28
|
+
* @module iTwinServiceClients
|
|
29
|
+
*/
|
|
30
|
+
const deepAssign = __importStar(require("deep-assign"));
|
|
31
|
+
const qs_1 = require("qs");
|
|
32
|
+
const sarequest = __importStar(require("superagent"));
|
|
33
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
34
|
+
const FrontendLoggerCategory_1 = require("../FrontendLoggerCategory");
|
|
35
|
+
const loggerCategory = FrontendLoggerCategory_1.FrontendLoggerCategory.Request;
|
|
36
|
+
// CMS TODO: Move this entire wrapper to the frontend for use in the map/tile requests. Replace it with
|
|
37
|
+
// just using fetch directly as it is only ever used browser side.
|
|
38
|
+
/** @internal */
|
|
39
|
+
exports.requestIdHeaderName = "X-Correlation-Id";
|
|
40
|
+
/** @internal */
|
|
41
|
+
class RequestGlobalOptions {
|
|
42
|
+
}
|
|
43
|
+
exports.RequestGlobalOptions = RequestGlobalOptions;
|
|
44
|
+
RequestGlobalOptions.httpsProxy = undefined;
|
|
45
|
+
/** Creates an agent for any user defined proxy using the supplied additional options. Returns undefined if user hasn't defined a proxy.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
RequestGlobalOptions.createHttpsProxy = (_additionalOptions) => undefined;
|
|
49
|
+
RequestGlobalOptions.maxRetries = 4;
|
|
50
|
+
RequestGlobalOptions.timeout = {
|
|
51
|
+
deadline: 25000,
|
|
52
|
+
response: 10000,
|
|
53
|
+
};
|
|
54
|
+
// Assume application is online or offline. This hint skip retry/timeout
|
|
55
|
+
RequestGlobalOptions.online = true;
|
|
56
|
+
/** Error object that's thrown/rejected if the Request fails due to a network error, or if the status is *not* in the range of 200-299 (inclusive)
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
class ResponseError extends core_bentley_1.BentleyError {
|
|
60
|
+
constructor(errorNumber, message, getMetaData) {
|
|
61
|
+
super(errorNumber, message, getMetaData);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parses error from server's response
|
|
65
|
+
* @param response Http response from the server.
|
|
66
|
+
* @returns Parsed error.
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
static parse(response, log = true) {
|
|
70
|
+
const error = new ResponseError(ResponseError.parseHttpStatus(response.statusType));
|
|
71
|
+
if (!response) {
|
|
72
|
+
error.message = "Couldn't get response object.";
|
|
73
|
+
return error;
|
|
74
|
+
}
|
|
75
|
+
if (response.response) {
|
|
76
|
+
if (response.response.error) {
|
|
77
|
+
error.name = response.response.error.name || error.name;
|
|
78
|
+
error.description = response.response.error.message;
|
|
79
|
+
}
|
|
80
|
+
if (response.response.res) {
|
|
81
|
+
error.message = response.response.res.statusMessage;
|
|
82
|
+
}
|
|
83
|
+
if (response.response.body && Object.keys(response.response.body).length > 0) {
|
|
84
|
+
error._data = {};
|
|
85
|
+
deepAssign.default(error._data, response.response.body);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
error._data = response.response.text;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
error.status = response.status || response.statusCode;
|
|
92
|
+
error.name = response.code || response.name || error.name;
|
|
93
|
+
error.message = error.message || response.message || response.statusMessage;
|
|
94
|
+
if (log)
|
|
95
|
+
error.log();
|
|
96
|
+
return error;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Decides whether request should be retried or not
|
|
100
|
+
* @param error Error returned by request
|
|
101
|
+
* @param response Response returned by request
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
static shouldRetry(error, response) {
|
|
105
|
+
if (error !== undefined && error !== null) {
|
|
106
|
+
if ((error.status === undefined || error.status === null) && (error.res === undefined || error.res === null)) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return (response !== undefined && response.statusType === core_bentley_1.HttpStatus.ServerError);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
static parseHttpStatus(statusType) {
|
|
116
|
+
switch (statusType) {
|
|
117
|
+
case 1:
|
|
118
|
+
return core_bentley_1.HttpStatus.Info;
|
|
119
|
+
case 2:
|
|
120
|
+
return core_bentley_1.HttpStatus.Success;
|
|
121
|
+
case 3:
|
|
122
|
+
return core_bentley_1.HttpStatus.Redirection;
|
|
123
|
+
case 4:
|
|
124
|
+
return core_bentley_1.HttpStatus.ClientError;
|
|
125
|
+
case 5:
|
|
126
|
+
return core_bentley_1.HttpStatus.ServerError;
|
|
127
|
+
default:
|
|
128
|
+
return core_bentley_1.HttpStatus.Success;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
logMessage() {
|
|
135
|
+
return `${this.status} ${this.name}: ${this.message}`;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Logs this error
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
log() {
|
|
142
|
+
core_bentley_1.Logger.logError(loggerCategory, this.logMessage(), () => this.getMetaData());
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.ResponseError = ResponseError;
|
|
146
|
+
const logResponse = (req, startTime) => (res) => {
|
|
147
|
+
const elapsed = new Date().getTime() - startTime;
|
|
148
|
+
const elapsedTime = `${elapsed}ms`;
|
|
149
|
+
core_bentley_1.Logger.logTrace(loggerCategory, `${req.method.toUpperCase()} ${res.status} ${req.url} (${elapsedTime})`);
|
|
150
|
+
};
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
152
|
+
const logRequest = (req) => {
|
|
153
|
+
const startTime = new Date().getTime();
|
|
154
|
+
return req.on("response", logResponse(req, startTime));
|
|
155
|
+
};
|
|
156
|
+
/** Wrapper around making HTTP requests with the specific options.
|
|
157
|
+
*
|
|
158
|
+
* Usable in both a browser and node based environment.
|
|
159
|
+
*
|
|
160
|
+
* @param url Server URL to address the request
|
|
161
|
+
* @param options Options to pass to the request
|
|
162
|
+
* @returns Resolves to the response from the server
|
|
163
|
+
* @throws ResponseError if the request fails due to network issues, or if the returned status is *outside* the range of 200-299 (inclusive)
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
async function request(url, options) {
|
|
167
|
+
if (!RequestGlobalOptions.online) {
|
|
168
|
+
throw new ResponseError(503, "Service unavailable");
|
|
169
|
+
}
|
|
170
|
+
let sareq = sarequest.default(options.method, url);
|
|
171
|
+
const retries = typeof options.retries === "undefined" ? RequestGlobalOptions.maxRetries : options.retries;
|
|
172
|
+
sareq = sareq.retry(retries, options.retryCallback);
|
|
173
|
+
if (core_bentley_1.Logger.isEnabled(loggerCategory, core_bentley_1.LogLevel.Trace))
|
|
174
|
+
sareq = sareq.use(logRequest);
|
|
175
|
+
if (options.headers)
|
|
176
|
+
sareq = sareq.set(options.headers);
|
|
177
|
+
let queryStr = "";
|
|
178
|
+
let fullUrl = "";
|
|
179
|
+
if (options.qs && Object.keys(options.qs).length > 0) {
|
|
180
|
+
const stringifyOptions = { delimiter: "&", encode: false };
|
|
181
|
+
queryStr = (0, qs_1.stringify)(options.qs, stringifyOptions);
|
|
182
|
+
sareq = sareq.query(queryStr);
|
|
183
|
+
fullUrl = `${url}?${queryStr}`;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
fullUrl = url;
|
|
187
|
+
}
|
|
188
|
+
core_bentley_1.Logger.logInfo(loggerCategory, fullUrl);
|
|
189
|
+
if (options.auth)
|
|
190
|
+
sareq = sareq.auth(options.auth.user, options.auth.password);
|
|
191
|
+
if (options.accept)
|
|
192
|
+
sareq = sareq.accept(options.accept);
|
|
193
|
+
if (options.body)
|
|
194
|
+
sareq = sareq.send(options.body);
|
|
195
|
+
if (options.timeout)
|
|
196
|
+
sareq = sareq.timeout(options.timeout);
|
|
197
|
+
else
|
|
198
|
+
sareq = sareq.timeout(RequestGlobalOptions.timeout);
|
|
199
|
+
if (options.responseType)
|
|
200
|
+
sareq = sareq.responseType(options.responseType);
|
|
201
|
+
if (options.redirects)
|
|
202
|
+
sareq = sareq.redirects(options.redirects);
|
|
203
|
+
else
|
|
204
|
+
sareq = sareq.redirects(0);
|
|
205
|
+
if (options.buffer)
|
|
206
|
+
sareq = sareq.buffer(options.buffer);
|
|
207
|
+
if (options.parser)
|
|
208
|
+
sareq = sareq.parse(options.parser);
|
|
209
|
+
/** Default to any globally supplied proxy, unless an agent is specified in this call */
|
|
210
|
+
if (options.agent)
|
|
211
|
+
sareq = sareq.agent(options.agent);
|
|
212
|
+
else if (RequestGlobalOptions.httpsProxy)
|
|
213
|
+
sareq = sareq.agent(RequestGlobalOptions.httpsProxy);
|
|
214
|
+
if (options.progressCallback) {
|
|
215
|
+
sareq = sareq.on("progress", (event) => {
|
|
216
|
+
if (event) {
|
|
217
|
+
options.progressCallback({
|
|
218
|
+
loaded: event.loaded,
|
|
219
|
+
total: event.total,
|
|
220
|
+
percent: event.percent,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
const errorCallback = options.errorCallback ? options.errorCallback : ResponseError.parse;
|
|
226
|
+
if (options.readStream) {
|
|
227
|
+
if (typeof window !== "undefined")
|
|
228
|
+
throw new Error("This option is not supported on browsers");
|
|
229
|
+
return new Promise((resolve, reject) => {
|
|
230
|
+
sareq = sareq.type("blob");
|
|
231
|
+
options
|
|
232
|
+
.readStream
|
|
233
|
+
.pipe(sareq)
|
|
234
|
+
.on("error", (error) => {
|
|
235
|
+
const parsedError = errorCallback(error);
|
|
236
|
+
reject(parsedError);
|
|
237
|
+
})
|
|
238
|
+
.on("end", () => {
|
|
239
|
+
const retResponse = {
|
|
240
|
+
status: 201,
|
|
241
|
+
header: undefined,
|
|
242
|
+
body: undefined,
|
|
243
|
+
text: undefined,
|
|
244
|
+
};
|
|
245
|
+
resolve(retResponse);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
if (options.stream) {
|
|
250
|
+
if (typeof window !== "undefined")
|
|
251
|
+
throw new Error("This option is not supported on browsers");
|
|
252
|
+
return new Promise((resolve, reject) => {
|
|
253
|
+
sareq
|
|
254
|
+
.on("response", (res) => {
|
|
255
|
+
if (res.statusCode !== 200) {
|
|
256
|
+
const parsedError = errorCallback(res);
|
|
257
|
+
reject(parsedError);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
})
|
|
261
|
+
.pipe(options.stream)
|
|
262
|
+
.on("error", (error) => {
|
|
263
|
+
const parsedError = errorCallback(error);
|
|
264
|
+
reject(parsedError);
|
|
265
|
+
})
|
|
266
|
+
.on("finish", () => {
|
|
267
|
+
const retResponse = {
|
|
268
|
+
status: 200,
|
|
269
|
+
header: undefined,
|
|
270
|
+
body: undefined,
|
|
271
|
+
text: undefined,
|
|
272
|
+
};
|
|
273
|
+
resolve(retResponse);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
// console.log("%s %s %s", url, options.method, queryStr);
|
|
278
|
+
/**
|
|
279
|
+
* Note:
|
|
280
|
+
* Javascript's fetch returns status.OK if error is between 200-299 inclusive, and doesn't reject in this case.
|
|
281
|
+
* Fetch only rejects if there's some network issue (permissions issue or similar)
|
|
282
|
+
* Superagent rejects network issues, and errors outside the range of 200-299. We are currently using
|
|
283
|
+
* superagent, but may eventually switch to JavaScript's fetch library.
|
|
284
|
+
*/
|
|
285
|
+
try {
|
|
286
|
+
const response = await sareq;
|
|
287
|
+
const retResponse = {
|
|
288
|
+
body: response.body,
|
|
289
|
+
text: response.text,
|
|
290
|
+
header: response.header,
|
|
291
|
+
status: response.status,
|
|
292
|
+
};
|
|
293
|
+
return retResponse;
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
const parsedError = errorCallback(error);
|
|
297
|
+
throw parsedError;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.request = request;
|
|
301
|
+
/**
|
|
302
|
+
* fetch json from HTTP request
|
|
303
|
+
* @param url server URL to address the request
|
|
304
|
+
* @internal
|
|
305
|
+
*/
|
|
306
|
+
async function getJson(url) {
|
|
307
|
+
const options = {
|
|
308
|
+
method: "GET",
|
|
309
|
+
responseType: "json",
|
|
310
|
+
};
|
|
311
|
+
const data = await request(url, options);
|
|
312
|
+
return data.body;
|
|
313
|
+
}
|
|
314
|
+
exports.getJson = getJson;
|
|
315
|
+
//# sourceMappingURL=Request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/request/Request.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,wDAA0C;AAG1C,2BAAkD;AAClD,sDAAwC;AACxC,sDAAsG;AACtG,sEAAmE;AAEnE,MAAM,cAAc,GAAW,+CAAsB,CAAC,OAAO,CAAC;AAE9D,uGAAuG;AACvG,kEAAkE;AAElE,gBAAgB;AACH,QAAA,mBAAmB,GAAG,kBAAkB,CAAC;AAiHtD,gBAAgB;AAChB,MAAa,oBAAoB;;AAAjC,oDAaC;AAZe,+BAAU,GAAiB,SAAS,CAAC;AACnD;;GAEG;AACW,qCAAgB,GAAwE,CAAC,kBAAuC,EAAE,EAAE,CAAC,SAAS,CAAC;AAC/I,+BAAU,GAAW,CAAC,CAAC;AACvB,4BAAO,GAA0B;IAC7C,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,KAAK;CAChB,CAAC;AACF,wEAAwE;AAC1D,2BAAM,GAAY,IAAI,CAAC;AAGvC;;GAEG;AACH,MAAa,aAAc,SAAQ,2BAAY;IAI7C,YAAmB,WAAgC,EAAE,OAAgB,EAAE,WAAiC;QACtG,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,QAAa,EAAE,GAAG,GAAG,IAAI;QAC3C,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,aAAa,CAAC,eAAe,CAAC,QAAQ,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;iBACpB,EAAE,CAAC,OAAO,EAAE,CAAC,KAAU,EAAE,EAAE;gBAC1B,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;gBACzC,MAAM,CAAC,WAAW,CAAC,CAAC;YACtB,CAAC,CAAC;iBACD,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;gBACjB,MAAM,WAAW,GAAa;oBAC5B,MAAM,EAAE,GAAG;oBACX,MAAM,EAAE,SAAS;oBACjB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,SAAS;iBAChB,CAAC;gBACF,OAAO,CAAC,WAAW,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;KACJ;IAED,0DAA0D;IAE1D;;;;;;MAME;IACF,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC;QAC7B,MAAM,WAAW,GAAa;YAC5B,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;SACxB,CAAC;QACF,OAAO,WAAW,CAAC;KACpB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,WAAW,CAAC;KACnB;AACH,CAAC;AAzJD,0BAyJC;AAED;;;;GAIG;AACI,KAAK,UAAU,OAAO,CAAC,GAAW;IACvC,MAAM,OAAO,GAAmB;QAC9B,MAAM,EAAE,KAAK;QACb,YAAY,EAAE,MAAM;KACrB,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC;AAPD,0BAOC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iTwinServiceClients\r\n */\r\nimport * as deepAssign from \"deep-assign\";\r\nimport * as _ from \"lodash\";\r\nimport * as https from \"https\";\r\nimport { IStringifyOptions, stringify } from \"qs\";\r\nimport * as sarequest from \"superagent\";\r\nimport { BentleyError, GetMetaDataFunction, HttpStatus, Logger, LogLevel } from \"@itwin/core-bentley\";\r\nimport { FrontendLoggerCategory } from \"../FrontendLoggerCategory\";\r\n\r\nconst loggerCategory: string = FrontendLoggerCategory.Request;\r\n\r\n// CMS TODO: Move this entire wrapper to the frontend for use in the map/tile requests. Replace it with\r\n// just using fetch directly as it is only ever used browser side.\r\n\r\n/** @internal */\r\nexport const requestIdHeaderName = \"X-Correlation-Id\";\r\n\r\n/** @internal */\r\nexport interface RequestBasicCredentials { // axios: AxiosBasicCredentials\r\n user: string; // axios: username\r\n password: string; // axios: password\r\n}\r\n\r\n/** Typical option to query REST API. Note that services may not quite support these fields,\r\n * and the interface is only provided as a hint.\r\n * @internal\r\n */\r\nexport interface RequestQueryOptions {\r\n /**\r\n * Select string used by the query (use the mapped EC property names, and not TypeScript property names)\r\n * Example: \"Name,Size,Description\"\r\n */\r\n $select?: string;\r\n\r\n /**\r\n * Filter string used by the query (use the mapped EC property names, and not TypeScript property names)\r\n * Example: \"Name like '*.pdf' and Size lt 1000\"\r\n */\r\n $filter?: string;\r\n\r\n /** Sets the limit on the number of entries to be returned by the query */\r\n $top?: number;\r\n\r\n /** Sets the number of entries to be skipped */\r\n $skip?: number;\r\n\r\n /**\r\n * Orders the return values (use the mapped EC property names, and not TypeScript property names)\r\n * Example: \"Size desc\"\r\n */\r\n $orderby?: string;\r\n\r\n /**\r\n * Sets the limit on the number of entries to be returned by a single response.\r\n * Can be used with a Top option. For example if Top is set to 1000 and PageSize\r\n * is set to 100 then 10 requests will be performed to get result.\r\n */\r\n $pageSize?: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface RequestQueryStringifyOptions {\r\n delimiter?: string;\r\n encode?: boolean;\r\n}\r\n\r\n/** Option to control the time outs\r\n * Use a short response timeout to detect unresponsive networks quickly, and a long deadline to give time for downloads on slow,\r\n * but reliable, networks. Note that both of these timers limit how long uploads of attached files are allowed to take. Use long\r\n * timeouts if you're uploading files.\r\n * @internal\r\n */\r\nexport interface RequestTimeoutOptions {\r\n /** Sets a deadline (in milliseconds) for the entire request (including all uploads, redirects, server processing time) to complete.\r\n * If the response isn't fully downloaded within that time, the request will be aborted\r\n */\r\n deadline?: number;\r\n\r\n /** Sets maximum time (in milliseconds) to wait for the first byte to arrive from the server, but it does not limit how long the entire\r\n * download can take. Response timeout should be at least few seconds longer than just the time it takes the server to respond, because\r\n * it also includes time to make DNS lookup, TCP/IP and TLS connections, and time to upload request data.\r\n */\r\n response?: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface RequestOptions {\r\n method: string;\r\n headers?: any; // {Mas-App-Guid, Mas-UUid, User-Agent}\r\n auth?: RequestBasicCredentials;\r\n body?: any;\r\n qs?: any | RequestQueryOptions;\r\n responseType?: string;\r\n timeout?: RequestTimeoutOptions; // Optional timeouts. If unspecified, an arbitrary default is setup.\r\n stream?: any; // Optional stream to read the response to/from (only for NodeJs applications)\r\n readStream?: any; // Optional stream to read input from (only for NodeJs applications)\r\n buffer?: any;\r\n parser?: any;\r\n accept?: string;\r\n redirects?: number;\r\n errorCallback?: (response: any) => ResponseError;\r\n retryCallback?: (error: any, response: any) => boolean;\r\n progressCallback?: ProgressCallback;\r\n agent?: https.Agent;\r\n retries?: number;\r\n useCorsProxy?: boolean;\r\n}\r\n\r\n/** Response object if the request was successful. Note that the status within the range of 200-299 are considered as a success.\r\n * @internal\r\n */\r\nexport interface Response {\r\n body: any; // Parsed body of response\r\n text: string | undefined; // Returned for responseType:text\r\n header: any; // Parsed headers of response\r\n status: number; // Status code of response\r\n}\r\n\r\n/** @internal */\r\nexport interface ProgressInfo {\r\n percent?: number;\r\n total?: number;\r\n loaded: number;\r\n}\r\n\r\n/** @internal */\r\nexport type ProgressCallback = (progress: ProgressInfo) => void;\r\n\r\n/** @internal */\r\nexport class RequestGlobalOptions {\r\n public static httpsProxy?: https.Agent = undefined;\r\n /** Creates an agent for any user defined proxy using the supplied additional options. Returns undefined if user hasn't defined a proxy.\r\n * @internal\r\n */\r\n public static createHttpsProxy: (additionalOptions?: https.AgentOptions) => https.Agent | undefined = (_additionalOptions?: https.AgentOptions) => undefined;\r\n public static maxRetries: number = 4;\r\n public static timeout: RequestTimeoutOptions = {\r\n deadline: 25000,\r\n response: 10000,\r\n };\r\n // Assume application is online or offline. This hint skip retry/timeout\r\n public static online: boolean = true;\r\n}\r\n\r\n/** Error object that's thrown/rejected if the Request fails due to a network error, or if the status is *not* in the range of 200-299 (inclusive)\r\n * @internal\r\n */\r\nexport class ResponseError extends BentleyError {\r\n protected _data?: any;\r\n public status?: number;\r\n public description?: string;\r\n public constructor(errorNumber: number | HttpStatus, message?: string, getMetaData?: GetMetaDataFunction) {\r\n super(errorNumber, message, getMetaData);\r\n }\r\n\r\n /**\r\n * Parses error from server's response\r\n * @param response Http response from the server.\r\n * @returns Parsed error.\r\n * @internal\r\n */\r\n public static parse(response: any, log = true): ResponseError {\r\n const error = new ResponseError(ResponseError.parseHttpStatus(response.statusType));\r\n if (!response) {\r\n error.message = \"Couldn't get response object.\";\r\n return error;\r\n }\r\n\r\n if (response.response) {\r\n if (response.response.error) {\r\n error.name = response.response.error.name || error.name;\r\n error.description = response.response.error.message;\r\n }\r\n if (response.response.res) {\r\n error.message = response.response.res.statusMessage;\r\n }\r\n if (response.response.body && Object.keys(response.response.body).length > 0) {\r\n error._data = {};\r\n deepAssign.default(error._data, response.response.body);\r\n } else {\r\n error._data = response.response.text;\r\n }\r\n }\r\n\r\n error.status = response.status || response.statusCode;\r\n error.name = response.code || response.name || error.name;\r\n error.message = error.message || response.message || response.statusMessage;\r\n\r\n if (log)\r\n error.log();\r\n\r\n return error;\r\n }\r\n\r\n /**\r\n * Decides whether request should be retried or not\r\n * @param error Error returned by request\r\n * @param response Response returned by request\r\n * @internal\r\n */\r\n public static shouldRetry(error: any, response: any): boolean {\r\n if (error !== undefined && error !== null) {\r\n if ((error.status === undefined || error.status === null) && (error.res === undefined || error.res === null)) {\r\n return true;\r\n }\r\n }\r\n return (response !== undefined && response.statusType === HttpStatus.ServerError);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static parseHttpStatus(statusType: number): HttpStatus {\r\n switch (statusType) {\r\n case 1:\r\n return HttpStatus.Info;\r\n case 2:\r\n return HttpStatus.Success;\r\n case 3:\r\n return HttpStatus.Redirection;\r\n case 4:\r\n return HttpStatus.ClientError;\r\n case 5:\r\n return HttpStatus.ServerError;\r\n default:\r\n return HttpStatus.Success;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public logMessage(): string {\r\n return `${this.status} ${this.name}: ${this.message}`;\r\n }\r\n\r\n /**\r\n * Logs this error\r\n * @internal\r\n */\r\n public log(): void {\r\n Logger.logError(loggerCategory, this.logMessage(), () => this.getMetaData());\r\n }\r\n}\r\n\r\nconst logResponse = (req: sarequest.SuperAgentRequest, startTime: number) => (res: sarequest.Response) => {\r\n const elapsed = new Date().getTime() - startTime;\r\n const elapsedTime = `${elapsed}ms`;\r\n Logger.logTrace(loggerCategory, `${req.method.toUpperCase()} ${res.status} ${req.url} (${elapsedTime})`);\r\n};\r\n\r\n// eslint-disable-next-line @typescript-eslint/promise-function-async\r\nconst logRequest = (req: sarequest.SuperAgentRequest): sarequest.SuperAgentRequest => {\r\n const startTime = new Date().getTime();\r\n return req.on(\"response\", logResponse(req, startTime));\r\n};\r\n\r\n/** Wrapper around making HTTP requests with the specific options.\r\n *\r\n * Usable in both a browser and node based environment.\r\n *\r\n * @param url Server URL to address the request\r\n * @param options Options to pass to the request\r\n * @returns Resolves to the response from the server\r\n * @throws ResponseError if the request fails due to network issues, or if the returned status is *outside* the range of 200-299 (inclusive)\r\n * @internal\r\n */\r\nexport async function request(url: string, options: RequestOptions): Promise<Response> {\r\n if (!RequestGlobalOptions.online) {\r\n throw new ResponseError(503, \"Service unavailable\");\r\n }\r\n\r\n let sareq: sarequest.SuperAgentRequest = sarequest.default(options.method, url);\r\n const retries = typeof options.retries === \"undefined\" ? RequestGlobalOptions.maxRetries : options.retries;\r\n sareq = sareq.retry(retries, options.retryCallback);\r\n\r\n if (Logger.isEnabled(loggerCategory, LogLevel.Trace))\r\n sareq = sareq.use(logRequest);\r\n\r\n if (options.headers)\r\n sareq = sareq.set(options.headers);\r\n\r\n let queryStr: string = \"\";\r\n let fullUrl: string = \"\";\r\n if (options.qs && Object.keys(options.qs).length > 0) {\r\n const stringifyOptions: IStringifyOptions = { delimiter: \"&\", encode: false };\r\n queryStr = stringify(options.qs, stringifyOptions);\r\n sareq = sareq.query(queryStr);\r\n fullUrl = `${url}?${queryStr}`;\r\n } else {\r\n fullUrl = url;\r\n }\r\n\r\n Logger.logInfo(loggerCategory, fullUrl);\r\n\r\n if (options.auth)\r\n sareq = sareq.auth(options.auth.user, options.auth.password);\r\n\r\n if (options.accept)\r\n sareq = sareq.accept(options.accept);\r\n\r\n if (options.body)\r\n sareq = sareq.send(options.body);\r\n\r\n if (options.timeout)\r\n sareq = sareq.timeout(options.timeout);\r\n else\r\n sareq = sareq.timeout(RequestGlobalOptions.timeout);\r\n\r\n if (options.responseType)\r\n sareq = sareq.responseType(options.responseType);\r\n\r\n if (options.redirects)\r\n sareq = sareq.redirects(options.redirects);\r\n else\r\n sareq = sareq.redirects(0);\r\n\r\n if (options.buffer)\r\n sareq = sareq.buffer(options.buffer);\r\n\r\n if (options.parser)\r\n sareq = sareq.parse(options.parser);\r\n\r\n /** Default to any globally supplied proxy, unless an agent is specified in this call */\r\n if (options.agent)\r\n sareq = sareq.agent(options.agent);\r\n else if (RequestGlobalOptions.httpsProxy)\r\n sareq = sareq.agent(RequestGlobalOptions.httpsProxy);\r\n\r\n if (options.progressCallback) {\r\n sareq = sareq.on(\"progress\", (event: sarequest.ProgressEvent) => {\r\n if (event) {\r\n options.progressCallback!({\r\n loaded: event.loaded,\r\n total: event.total,\r\n percent: event.percent,\r\n });\r\n }\r\n });\r\n }\r\n\r\n const errorCallback = options.errorCallback ? options.errorCallback : ResponseError.parse;\r\n\r\n if (options.readStream) {\r\n if (typeof window !== \"undefined\")\r\n throw new Error(\"This option is not supported on browsers\");\r\n\r\n return new Promise<Response>((resolve, reject) => {\r\n sareq = sareq.type(\"blob\");\r\n options\r\n .readStream\r\n .pipe(sareq)\r\n .on(\"error\", (error: any) => {\r\n const parsedError = errorCallback(error);\r\n reject(parsedError);\r\n })\r\n .on(\"end\", () => {\r\n const retResponse: Response = {\r\n status: 201,\r\n header: undefined,\r\n body: undefined,\r\n text: undefined,\r\n };\r\n resolve(retResponse);\r\n });\r\n });\r\n }\r\n\r\n if (options.stream) {\r\n if (typeof window !== \"undefined\")\r\n throw new Error(\"This option is not supported on browsers\");\r\n\r\n return new Promise<Response>((resolve, reject) => {\r\n sareq\r\n .on(\"response\", (res: any) => {\r\n if (res.statusCode !== 200) {\r\n const parsedError = errorCallback(res);\r\n reject(parsedError);\r\n return;\r\n }\r\n })\r\n .pipe(options.stream)\r\n .on(\"error\", (error: any) => {\r\n const parsedError = errorCallback(error);\r\n reject(parsedError);\r\n })\r\n .on(\"finish\", () => {\r\n const retResponse: Response = {\r\n status: 200,\r\n header: undefined,\r\n body: undefined,\r\n text: undefined,\r\n };\r\n resolve(retResponse);\r\n });\r\n });\r\n }\r\n\r\n // console.log(\"%s %s %s\", url, options.method, queryStr);\r\n\r\n /**\r\n * Note:\r\n * Javascript's fetch returns status.OK if error is between 200-299 inclusive, and doesn't reject in this case.\r\n * Fetch only rejects if there's some network issue (permissions issue or similar)\r\n * Superagent rejects network issues, and errors outside the range of 200-299. We are currently using\r\n * superagent, but may eventually switch to JavaScript's fetch library.\r\n */\r\n try {\r\n const response = await sareq;\r\n const retResponse: Response = {\r\n body: response.body,\r\n text: response.text,\r\n header: response.header,\r\n status: response.status,\r\n };\r\n return retResponse;\r\n } catch (error) {\r\n const parsedError = errorCallback(error);\r\n throw parsedError;\r\n }\r\n}\r\n\r\n/**\r\n * fetch json from HTTP request\r\n * @param url server URL to address the request\r\n * @internal\r\n */\r\nexport async function getJson(url: string): Promise<any> {\r\n const options: RequestOptions = {\r\n method: \"GET\",\r\n responseType: \"json\",\r\n };\r\n const data = await request(url, options);\r\n return data.body;\r\n}\r\n"]}
|
|
@@ -32,6 +32,7 @@ export * from "./I3dmReader";
|
|
|
32
32
|
export * from "./B3dmReader";
|
|
33
33
|
export * from "./ImdlReader";
|
|
34
34
|
export * from "./map/ArcGISTileMap";
|
|
35
|
+
export * from "./map/MapLayerAuthentication";
|
|
35
36
|
export * from "./map/ArcGisTokenGenerator";
|
|
36
37
|
export * from "./map/ArcGisTokenManager";
|
|
37
38
|
export * from "./map/MapLayerFormatRegistry";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/tile/internal.ts"],"names":[],"mappings":"AAIA;;GAEG;AAYH,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC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AA+B,CAAC;AAC9C,cAAc,sDAAsD,CAAC;AACrE,cAAc,sDAAsD,CAAC;AACrE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,mDAAmD,CAAC;AAClE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,mDAAmD,CAAC;AAClE,cAAc,oDAAoD,CAAC;AACnE,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
|
package/lib/cjs/tile/internal.js
CHANGED
|
@@ -57,6 +57,7 @@ __exportStar(require("./I3dmReader"), exports);
|
|
|
57
57
|
__exportStar(require("./B3dmReader"), exports);
|
|
58
58
|
__exportStar(require("./ImdlReader"), exports);
|
|
59
59
|
__exportStar(require("./map/ArcGISTileMap"), exports);
|
|
60
|
+
__exportStar(require("./map/MapLayerAuthentication"), exports);
|
|
60
61
|
__exportStar(require("./map/ArcGisTokenGenerator"), exports);
|
|
61
62
|
__exportStar(require("./map/ArcGisTokenManager"), exports);
|
|
62
63
|
__exportStar(require("./map/MapLayerFormatRegistry"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/tile/internal.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;;;;;;;AAEH;;;;;;;;GAQG;AAEH,sDAAoC;AACpC,0DAAwC;AACxC,+CAA6B;AAC7B,yDAAuC;AACvC,yCAAuB;AACvB,gDAA8B;AAC9B,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B;AAC9B,iDAA+B;AAC/B,wDAAsC;AACtC,sDAAoC;AACpC,qDAAmC;AACnC,mDAAiC;AACjC,6CAA2B;AAC3B,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,sDAAoC;AACpC,0DAAwC;AACxC,8CAA4B;AAC5B,gDAA8B;AAC9B,uDAAqC;AACrC,8DAA4C;AAC5C,wDAAsC;AACtC,oDAAkC;AAClC,+CAA6B;AAC7B,+CAA6B;AAC7B,+CAA6B;AAC7B,+CAA6B;AAC7B,sDAAoC;AACpC,6DAA2C;AAC3C,2DAAyC;AACzC,+DAA6C;AAC7C,wDAAsC;AACtC,qDAAmC;AACnC,wDAAsC;AACtC,yDAAuC;AACvC,gEAA8C;AAC9C,uFAAqE;AACrE,uFAAqE;AACrE,6EAA2D;AAC3D,oFAAkE;AAClE,gFAA8D;AAC9D,oFAAkE;AAClE,qFAAmE;AACnE,+DAA6C;AAC7C,kEAAgD;AAChD,oDAAkC;AAClC,4DAA0C;AAC1C,8DAA4C;AAC5C,iEAA+C;AAC/C,gDAA8B;AAC9B,sDAAoC;AACpC,sDAAoC;AACpC,sDAAoC;AACpC,wDAAsC;AACtC,4DAA0C;AAC1C,+CAA6B;AAC7B,yDAAuC;AACvC,+CAA6B;AAC7B,sDAAoC;AACpC,mDAAiC;AACjC,oDAAkC;AAClC,uDAAqC;AACrC,oDAAkC;AAClC,wDAAsC;AACtC,wDAAsC;AACtC,iEAA+C;AAC/C,wDAAsC;AACtC,yDAAuC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\n/* The order of exports below is based on dependencies between the types in each file.\r\n * For example, IModelTileTree derives from TileTree, so TileTree must be exported first.\r\n * No file inside core-frontend should import from *any* file in /tile/ *except* for this one.\r\n * e.g.:\r\n * import { TileTree } from \"./tile/TileTree\"; // NO...\r\n * import { TileTree } from \"./tile/internal\"; // YES!\r\n * Failure to follow either of these two guidelines is very likely to produce difficult-to-debug run-time errors due\r\n * to circular dependencies.\r\n */\r\n\r\nexport * from \"./ViewFlagOverrides\";\r\nexport * from \"./map/MapCartoRectangle\";\r\nexport * from \"./map/QuadId\";\r\nexport * from \"./DisclosedTileTreeSet\";\r\nexport * from \"./Tile\";\r\nexport * from \"./LRUTileList\";\r\nexport * from \"./RealityTile\";\r\nexport * from \"./TileParams\";\r\nexport * from \"./TileContent\";\r\nexport * from \"./TileDrawArgs\";\r\nexport * from \"./RealityTileDrawArgs\";\r\nexport * from \"./GraphicsCollector\";\r\nexport * from \"./BatchedTileIdMap\";\r\nexport * from \"./TileTreeParams\";\r\nexport * from \"./TileTree\";\r\nexport * from \"./RealityTileTree\";\r\nexport * from \"./TileTreeSupplier\";\r\nexport * from \"./TileTreeOwner\";\r\nexport * from \"./TileTreeReference\";\r\nexport * from \"./TiledGraphicsProvider\";\r\nexport * from \"./TileAdmin\";\r\nexport * from \"./TileRequest\";\r\nexport * from \"./TileRequestChannel\";\r\nexport * from \"./IModelTileRequestChannels\";\r\nexport * from \"./TileRequestChannels\";\r\nexport * from \"./TileUsageMarker\";\r\nexport * from \"./GltfReader\";\r\nexport * from \"./I3dmReader\";\r\nexport * from \"./B3dmReader\";\r\nexport * from \"./ImdlReader\";\r\nexport * from \"./map/ArcGISTileMap\";\r\nexport * from \"./map/ArcGisTokenGenerator\";\r\nexport * from \"./map/ArcGisTokenManager\";\r\nexport * from \"./map/MapLayerFormatRegistry\";\r\nexport * from \"./map/ArcGisUtilities\";\r\nexport * from \"./map/WmsUtilities\";\r\nexport * from \"./map/WmsCapabilities\";\r\nexport * from \"./map/WmtsCapabilities\";\r\nexport * from \"./map/MapLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/ArcGISMapLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/AzureMapsLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/BingImageryProvider\";\r\nexport * from \"./map/ImageryProviders/MapBoxLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/TileUrlImageryProvider\";\r\nexport * from \"./map/ImageryProviders/WmsMapLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/WmtsMapLayerImageryProvider\";\r\nexport * from \"./map/MapLayerImageryFormats\";\r\nexport * from \"./map/MapLayerTileTreeReference\";\r\nexport * from \"./map/MapTileTree\";\r\nexport * from \"./map/TerrainMeshProvider\";\r\nexport * from \"./map/CesiumTerrainProvider\";\r\nexport * from \"./map/EllipsoidTerrainProvider\";\r\nexport * from \"./map/MapTile\";\r\nexport * from \"./RealityTileLoader\";\r\nexport * from \"./map/MapTileLoader\";\r\nexport * from \"./map/BingElevation\";\r\nexport * from \"./map/MapTilingScheme\";\r\nexport * from \"./map/MapTileAvailability\";\r\nexport * from \"./PntsReader\";\r\nexport * from \"./RealityModelTileTree\";\r\nexport * from \"./IModelTile\";\r\nexport * from \"./DynamicIModelTile\";\r\nexport * from \"./IModelTileTree\";\r\nexport * from \"./PrimaryTileTree\";\r\nexport * from \"./ClassifierTileTree\";\r\nexport * from \"./OrbitGtTileTree\";\r\nexport * from \"./map/ImageryTileTree\";\r\nexport * from \"./map/MapLayerSources\";\r\nexport * from \"./map/MapTiledGraphicsProvider\";\r\nexport * from \"./CesiumAssetProvider\";\r\nexport * from \"./ContextShareProvider\";\r\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/tile/internal.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;;;;;;;AAEH;;;;;;;;GAQG;AAEH,sDAAoC;AACpC,0DAAwC;AACxC,+CAA6B;AAC7B,yDAAuC;AACvC,yCAAuB;AACvB,gDAA8B;AAC9B,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B;AAC9B,iDAA+B;AAC/B,wDAAsC;AACtC,sDAAoC;AACpC,qDAAmC;AACnC,mDAAiC;AACjC,6CAA2B;AAC3B,oDAAkC;AAClC,qDAAmC;AACnC,kDAAgC;AAChC,sDAAoC;AACpC,0DAAwC;AACxC,8CAA4B;AAC5B,gDAA8B;AAC9B,uDAAqC;AACrC,8DAA4C;AAC5C,wDAAsC;AACtC,oDAAkC;AAClC,+CAA6B;AAC7B,+CAA6B;AAC7B,+CAA6B;AAC7B,+CAA6B;AAC7B,sDAAoC;AACpC,+DAA6C;AAC7C,6DAA2C;AAC3C,2DAAyC;AACzC,+DAA6C;AAC7C,wDAAsC;AACtC,qDAAmC;AACnC,wDAAsC;AACtC,yDAAuC;AACvC,gEAA8C;AAC9C,uFAAqE;AACrE,uFAAqE;AACrE,6EAA2D;AAC3D,oFAAkE;AAClE,gFAA8D;AAC9D,oFAAkE;AAClE,qFAAmE;AACnE,+DAA6C;AAC7C,kEAAgD;AAChD,oDAAkC;AAClC,4DAA0C;AAC1C,8DAA4C;AAC5C,iEAA+C;AAC/C,gDAA8B;AAC9B,sDAAoC;AACpC,sDAAoC;AACpC,sDAAoC;AACpC,wDAAsC;AACtC,4DAA0C;AAC1C,+CAA6B;AAC7B,yDAAuC;AACvC,+CAA6B;AAC7B,sDAAoC;AACpC,mDAAiC;AACjC,oDAAkC;AAClC,uDAAqC;AACrC,oDAAkC;AAClC,wDAAsC;AACtC,wDAAsC;AACtC,iEAA+C;AAC/C,wDAAsC;AACtC,yDAAuC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\n/* The order of exports below is based on dependencies between the types in each file.\r\n * For example, IModelTileTree derives from TileTree, so TileTree must be exported first.\r\n * No file inside core-frontend should import from *any* file in /tile/ *except* for this one.\r\n * e.g.:\r\n * import { TileTree } from \"./tile/TileTree\"; // NO...\r\n * import { TileTree } from \"./tile/internal\"; // YES!\r\n * Failure to follow either of these two guidelines is very likely to produce difficult-to-debug run-time errors due\r\n * to circular dependencies.\r\n */\r\n\r\nexport * from \"./ViewFlagOverrides\";\r\nexport * from \"./map/MapCartoRectangle\";\r\nexport * from \"./map/QuadId\";\r\nexport * from \"./DisclosedTileTreeSet\";\r\nexport * from \"./Tile\";\r\nexport * from \"./LRUTileList\";\r\nexport * from \"./RealityTile\";\r\nexport * from \"./TileParams\";\r\nexport * from \"./TileContent\";\r\nexport * from \"./TileDrawArgs\";\r\nexport * from \"./RealityTileDrawArgs\";\r\nexport * from \"./GraphicsCollector\";\r\nexport * from \"./BatchedTileIdMap\";\r\nexport * from \"./TileTreeParams\";\r\nexport * from \"./TileTree\";\r\nexport * from \"./RealityTileTree\";\r\nexport * from \"./TileTreeSupplier\";\r\nexport * from \"./TileTreeOwner\";\r\nexport * from \"./TileTreeReference\";\r\nexport * from \"./TiledGraphicsProvider\";\r\nexport * from \"./TileAdmin\";\r\nexport * from \"./TileRequest\";\r\nexport * from \"./TileRequestChannel\";\r\nexport * from \"./IModelTileRequestChannels\";\r\nexport * from \"./TileRequestChannels\";\r\nexport * from \"./TileUsageMarker\";\r\nexport * from \"./GltfReader\";\r\nexport * from \"./I3dmReader\";\r\nexport * from \"./B3dmReader\";\r\nexport * from \"./ImdlReader\";\r\nexport * from \"./map/ArcGISTileMap\";\r\nexport * from \"./map/MapLayerAuthentication\";\r\nexport * from \"./map/ArcGisTokenGenerator\";\r\nexport * from \"./map/ArcGisTokenManager\";\r\nexport * from \"./map/MapLayerFormatRegistry\";\r\nexport * from \"./map/ArcGisUtilities\";\r\nexport * from \"./map/WmsUtilities\";\r\nexport * from \"./map/WmsCapabilities\";\r\nexport * from \"./map/WmtsCapabilities\";\r\nexport * from \"./map/MapLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/ArcGISMapLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/AzureMapsLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/BingImageryProvider\";\r\nexport * from \"./map/ImageryProviders/MapBoxLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/TileUrlImageryProvider\";\r\nexport * from \"./map/ImageryProviders/WmsMapLayerImageryProvider\";\r\nexport * from \"./map/ImageryProviders/WmtsMapLayerImageryProvider\";\r\nexport * from \"./map/MapLayerImageryFormats\";\r\nexport * from \"./map/MapLayerTileTreeReference\";\r\nexport * from \"./map/MapTileTree\";\r\nexport * from \"./map/TerrainMeshProvider\";\r\nexport * from \"./map/CesiumTerrainProvider\";\r\nexport * from \"./map/EllipsoidTerrainProvider\";\r\nexport * from \"./map/MapTile\";\r\nexport * from \"./RealityTileLoader\";\r\nexport * from \"./map/MapTileLoader\";\r\nexport * from \"./map/BingElevation\";\r\nexport * from \"./map/MapTilingScheme\";\r\nexport * from \"./map/MapTileAvailability\";\r\nexport * from \"./PntsReader\";\r\nexport * from \"./RealityModelTileTree\";\r\nexport * from \"./IModelTile\";\r\nexport * from \"./DynamicIModelTile\";\r\nexport * from \"./IModelTileTree\";\r\nexport * from \"./PrimaryTileTree\";\r\nexport * from \"./ClassifierTileTree\";\r\nexport * from \"./OrbitGtTileTree\";\r\nexport * from \"./map/ImageryTileTree\";\r\nexport * from \"./map/MapLayerSources\";\r\nexport * from \"./map/MapTiledGraphicsProvider\";\r\nexport * from \"./CesiumAssetProvider\";\r\nexport * from \"./ContextShareProvider\";\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcGISTileMap.d.ts","sourceRoot":"","sources":["../../../../src/tile/map/ArcGISTileMap.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,gBAAgB;AAChB,qBAAa,aAAa;IAChB,kBAAkB,SAAM;IACxB,0BAA0B,SAAK;IAEvC,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,WAAW,CAA2E;IAC9F,OAAO,CAAC,YAAY,CAAS;gBACjB,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;cAOhC,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"ArcGISTileMap.d.ts","sourceRoot":"","sources":["../../../../src/tile/map/ArcGISTileMap.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,gBAAgB;AAChB,qBAAa,aAAa;IAChB,kBAAkB,SAAM;IACxB,0BAA0B,SAAK;IAEvC,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,WAAW,CAA2E;IAC9F,OAAO,CAAC,YAAY,CAAS;gBACjB,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;cAOhC,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAQ/H,SAAS,CAAC,0BAA0B,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG;QAAC,aAAa,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,OAAO,EAAE,CAAA;KAAC;IAexF,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;cA4B5D,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;cA6E7E,iCAAiC,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAkC1F"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.ArcGISTileMap = void 0;
|
|
11
|
-
const
|
|
11
|
+
const Request_1 = require("../../request/Request");
|
|
12
12
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
13
13
|
const internal_1 = require("../internal");
|
|
14
14
|
const nonVisibleChildren = [false, false, false, false];
|
|
@@ -24,7 +24,11 @@ class ArcGISTileMap {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
async fetchTileMapFromServer(level, row, column, width, height) {
|
|
27
|
-
|
|
27
|
+
const data = await (0, Request_1.request)(`${this._restBaseUrl}/tilemap/${level}/${row}/${column}/${width}/${height}?f=json`, {
|
|
28
|
+
method: "GET",
|
|
29
|
+
responseType: "json",
|
|
30
|
+
});
|
|
31
|
+
return data.body;
|
|
28
32
|
}
|
|
29
33
|
getAvailableTilesFromCache(tiles) {
|
|
30
34
|
let allTilesFound = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcGISTileMap.js","sourceRoot":"","sources":["../../../../src/tile/map/ArcGISTileMap.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAA+C;AAC/C,sDAAyE;AACzE,0CAAqC;AAErC,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,gBAAgB;AAChB,MAAa,aAAa;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AG,QAAQ,CAAC,MAAM,EAAE;oBACtC,wFAAwF;oBACxF,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAE,EAAE,CAAA,KAAK,CAAC,CAAC;oBACzC,KAAK,IAAI,CAAC,GAAC,CAAC,EAAE,CAAC,GAAC,SAAS,CAAC,MAAM,EAAC,CAAC,EAAE,EAAG;wBACrC,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;qBAC5B;oBACD,SAAS,GAAG,QAAQ,CAAC;iBACtB;aACF;SACF;QAAC,OAAO,MAAM,EAAE;YACf,yDAAyD;YACzD,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAE,EAAE,CAAA,KAAK,CAAC,CAAC;SACrC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5KD,sCA4KC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\nimport { getJson} from \"@bentley/itwin-client\";\r\nimport { assert, compareStrings, Dictionary } from \"@itwin/core-bentley\";\r\nimport { QuadId } from \"../internal\";\r\n\r\nconst nonVisibleChildren = [false, false, false, false];\r\n/** @internal */\r\nexport class ArcGISTileMap {\r\n public tileMapRequestSize = 32;\r\n public fallbackTileMapRequestSize = 2;\r\n\r\n private _callQueues: Array<Promise<boolean[]>> | undefined;\r\n private _tilesCache = new Dictionary<string, boolean>((lhs, rhs) => compareStrings(lhs, rhs));\r\n private _restBaseUrl: string;\r\n constructor(restBaseUrl: string, nbLods?: number) {\r\n this._restBaseUrl = restBaseUrl;\r\n if (nbLods !== undefined && nbLods > 0) {\r\n this._callQueues = new Array<Promise<boolean[]>>(nbLods).fill(Promise.resolve<boolean[]>(nonVisibleChildren));\r\n }\r\n\r\n }\r\n protected async fetchTileMapFromServer(level: number, row: number, column: number, width: number, height: number): Promise<any> {\r\n return getJson(`${this._restBaseUrl}/tilemap/${level}/${row}/${column}/${width}/${height}?f=json`);\r\n }\r\n\r\n protected getAvailableTilesFromCache(tiles: QuadId[]): {allTilesFound: boolean, available: boolean[]} {\r\n let allTilesFound = true;\r\n\r\n // Check children visibility from cache\r\n const available = tiles.map((tileId) => {\r\n const avail = this._tilesCache.get(tileId.contentId);\r\n if (undefined === avail) {\r\n allTilesFound = false;\r\n }\r\n return avail ?? false;\r\n });\r\n\r\n return {allTilesFound, available};\r\n }\r\n\r\n public async getChildrenAvailability(childIds: QuadId[]): Promise<boolean[]> {\r\n if (!childIds.length)\r\n return [];\r\n\r\n // We need to check cache again:\r\n // Tiles we are looking for may have been added to cache while we were waiting in the call queue.\r\n const cacheInfo = this.getAvailableTilesFromCache(childIds);\r\n if (cacheInfo.allTilesFound) {\r\n return cacheInfo.available;\r\n }\r\n\r\n // If we never encountered this tile level before, then a tilemap request must be made to get tiles visibility.\r\n // However, we dont want several overlapping large tilemap request being made simultaneously for tiles on the same level.\r\n // To avoid this from happening, we 'serialize' async calls so that we wait until the first tilemap request has completed\r\n // before making another one.\r\n const childLevel = childIds[0].level+1;\r\n if (this._callQueues && childLevel < this._callQueues.length ) {\r\n const res = this._callQueues[childLevel].then(async () => this.getChildrenAvailabilityFromServer(childIds));\r\n this._callQueues[childLevel] = res.catch(() => {return nonVisibleChildren;});\r\n return res;\r\n } else {\r\n // We should not be in this case, probably because server info is missing LODs in the capabilities?!\r\n return this.getChildrenAvailabilityFromServer(childIds);\r\n }\r\n }\r\n\r\n // Query tiles are tiles that we need to check availability\r\n // The array is assumed to be in in row major orientation, i.e.: [TileRow0Col0, TileRow0Col1, TileRow1Col0, TileRow1Col1,]\r\n protected async fetchAndReadTilemap(queryTiles: QuadId[], reqWidth: number, reqHeight: number) {\r\n let available: boolean[] = [];\r\n if (queryTiles.length === 0) {\r\n return available;\r\n }\r\n\r\n const row = queryTiles[0].row;\r\n const column = queryTiles[0].column;\r\n const level = queryTiles[0].level;\r\n\r\n let reqRow, reqColumn;\r\n if (reqWidth === this.fallbackTileMapRequestSize && reqHeight === this.fallbackTileMapRequestSize){\r\n reqRow = row;\r\n reqColumn = column;\r\n } else {\r\n // If tile map if big enough. create offset that will place the current tile in the middle of the tilemap.\r\n // If we place the first query tile in the top-left corner (i.e. without offset), any query for a tile located above or on the left\r\n // will trigger a new request.\r\n const offsetRow = (reqHeight/2.0)-1;\r\n const offsetColumn = (reqWidth/2.0)-1;\r\n reqRow = Math.max(row - offsetRow, 0);\r\n reqColumn = Math.max(column - offsetColumn, 0);\r\n }\r\n\r\n try {\r\n // console.log(`Tilemap request: ${level},${reqRow},${reqColumn},${reqWidth},${reqHeight}`);\r\n const json = await this.fetchTileMapFromServer(level, reqRow, reqColumn, reqWidth, reqHeight);\r\n let tileMapWidth = reqWidth;\r\n let tileMapHeight = reqHeight;\r\n if (Array.isArray(json.data)){\r\n\r\n // The response width and height might be different than the requested dimensions.\r\n // Ref: https://developers.arcgis.com/rest/services-reference/enterprise/tile-map.htm\r\n if (json.adjusted) {\r\n // If tilemap size got adjusted, I'm expecting to get adjusted size...\r\n // otherwise there is something really odd with this server.\r\n assert(json.location?.width !== undefined && json.location?.height !== undefined);\r\n if (json.location?.width !== undefined && json.location?.height !== undefined) {\r\n tileMapWidth = json.location?.width;\r\n tileMapHeight = json.location?.height;\r\n }\r\n }\r\n let k = 0;\r\n for (let j = 0; j < tileMapWidth; j++) {\r\n for (let i = 0; i < tileMapHeight; i++) {\r\n const avail = json.data[(j*tileMapWidth)+i] !== 0;\r\n const curColumn = reqColumn + i;\r\n const curRow = reqRow + j;\r\n // console.log(`Tilemap tile:: ${level},${curRow},${curColumn} => ${avail}`);\r\n this._tilesCache.set(QuadId.getTileContentId(level, curColumn, curRow), avail);\r\n\r\n // Check if actual tile is among the children we are looking for, if so update the availability array.\r\n if ( curColumn >= queryTiles[0].column && curColumn <= queryTiles[queryTiles.length-1].column\r\n && curRow >= queryTiles[0].row && curRow <= queryTiles[queryTiles.length-1].row ) {\r\n available[k++] = avail;\r\n }\r\n\r\n }\r\n }\r\n } else {\r\n // If server returns data (i.e. error 422), thats fine we assume all tiles of tilemap are not available.\r\n available = queryTiles.map(()=>false);\r\n\r\n // Mark all tilemap tiles to non-available in the cache too\r\n for (let j = 0; j < tileMapWidth; j++) {\r\n for (let i = 0; i < tileMapHeight; i++) {\r\n this._tilesCache.set(QuadId.getTileContentId(level, reqColumn + i, reqRow + j), false);\r\n }\r\n }\r\n }\r\n } catch (_error) {\r\n available = queryTiles.map(()=>false);\r\n }\r\n\r\n return available;\r\n }\r\n\r\n protected async getChildrenAvailabilityFromServer(childIds: QuadId[]): Promise<boolean[]> {\r\n // We need to check cache again:\r\n // Tiles we are looking for may have been added to cache while we were waiting in the call queue.\r\n const cacheInfo = this.getAvailableTilesFromCache(childIds);\r\n if (cacheInfo.allTilesFound) {\r\n return cacheInfo.available;\r\n }\r\n\r\n let available;\r\n try {\r\n available = await this.fetchAndReadTilemap(childIds, this.tileMapRequestSize, this.tileMapRequestSize);\r\n if (available.length !== childIds.length) {\r\n if (this.tileMapRequestSize > this.fallbackTileMapRequestSize) {\r\n // Maybe we were unlucky and the tilemap got adjusted our the tiles we are looking for got clipped,\r\n // so let try we a smaller tilemap\r\n available = await this.fetchAndReadTilemap(childIds, this.fallbackTileMapRequestSize, this.fallbackTileMapRequestSize);\r\n }\r\n\r\n if (available.length < childIds.length) {\r\n // Could not all tiles children tiles, returns what we got and fill any gaps with false.\r\n const tmpAvail = childIds.map(()=>false);\r\n for (let i=0; i<available.length;i++ ) {\r\n tmpAvail[i] = available[i];\r\n }\r\n available = tmpAvail;\r\n }\r\n }\r\n } catch (_error) {\r\n // if any error occurs, we assume tiles not to be visible\r\n available = childIds.map(()=>false);\r\n }\r\n\r\n return available;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ArcGISTileMap.js","sourceRoot":"","sources":["../../../../src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C,kBAAkB,CAAC,CAAC;YACvG,IAAI,SAAS,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE;gBACxC,IAAI,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,0BAA0B,EAAE;oBAC/D,mGAAmG;oBACnG,kCAAkC;oBAChC,SAAS,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,0BAA0B,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC;iBACxH;gBAED,IAAI,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE;oBACtC,wFAAwF;oBACxF,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAE,EAAE,CAAA,KAAK,CAAC,CAAC;oBACzC,KAAK,IAAI,CAAC,GAAC,CAAC,EAAE,CAAC,GAAC,SAAS,CAAC,MAAM,EAAC,CAAC,EAAE,EAAG;wBACrC,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;qBAC5B;oBACD,SAAS,GAAG,QAAQ,CAAC;iBACtB;aACF;SACF;QAAC,OAAO,MAAM,EAAE;YACf,yDAAyD;YACzD,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAE,EAAE,CAAA,KAAK,CAAC,CAAC;SACrC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAhLD,sCAgLC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\nimport { request } from \"../../request/Request\";\r\nimport { assert, compareStrings, Dictionary } from \"@itwin/core-bentley\";\r\nimport { QuadId } from \"../internal\";\r\n\r\nconst nonVisibleChildren = [false, false, false, false];\r\n/** @internal */\r\nexport class ArcGISTileMap {\r\n public tileMapRequestSize = 32;\r\n public fallbackTileMapRequestSize = 2;\r\n\r\n private _callQueues: Array<Promise<boolean[]>> | undefined;\r\n private _tilesCache = new Dictionary<string, boolean>((lhs, rhs) => compareStrings(lhs, rhs));\r\n private _restBaseUrl: string;\r\n constructor(restBaseUrl: string, nbLods?: number) {\r\n this._restBaseUrl = restBaseUrl;\r\n if (nbLods !== undefined && nbLods > 0) {\r\n this._callQueues = new Array<Promise<boolean[]>>(nbLods).fill(Promise.resolve<boolean[]>(nonVisibleChildren));\r\n }\r\n\r\n }\r\n protected async fetchTileMapFromServer(level: number, row: number, column: number, width: number, height: number): Promise<any> {\r\n const data = await request(`${this._restBaseUrl}/tilemap/${level}/${row}/${column}/${width}/${height}?f=json`, {\r\n method: \"GET\",\r\n responseType: \"json\",\r\n });\r\n return data.body;\r\n }\r\n\r\n protected getAvailableTilesFromCache(tiles: QuadId[]): {allTilesFound: boolean, available: boolean[]} {\r\n let allTilesFound = true;\r\n\r\n // Check children visibility from cache\r\n const available = tiles.map((tileId) => {\r\n const avail = this._tilesCache.get(tileId.contentId);\r\n if (undefined === avail) {\r\n allTilesFound = false;\r\n }\r\n return avail ?? false;\r\n });\r\n\r\n return {allTilesFound, available};\r\n }\r\n\r\n public async getChildrenAvailability(childIds: QuadId[]): Promise<boolean[]> {\r\n if (!childIds.length)\r\n return [];\r\n\r\n // We need to check cache again:\r\n // Tiles we are looking for may have been added to cache while we were waiting in the call queue.\r\n const cacheInfo = this.getAvailableTilesFromCache(childIds);\r\n if (cacheInfo.allTilesFound) {\r\n return cacheInfo.available;\r\n }\r\n\r\n // If we never encountered this tile level before, then a tilemap request must be made to get tiles visibility.\r\n // However, we dont want several overlapping large tilemap request being made simultaneously for tiles on the same level.\r\n // To avoid this from happening, we 'serialize' async calls so that we wait until the first tilemap request has completed\r\n // before making another one.\r\n const childLevel = childIds[0].level+1;\r\n if (this._callQueues && childLevel < this._callQueues.length ) {\r\n const res = this._callQueues[childLevel].then(async () => this.getChildrenAvailabilityFromServer(childIds));\r\n this._callQueues[childLevel] = res.catch(() => {return nonVisibleChildren;});\r\n return res;\r\n } else {\r\n // We should not be in this case, probably because server info is missing LODs in the capabilities?!\r\n return this.getChildrenAvailabilityFromServer(childIds);\r\n }\r\n }\r\n\r\n // Query tiles are tiles that we need to check availability\r\n // The array is assumed to be in in row major orientation, i.e.: [TileRow0Col0, TileRow0Col1, TileRow1Col0, TileRow1Col1,]\r\n protected async fetchAndReadTilemap(queryTiles: QuadId[], reqWidth: number, reqHeight: number) {\r\n let available: boolean[] = [];\r\n if (queryTiles.length === 0) {\r\n return available;\r\n }\r\n\r\n const row = queryTiles[0].row;\r\n const column = queryTiles[0].column;\r\n const level = queryTiles[0].level;\r\n\r\n let reqRow, reqColumn;\r\n if (reqWidth === this.fallbackTileMapRequestSize && reqHeight === this.fallbackTileMapRequestSize){\r\n reqRow = row;\r\n reqColumn = column;\r\n } else {\r\n // If tile map if big enough. create offset that will place the current tile in the middle of the tilemap.\r\n // If we place the first query tile in the top-left corner (i.e. without offset), any query for a tile located above or on the left\r\n // will trigger a new request.\r\n const offsetRow = (reqHeight/2.0)-1;\r\n const offsetColumn = (reqWidth/2.0)-1;\r\n reqRow = Math.max(row - offsetRow, 0);\r\n reqColumn = Math.max(column - offsetColumn, 0);\r\n }\r\n\r\n try {\r\n // console.log(`Tilemap request: ${level},${reqRow},${reqColumn},${reqWidth},${reqHeight}`);\r\n const json = await this.fetchTileMapFromServer(level, reqRow, reqColumn, reqWidth, reqHeight);\r\n let tileMapWidth = reqWidth;\r\n let tileMapHeight = reqHeight;\r\n if (Array.isArray(json.data)){\r\n\r\n // The response width and height might be different than the requested dimensions.\r\n // Ref: https://developers.arcgis.com/rest/services-reference/enterprise/tile-map.htm\r\n if (json.adjusted) {\r\n // If tilemap size got adjusted, I'm expecting to get adjusted size...\r\n // otherwise there is something really odd with this server.\r\n assert(json.location?.width !== undefined && json.location?.height !== undefined);\r\n if (json.location?.width !== undefined && json.location?.height !== undefined) {\r\n tileMapWidth = json.location?.width;\r\n tileMapHeight = json.location?.height;\r\n }\r\n }\r\n let k = 0;\r\n for (let j = 0; j < tileMapWidth; j++) {\r\n for (let i = 0; i < tileMapHeight; i++) {\r\n const avail = json.data[(j*tileMapWidth)+i] !== 0;\r\n const curColumn = reqColumn + i;\r\n const curRow = reqRow + j;\r\n // console.log(`Tilemap tile:: ${level},${curRow},${curColumn} => ${avail}`);\r\n this._tilesCache.set(QuadId.getTileContentId(level, curColumn, curRow), avail);\r\n\r\n // Check if actual tile is among the children we are looking for, if so update the availability array.\r\n if ( curColumn >= queryTiles[0].column && curColumn <= queryTiles[queryTiles.length-1].column\r\n && curRow >= queryTiles[0].row && curRow <= queryTiles[queryTiles.length-1].row ) {\r\n available[k++] = avail;\r\n }\r\n\r\n }\r\n }\r\n } else {\r\n // If server returns data (i.e. error 422), thats fine we assume all tiles of tilemap are not available.\r\n available = queryTiles.map(()=>false);\r\n\r\n // Mark all tilemap tiles to non-available in the cache too\r\n for (let j = 0; j < tileMapWidth; j++) {\r\n for (let i = 0; i < tileMapHeight; i++) {\r\n this._tilesCache.set(QuadId.getTileContentId(level, reqColumn + i, reqRow + j), false);\r\n }\r\n }\r\n }\r\n } catch (_error) {\r\n available = queryTiles.map(()=>false);\r\n }\r\n\r\n return available;\r\n }\r\n\r\n protected async getChildrenAvailabilityFromServer(childIds: QuadId[]): Promise<boolean[]> {\r\n // We need to check cache again:\r\n // Tiles we are looking for may have been added to cache while we were waiting in the call queue.\r\n const cacheInfo = this.getAvailableTilesFromCache(childIds);\r\n if (cacheInfo.allTilesFound) {\r\n return cacheInfo.available;\r\n }\r\n\r\n let available;\r\n try {\r\n available = await this.fetchAndReadTilemap(childIds, this.tileMapRequestSize, this.tileMapRequestSize);\r\n if (available.length !== childIds.length) {\r\n if (this.tileMapRequestSize > this.fallbackTileMapRequestSize) {\r\n // Maybe we were unlucky and the tilemap got adjusted our the tiles we are looking for got clipped,\r\n // so let try we a smaller tilemap\r\n available = await this.fetchAndReadTilemap(childIds, this.fallbackTileMapRequestSize, this.fallbackTileMapRequestSize);\r\n }\r\n\r\n if (available.length < childIds.length) {\r\n // Could not all tiles children tiles, returns what we got and fill any gaps with false.\r\n const tmpAvail = childIds.map(()=>false);\r\n for (let i=0; i<available.length;i++ ) {\r\n tmpAvail[i] = available[i];\r\n }\r\n available = tmpAvail;\r\n }\r\n }\r\n } catch (_error) {\r\n // if any error occurs, we assume tiles not to be visible\r\n available = childIds.map(()=>false);\r\n }\r\n\r\n return available;\r\n }\r\n}\r\n"]}
|
|
@@ -5,7 +5,7 @@ exports.ArcGisTokenGenerator = exports.ArcGisTokenClientType = void 0;
|
|
|
5
5
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
6
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
7
|
*--------------------------------------------------------------------------------------------*/
|
|
8
|
-
const
|
|
8
|
+
const Request_1 = require("../../request/Request");
|
|
9
9
|
// client application's base URL, a user-specified IP address, or the IP address that is making the request.
|
|
10
10
|
/** @internal */
|
|
11
11
|
var ArcGisTokenClientType;
|
|
@@ -24,7 +24,7 @@ class ArcGisTokenGenerator {
|
|
|
24
24
|
const infoUrl = lowerUrl.substr(0, restApiIdx + ArcGisTokenGenerator.restApiPath.length) + ArcGisTokenGenerator.restApiInfoPath;
|
|
25
25
|
let tokenServicesUrl;
|
|
26
26
|
try {
|
|
27
|
-
const response = await (0,
|
|
27
|
+
const response = await (0, Request_1.request)(infoUrl, { method: "GET", responseType: "json" });
|
|
28
28
|
tokenServicesUrl = ArcGisTokenGenerator.getTokenServiceFromInfoJson(response === null || response === void 0 ? void 0 : response.body);
|
|
29
29
|
}
|
|
30
30
|
catch (_error) {
|
|
@@ -84,7 +84,7 @@ class ArcGisTokenGenerator {
|
|
|
84
84
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
85
85
|
responseType: "json",
|
|
86
86
|
};
|
|
87
|
-
const response = await (0,
|
|
87
|
+
const response = await (0, Request_1.request)(tokenServiceUrl, httpRequestOptions);
|
|
88
88
|
// Check a token was really generated (an error could be part of the body)
|
|
89
89
|
token = response === null || response === void 0 ? void 0 : response.body;
|
|
90
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcGisTokenGenerator.js","sourceRoot":"","sources":["../../../../src/tile/map/ArcGisTokenGenerator.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,wDAAgE;AAkBhE,4GAA4G;AAC5G,gBAAgB;AAChB,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,6DAAE,CAAA;IACF,uEAAO,CAAA;IACP,2EAAS,CAAA;AACX,CAAC,EAJW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAIhC;AA8BD,gBAAgB;AAChB,MAAa,oBAAoB;IAOxB,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,kBAA0B;QACjE,MAAM,QAAQ,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;QAClD,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QACtE,IAAI,UAAU,KAAK,CAAC,CAAC;YACnB,OAAO,SAAS,CAAC;QACnB,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,GAAG,oBAAoB,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,oBAAoB,CAAC,eAAe,CAAC;QAEhI,IAAI,gBAAoC,CAAC;QACzC,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAO,EAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC;YACjF,gBAAgB,GAAG,oBAAoB,CAAC,2BAA2B,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC,CAAC;SACrF;QAAC,OAAO,MAAM,EAAE;SAChB;QACD,OAAO,gBAAgB,CAAC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C,MAAM,EAAE,GAAG,CAAC,CAAC;IACtE,CAAC;IAED,2EAA2E;IAC3E,qDAAqD;IAC9C,MAAM,CAAC,aAAa,CAAC,GAAW;QACrC,OAAO,kBAAkB,CAAC,GAAG,CAAC;aAC3B,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;aACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;aACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;aACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;aACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;;AA3GH,oDA4GC;AA3GyB,gCAAW,GAAG,QAAQ,CAAC;AACvB,oCAAe,GAAG,cAAc,CAAC;AAEzD,wEAAwE;AACzD,0CAAqB,GAAG,IAAI,GAAG,EAAkB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { request, RequestOptions } from \"@bentley/itwin-client\";\r\n\r\n/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\n/** @internal */\r\nexport interface ArcGisToken {\r\n // The generated token.\r\n token: string;\r\n\r\n // The expiration time of the token in milliseconds since January 1, 1970 (UTC).\r\n expires: number;\r\n\r\n // This property will show as true if the token must always pass over ssl.\r\n ssl: boolean;\r\n}\r\n\r\n// client application's base URL, a user-specified IP address, or the IP address that is making the request.\r\n/** @internal */\r\nexport enum ArcGisTokenClientType {\r\n ip,\r\n referer,\r\n requestIp,\r\n}\r\n\r\n/** @internal */\r\nexport interface ArcGisGenerateTokenOptions {\r\n\r\n // The client type that will be granted access to the token.\r\n // Users will be able to specify whether the token will be generated for a client application's base URL,\r\n // a user-specified IP address, or the IP address that is making the request.\r\n client: ArcGisTokenClientType;\r\n\r\n // The IP address that will be using the created token for access.\r\n // On the Generate Token page, the IP address is specified in the IP Address field. This is required when client has been set as ip.\r\n // Example ip=11.11.111.111\r\n ip?: string;\r\n\r\n // The base URL of the client application that will use the token.\r\n // On the Generate Token page, the referrer URL is specified in the Webapp URL field.\r\n // Defaults to location.origin if undefined and client = referer.\r\n // This is required when client has been set as referer.\r\n // Example : referer=https://myserver/mywebapp\r\n referer?: string;\r\n\r\n // The token expiration time in minutes. The default is 60 minutes (one hour).\r\n // The maximum expiration period is 15 days. The maximum value of the expiration time is controlled by the server.\r\n // Requests for tokens larger than this time will be rejected.\r\n // Applications are responsible for renewing expired tokens;\r\n // expired tokens will be rejected by the server on subsequent requests that use the token.\r\n expiration?: number; // in minutes, defaults to 60 minutes\r\n}\r\n\r\n/** @internal */\r\nexport class ArcGisTokenGenerator {\r\n private static readonly restApiPath = \"/rest/\";\r\n private static readonly restApiInfoPath = \"info?f=pjson\";\r\n\r\n // Cache info url to avoid fetching/parsing twice for the same base url.\r\n private static _tokenServiceUrlCache = new Map<string, string>();\r\n\r\n public static async fetchTokenServiceUrl(esriRestServiceUrl: string): Promise<string | undefined> {\r\n const lowerUrl = esriRestServiceUrl.toLowerCase();\r\n const restApiIdx = lowerUrl.indexOf(ArcGisTokenGenerator.restApiPath);\r\n if (restApiIdx === -1)\r\n return undefined;\r\n const infoUrl = lowerUrl.substr(0, restApiIdx + ArcGisTokenGenerator.restApiPath.length) + ArcGisTokenGenerator.restApiInfoPath;\r\n\r\n let tokenServicesUrl: string | undefined;\r\n try {\r\n const response = await request(infoUrl, { method: \"GET\", responseType: \"json\" });\r\n tokenServicesUrl = ArcGisTokenGenerator.getTokenServiceFromInfoJson(response?.body);\r\n } catch (_error) {\r\n }\r\n return tokenServicesUrl;\r\n }\r\n\r\n public static getTokenServiceFromInfoJson(json: any): string | undefined {\r\n return json.authInfo?.isTokenBasedSecurity ? json?.authInfo?.tokenServicesUrl : undefined;\r\n }\r\n\r\n public async getTokenServiceUrl(baseUrl: string): Promise<string | undefined> {\r\n const cached = ArcGisTokenGenerator._tokenServiceUrlCache.get(baseUrl);\r\n if (cached !== undefined)\r\n return cached;\r\n\r\n const tokenServiceUrl = await ArcGisTokenGenerator.fetchTokenServiceUrl(baseUrl);\r\n if (tokenServiceUrl !== undefined)\r\n ArcGisTokenGenerator._tokenServiceUrlCache.set(baseUrl, tokenServiceUrl);\r\n\r\n return tokenServiceUrl;\r\n }\r\n\r\n // base url: ArcGis REST service base URL (format must be \"https://<host>/<instance>/rest/\")\r\n public async generate(esriRestServiceUrl: string, userName: string, password: string, options: ArcGisGenerateTokenOptions): Promise<any> {\r\n const tokenServiceUrl = await this.getTokenServiceUrl(esriRestServiceUrl);\r\n if (!tokenServiceUrl)\r\n return undefined;\r\n\r\n let token: undefined;\r\n try {\r\n const encodedUsername = encodeURIComponent(userName);\r\n const encodedPassword = encodeURIComponent(password);\r\n\r\n // Compose the expiration param\r\n let expirationStr = \"\";\r\n if (options.expiration) {\r\n expirationStr = `&expiration=${options.expiration}`;\r\n }\r\n\r\n // Compose the client param\r\n let clientStr = \"\";\r\n if (options.client === ArcGisTokenClientType.referer) {\r\n let refererStr = \"\";\r\n if (options.referer === undefined) {\r\n refererStr = encodeURIComponent(location.origin); // default to application origin\r\n } else {\r\n refererStr = encodeURIComponent(options.referer);\r\n }\r\n\r\n clientStr = `&client=referer&referer=${refererStr}`;\r\n } else if (options.client === ArcGisTokenClientType.ip) {\r\n if (options.ip === undefined)\r\n return token;\r\n clientStr = `&client=ip&ip=${options.ip}`;\r\n } else if (options.client === ArcGisTokenClientType.requestIp) {\r\n clientStr = `&client=requestip&ip=`;\r\n }\r\n\r\n const httpRequestOptions: RequestOptions = {\r\n method: \"POST\",\r\n body: `username=${encodedUsername}&password=${encodedPassword}${clientStr}${expirationStr}&f=pjson`,\r\n headers: { \"content-type\": \"application/x-www-form-urlencoded\" },\r\n responseType: \"json\",\r\n };\r\n\r\n const response = await request(tokenServiceUrl, httpRequestOptions);\r\n\r\n // Check a token was really generated (an error could be part of the body)\r\n token = response?.body;\r\n\r\n } catch (_error) {\r\n }\r\n return token;\r\n }\r\n\r\n // Encode following 'application/x-www-form-urlencoded' standard (https://www.w3.org/TR/html401/interact/forms.html#h-17.13.3.3)\r\n // Also mentioned here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent\r\n public static formEncode(str: string): string {\r\n return ArcGisTokenGenerator.rfc1738Encode(str).replace(/%20/g, \"+\");\r\n }\r\n\r\n // Encode following RFC1738 standard (https://www.ietf.org/rfc/rfc1738.txt)\r\n // Code from https://locutus.io/php/url/rawurlencode/\r\n public static rfc1738Encode(str: string): string {\r\n return encodeURIComponent(str)\r\n .replace(/!/g, \"%21\")\r\n .replace(/'/g, \"%27\")\r\n .replace(/\\(/g, \"%28\")\r\n .replace(/\\)/g, \"%29\")\r\n .replace(/\\*/g, \"%2A\");\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ArcGisTokenGenerator.js","sourceRoot":"","sources":["../../../../src/tile/map/ArcGisTokenGenerator.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,mDAAgE;AAkBhE,4GAA4G;AAC5G,gBAAgB;AAChB,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,6DAAE,CAAA;IACF,uEAAO,CAAA;IACP,2EAAS,CAAA;AACX,CAAC,EAJW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAIhC;AA8BD,gBAAgB;AAChB,MAAa,oBAAoB;IAOxB,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,kBAA0B;QACjE,MAAM,QAAQ,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;QAClD,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QACtE,IAAI,UAAU,KAAK,CAAC,CAAC;YACnB,OAAO,SAAS,CAAC;QACnB,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,GAAG,oBAAoB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AAY,EAAE,MAAM;aACrB,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAM,IAAA,iBAAO,EAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;YAEpE,0EAA0E;YAC1E,KAAK,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC;SAExB;QAAC,OAAO,MAAM,EAAE;SAChB;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,gIAAgI;IAChI,2HAA2H;IACpH,MAAM,CAAC,UAAU,CAAC,GAAW;QAClC,OAAO,oBAAoB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACtE,CAAC;IAED,2EAA2E;IAC3E,qDAAqD;IAC9C,MAAM,CAAC,aAAa,CAAC,GAAW;QACrC,OAAO,kBAAkB,CAAC,GAAG,CAAC;aAC3B,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;aACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;aACpB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;aACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;aACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;;AA3GH,oDA4GC;AA3GyB,gCAAW,GAAG,QAAQ,CAAC;AACvB,oCAAe,GAAG,cAAc,CAAC;AAEzD,wEAAwE;AACzD,0CAAqB,GAAG,IAAI,GAAG,EAAkB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { request, RequestOptions } from \"../../request/Request\";\r\n\r\n/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\n/** @internal */\r\nexport interface ArcGisToken {\r\n // The generated token.\r\n token: string;\r\n\r\n // The expiration time of the token in milliseconds since January 1, 1970 (UTC).\r\n expires: number;\r\n\r\n // This property will show as true if the token must always pass over ssl.\r\n ssl: boolean;\r\n}\r\n\r\n// client application's base URL, a user-specified IP address, or the IP address that is making the request.\r\n/** @internal */\r\nexport enum ArcGisTokenClientType {\r\n ip,\r\n referer,\r\n requestIp,\r\n}\r\n\r\n/** @internal */\r\nexport interface ArcGisGenerateTokenOptions {\r\n\r\n // The client type that will be granted access to the token.\r\n // Users will be able to specify whether the token will be generated for a client application's base URL,\r\n // a user-specified IP address, or the IP address that is making the request.\r\n client: ArcGisTokenClientType;\r\n\r\n // The IP address that will be using the created token for access.\r\n // On the Generate Token page, the IP address is specified in the IP Address field. This is required when client has been set as ip.\r\n // Example ip=11.11.111.111\r\n ip?: string;\r\n\r\n // The base URL of the client application that will use the token.\r\n // On the Generate Token page, the referrer URL is specified in the Webapp URL field.\r\n // Defaults to location.origin if undefined and client = referer.\r\n // This is required when client has been set as referer.\r\n // Example : referer=https://myserver/mywebapp\r\n referer?: string;\r\n\r\n // The token expiration time in minutes. The default is 60 minutes (one hour).\r\n // The maximum expiration period is 15 days. The maximum value of the expiration time is controlled by the server.\r\n // Requests for tokens larger than this time will be rejected.\r\n // Applications are responsible for renewing expired tokens;\r\n // expired tokens will be rejected by the server on subsequent requests that use the token.\r\n expiration?: number; // in minutes, defaults to 60 minutes\r\n}\r\n\r\n/** @internal */\r\nexport class ArcGisTokenGenerator {\r\n private static readonly restApiPath = \"/rest/\";\r\n private static readonly restApiInfoPath = \"info?f=pjson\";\r\n\r\n // Cache info url to avoid fetching/parsing twice for the same base url.\r\n private static _tokenServiceUrlCache = new Map<string, string>();\r\n\r\n public static async fetchTokenServiceUrl(esriRestServiceUrl: string): Promise<string | undefined> {\r\n const lowerUrl = esriRestServiceUrl.toLowerCase();\r\n const restApiIdx = lowerUrl.indexOf(ArcGisTokenGenerator.restApiPath);\r\n if (restApiIdx === -1)\r\n return undefined;\r\n const infoUrl = lowerUrl.substr(0, restApiIdx + ArcGisTokenGenerator.restApiPath.length) + ArcGisTokenGenerator.restApiInfoPath;\r\n\r\n let tokenServicesUrl: string | undefined;\r\n try {\r\n const response = await request(infoUrl, { method: \"GET\", responseType: \"json\" });\r\n tokenServicesUrl = ArcGisTokenGenerator.getTokenServiceFromInfoJson(response?.body);\r\n } catch (_error) {\r\n }\r\n return tokenServicesUrl;\r\n }\r\n\r\n public static getTokenServiceFromInfoJson(json: any): string | undefined {\r\n return json.authInfo?.isTokenBasedSecurity ? json?.authInfo?.tokenServicesUrl : undefined;\r\n }\r\n\r\n public async getTokenServiceUrl(baseUrl: string): Promise<string | undefined> {\r\n const cached = ArcGisTokenGenerator._tokenServiceUrlCache.get(baseUrl);\r\n if (cached !== undefined)\r\n return cached;\r\n\r\n const tokenServiceUrl = await ArcGisTokenGenerator.fetchTokenServiceUrl(baseUrl);\r\n if (tokenServiceUrl !== undefined)\r\n ArcGisTokenGenerator._tokenServiceUrlCache.set(baseUrl, tokenServiceUrl);\r\n\r\n return tokenServiceUrl;\r\n }\r\n\r\n // base url: ArcGis REST service base URL (format must be \"https://<host>/<instance>/rest/\")\r\n public async generate(esriRestServiceUrl: string, userName: string, password: string, options: ArcGisGenerateTokenOptions): Promise<any> {\r\n const tokenServiceUrl = await this.getTokenServiceUrl(esriRestServiceUrl);\r\n if (!tokenServiceUrl)\r\n return undefined;\r\n\r\n let token: undefined;\r\n try {\r\n const encodedUsername = encodeURIComponent(userName);\r\n const encodedPassword = encodeURIComponent(password);\r\n\r\n // Compose the expiration param\r\n let expirationStr = \"\";\r\n if (options.expiration) {\r\n expirationStr = `&expiration=${options.expiration}`;\r\n }\r\n\r\n // Compose the client param\r\n let clientStr = \"\";\r\n if (options.client === ArcGisTokenClientType.referer) {\r\n let refererStr = \"\";\r\n if (options.referer === undefined) {\r\n refererStr = encodeURIComponent(location.origin); // default to application origin\r\n } else {\r\n refererStr = encodeURIComponent(options.referer);\r\n }\r\n\r\n clientStr = `&client=referer&referer=${refererStr}`;\r\n } else if (options.client === ArcGisTokenClientType.ip) {\r\n if (options.ip === undefined)\r\n return token;\r\n clientStr = `&client=ip&ip=${options.ip}`;\r\n } else if (options.client === ArcGisTokenClientType.requestIp) {\r\n clientStr = `&client=requestip&ip=`;\r\n }\r\n\r\n const httpRequestOptions: RequestOptions = {\r\n method: \"POST\",\r\n body: `username=${encodedUsername}&password=${encodedPassword}${clientStr}${expirationStr}&f=pjson`,\r\n headers: { \"content-type\": \"application/x-www-form-urlencoded\" },\r\n responseType: \"json\",\r\n };\r\n\r\n const response = await request(tokenServiceUrl, httpRequestOptions);\r\n\r\n // Check a token was really generated (an error could be part of the body)\r\n token = response?.body;\r\n\r\n } catch (_error) {\r\n }\r\n return token;\r\n }\r\n\r\n // Encode following 'application/x-www-form-urlencoded' standard (https://www.w3.org/TR/html401/interact/forms.html#h-17.13.3.3)\r\n // Also mentioned here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent\r\n public static formEncode(str: string): string {\r\n return ArcGisTokenGenerator.rfc1738Encode(str).replace(/%20/g, \"+\");\r\n }\r\n\r\n // Encode following RFC1738 standard (https://www.ietf.org/rfc/rfc1738.txt)\r\n // Code from https://locutus.io/php/url/rawurlencode/\r\n public static rfc1738Encode(str: string): string {\r\n return encodeURIComponent(str)\r\n .replace(/!/g, \"%21\")\r\n .replace(/'/g, \"%27\")\r\n .replace(/\\(/g, \"%28\")\r\n .replace(/\\)/g, \"%29\")\r\n .replace(/\\*/g, \"%2A\");\r\n }\r\n}\r\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestBasicCredentials, Response } from "
|
|
1
|
+
import { RequestBasicCredentials, Response } from "../../request/Request";
|
|
2
2
|
import { MapCartoRectangle, MapLayerSource, MapLayerSourceValidation } from "../internal";
|
|
3
3
|
/** @packageDocumentation
|
|
4
4
|
* @module Tiles
|