@itwin/core-frontend 4.0.0-dev.70 → 4.0.0-dev.72
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 +74 -37
- package/lib/cjs/BingLocation.d.ts.map +1 -1
- package/lib/cjs/BingLocation.js +4 -5
- package/lib/cjs/BingLocation.js.map +1 -1
- package/lib/cjs/BriefcaseConnection.js.map +1 -1
- package/lib/cjs/NativeApp.d.ts.map +1 -1
- package/lib/cjs/NativeApp.js +0 -3
- package/lib/cjs/NativeApp.js.map +1 -1
- package/lib/cjs/RealityDataSourceCesiumIonAssetImpl.d.ts +1 -2
- package/lib/cjs/RealityDataSourceCesiumIonAssetImpl.d.ts.map +1 -1
- package/lib/cjs/RealityDataSourceCesiumIonAssetImpl.js +6 -20
- package/lib/cjs/RealityDataSourceCesiumIonAssetImpl.js.map +1 -1
- package/lib/cjs/RealityDataSourceContextShareImpl.d.ts +1 -1
- package/lib/cjs/RealityDataSourceContextShareImpl.d.ts.map +1 -1
- package/lib/cjs/RealityDataSourceContextShareImpl.js +2 -11
- package/lib/cjs/RealityDataSourceContextShareImpl.js.map +1 -1
- package/lib/cjs/RealityDataSourceTilesetUrlImpl.d.ts +4 -2
- package/lib/cjs/RealityDataSourceTilesetUrlImpl.d.ts.map +1 -1
- package/lib/cjs/RealityDataSourceTilesetUrlImpl.js +4 -12
- package/lib/cjs/RealityDataSourceTilesetUrlImpl.js.map +1 -1
- package/lib/cjs/extension/providers/RemoteExtensionProvider.d.ts.map +1 -1
- package/lib/cjs/extension/providers/RemoteExtensionProvider.js +1 -8
- package/lib/cjs/extension/providers/RemoteExtensionProvider.js.map +1 -1
- package/lib/cjs/render/primitives/PointCloudPrimitive.d.ts +1 -1
- package/lib/cjs/render/primitives/PointCloudPrimitive.d.ts.map +1 -1
- package/lib/cjs/render/primitives/PointCloudPrimitive.js.map +1 -1
- package/lib/cjs/render/webgl/AttributeBuffers.d.ts +1 -1
- package/lib/cjs/render/webgl/AttributeBuffers.d.ts.map +1 -1
- package/lib/cjs/render/webgl/AttributeBuffers.js.map +1 -1
- package/lib/cjs/render/webgl/PointCloud.js +1 -1
- package/lib/cjs/render/webgl/PointCloud.js.map +1 -1
- package/lib/cjs/request/Request.d.ts +17 -143
- package/lib/cjs/request/Request.d.ts.map +1 -1
- package/lib/cjs/request/Request.js +46 -303
- package/lib/cjs/request/Request.js.map +1 -1
- package/lib/cjs/tile/PntsReader.d.ts +5 -1
- package/lib/cjs/tile/PntsReader.d.ts.map +1 -1
- package/lib/cjs/tile/PntsReader.js +28 -25
- package/lib/cjs/tile/PntsReader.js.map +1 -1
- package/lib/cjs/tile/RealityTileLoader.d.ts.map +1 -1
- package/lib/cjs/tile/RealityTileLoader.js +14 -3
- package/lib/cjs/tile/RealityTileLoader.js.map +1 -1
- package/lib/cjs/tile/map/ArcGISTileMap.d.ts.map +1 -1
- package/lib/cjs/tile/map/ArcGISTileMap.js +1 -5
- package/lib/cjs/tile/map/ArcGISTileMap.js.map +1 -1
- package/lib/cjs/tile/map/BingElevation.d.ts.map +1 -1
- package/lib/cjs/tile/map/BingElevation.js +6 -16
- package/lib/cjs/tile/map/BingElevation.js.map +1 -1
- package/lib/cjs/tile/map/CesiumTerrainProvider.d.ts.map +1 -1
- package/lib/cjs/tile/map/CesiumTerrainProvider.js +12 -18
- package/lib/cjs/tile/map/CesiumTerrainProvider.js.map +1 -1
- package/lib/cjs/tile/map/ImageryProviders/BingImageryProvider.d.ts.map +1 -1
- package/lib/cjs/tile/map/ImageryProviders/BingImageryProvider.js +1 -3
- package/lib/cjs/tile/map/ImageryProviders/BingImageryProvider.js.map +1 -1
- package/lib/cjs/tile/map/MapLayerSources.js +1 -1
- package/lib/cjs/tile/map/MapLayerSources.js.map +1 -1
- package/lib/cjs/tile/map/WmsCapabilities.d.ts.map +1 -1
- package/lib/cjs/tile/map/WmsCapabilities.js +3 -6
- package/lib/cjs/tile/map/WmsCapabilities.js.map +1 -1
- package/lib/cjs/tile/map/WmtsCapabilities.d.ts.map +1 -1
- package/lib/cjs/tile/map/WmtsCapabilities.js +3 -6
- package/lib/cjs/tile/map/WmtsCapabilities.js.map +1 -1
- package/lib/cjs/tools/ViewTool.d.ts.map +1 -1
- package/lib/cjs/tools/ViewTool.js +0 -3
- package/lib/cjs/tools/ViewTool.js.map +1 -1
- package/lib/esm/BingLocation.d.ts.map +1 -1
- package/lib/esm/BingLocation.js +4 -5
- package/lib/esm/BingLocation.js.map +1 -1
- package/lib/esm/BriefcaseConnection.js.map +1 -1
- package/lib/esm/NativeApp.d.ts.map +1 -1
- package/lib/esm/NativeApp.js +0 -3
- package/lib/esm/NativeApp.js.map +1 -1
- package/lib/esm/RealityDataSourceCesiumIonAssetImpl.d.ts +1 -2
- package/lib/esm/RealityDataSourceCesiumIonAssetImpl.d.ts.map +1 -1
- package/lib/esm/RealityDataSourceCesiumIonAssetImpl.js +6 -20
- package/lib/esm/RealityDataSourceCesiumIonAssetImpl.js.map +1 -1
- package/lib/esm/RealityDataSourceContextShareImpl.d.ts +1 -1
- package/lib/esm/RealityDataSourceContextShareImpl.d.ts.map +1 -1
- package/lib/esm/RealityDataSourceContextShareImpl.js +2 -11
- package/lib/esm/RealityDataSourceContextShareImpl.js.map +1 -1
- package/lib/esm/RealityDataSourceTilesetUrlImpl.d.ts +4 -2
- package/lib/esm/RealityDataSourceTilesetUrlImpl.d.ts.map +1 -1
- package/lib/esm/RealityDataSourceTilesetUrlImpl.js +4 -12
- package/lib/esm/RealityDataSourceTilesetUrlImpl.js.map +1 -1
- package/lib/esm/extension/providers/RemoteExtensionProvider.d.ts.map +1 -1
- package/lib/esm/extension/providers/RemoteExtensionProvider.js +1 -8
- package/lib/esm/extension/providers/RemoteExtensionProvider.js.map +1 -1
- package/lib/esm/render/primitives/PointCloudPrimitive.d.ts +1 -1
- package/lib/esm/render/primitives/PointCloudPrimitive.d.ts.map +1 -1
- package/lib/esm/render/primitives/PointCloudPrimitive.js.map +1 -1
- package/lib/esm/render/webgl/AttributeBuffers.d.ts +1 -1
- package/lib/esm/render/webgl/AttributeBuffers.d.ts.map +1 -1
- package/lib/esm/render/webgl/AttributeBuffers.js.map +1 -1
- package/lib/esm/render/webgl/PointCloud.js +1 -1
- package/lib/esm/render/webgl/PointCloud.js.map +1 -1
- package/lib/esm/request/Request.d.ts +17 -143
- package/lib/esm/request/Request.d.ts.map +1 -1
- package/lib/esm/request/Request.js +42 -275
- package/lib/esm/request/Request.js.map +1 -1
- package/lib/esm/tile/PntsReader.d.ts +5 -1
- package/lib/esm/tile/PntsReader.d.ts.map +1 -1
- package/lib/esm/tile/PntsReader.js +29 -26
- package/lib/esm/tile/PntsReader.js.map +1 -1
- package/lib/esm/tile/RealityTileLoader.d.ts.map +1 -1
- package/lib/esm/tile/RealityTileLoader.js +14 -3
- package/lib/esm/tile/RealityTileLoader.js.map +1 -1
- package/lib/esm/tile/map/ArcGISTileMap.d.ts.map +1 -1
- package/lib/esm/tile/map/ArcGISTileMap.js +1 -5
- package/lib/esm/tile/map/ArcGISTileMap.js.map +1 -1
- package/lib/esm/tile/map/BingElevation.d.ts.map +1 -1
- package/lib/esm/tile/map/BingElevation.js +6 -16
- package/lib/esm/tile/map/BingElevation.js.map +1 -1
- package/lib/esm/tile/map/CesiumTerrainProvider.d.ts.map +1 -1
- package/lib/esm/tile/map/CesiumTerrainProvider.js +12 -18
- package/lib/esm/tile/map/CesiumTerrainProvider.js.map +1 -1
- package/lib/esm/tile/map/ImageryProviders/BingImageryProvider.d.ts.map +1 -1
- package/lib/esm/tile/map/ImageryProviders/BingImageryProvider.js +1 -3
- package/lib/esm/tile/map/ImageryProviders/BingImageryProvider.js.map +1 -1
- package/lib/esm/tile/map/MapLayerSources.js +2 -2
- package/lib/esm/tile/map/MapLayerSources.js.map +1 -1
- package/lib/esm/tile/map/WmsCapabilities.d.ts.map +1 -1
- package/lib/esm/tile/map/WmsCapabilities.js +3 -6
- package/lib/esm/tile/map/WmsCapabilities.js.map +1 -1
- package/lib/esm/tile/map/WmtsCapabilities.d.ts.map +1 -1
- package/lib/esm/tile/map/WmtsCapabilities.js +3 -6
- package/lib/esm/tile/map/WmtsCapabilities.js.map +1 -1
- package/lib/esm/tools/ViewTool.d.ts.map +1 -1
- package/lib/esm/tools/ViewTool.js +0 -3
- package/lib/esm/tools/ViewTool.js.map +1 -1
- package/package.json +21 -27
|
@@ -1,319 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getJson = exports.request = exports.ResponseError = exports.RequestGlobalOptions = exports.requestIdHeaderName = void 0;
|
|
27
2
|
/*---------------------------------------------------------------------------------------------
|
|
28
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
29
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
30
5
|
*--------------------------------------------------------------------------------------------*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const deepAssign = __importStar(require("deep-assign"));
|
|
35
|
-
const qs_1 = require("qs");
|
|
36
|
-
const sarequest = __importStar(require("superagent"));
|
|
37
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
38
|
-
const FrontendLoggerCategory_1 = require("../FrontendLoggerCategory");
|
|
39
|
-
const loggerCategory = FrontendLoggerCategory_1.FrontendLoggerCategory.Request;
|
|
40
|
-
// CMS TODO: Move this entire wrapper to the frontend for use in the map/tile requests. Replace it with
|
|
41
|
-
// just using fetch directly as it is only ever used browser side.
|
|
42
|
-
/** @internal */
|
|
43
|
-
exports.requestIdHeaderName = "X-Correlation-Id";
|
|
44
|
-
/** @internal */
|
|
45
|
-
class RequestGlobalOptions {
|
|
46
|
-
}
|
|
47
|
-
RequestGlobalOptions.httpsProxy = undefined;
|
|
48
|
-
/** Creates an agent for any user defined proxy using the supplied additional options. Returns undefined if user hasn't defined a proxy.
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
RequestGlobalOptions.createHttpsProxy = (_additionalOptions) => undefined;
|
|
52
|
-
RequestGlobalOptions.maxRetries = 4;
|
|
53
|
-
RequestGlobalOptions.timeout = {
|
|
54
|
-
deadline: 25000,
|
|
55
|
-
response: 10000,
|
|
56
|
-
};
|
|
57
|
-
// Assume application is online or offline. This hint skip retry/timeout
|
|
58
|
-
RequestGlobalOptions.online = true;
|
|
59
|
-
exports.RequestGlobalOptions = RequestGlobalOptions;
|
|
60
|
-
/** 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)
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.request = exports.HttpResponseError = void 0;
|
|
8
|
+
/** Error object that's thrown if the status is *not* in the range of 200-299 (inclusive).
|
|
61
9
|
* @internal
|
|
62
10
|
*/
|
|
63
|
-
class
|
|
64
|
-
constructor(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* @internal
|
|
72
|
-
*/
|
|
73
|
-
static parse(response, log = true) {
|
|
74
|
-
const error = new ResponseError(ResponseError.parseHttpStatus(response.statusType));
|
|
75
|
-
if (!response) {
|
|
76
|
-
error.message = "Couldn't get response object.";
|
|
77
|
-
return error;
|
|
78
|
-
}
|
|
79
|
-
if (response.response) {
|
|
80
|
-
if (response.response.error) {
|
|
81
|
-
error.name = response.response.error.name || error.name;
|
|
82
|
-
error.description = response.response.error.message;
|
|
83
|
-
}
|
|
84
|
-
if (response.response.res) {
|
|
85
|
-
error.message = response.response.res.statusMessage;
|
|
86
|
-
}
|
|
87
|
-
if (response.response.body && Object.keys(response.response.body).length > 0) {
|
|
88
|
-
error._data = {};
|
|
89
|
-
deepAssign.default(error._data, response.response.body);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
error._data = response.response.text;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
error.status = response.status || response.statusCode;
|
|
96
|
-
error.name = response.code || response.name || error.name;
|
|
97
|
-
error.message = error.message || response.message || response.statusMessage;
|
|
98
|
-
if (log)
|
|
99
|
-
error.log();
|
|
100
|
-
return error;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Decides whether request should be retried or not
|
|
104
|
-
* @param error Error returned by request
|
|
105
|
-
* @param response Response returned by request
|
|
106
|
-
* @internal
|
|
107
|
-
*/
|
|
108
|
-
static shouldRetry(error, response) {
|
|
109
|
-
if (error !== undefined && error !== null) {
|
|
110
|
-
if ((error.status === undefined || error.status === null) && (error.res === undefined || error.res === null)) {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return (response !== undefined && response.statusType === core_bentley_1.HttpStatus.ServerError);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @internal
|
|
118
|
-
*/
|
|
119
|
-
static parseHttpStatus(statusType) {
|
|
120
|
-
switch (statusType) {
|
|
121
|
-
case 1:
|
|
122
|
-
return core_bentley_1.HttpStatus.Info;
|
|
123
|
-
case 2:
|
|
124
|
-
return core_bentley_1.HttpStatus.Success;
|
|
125
|
-
case 3:
|
|
126
|
-
return core_bentley_1.HttpStatus.Redirection;
|
|
127
|
-
case 4:
|
|
128
|
-
return core_bentley_1.HttpStatus.ClientError;
|
|
129
|
-
case 5:
|
|
130
|
-
return core_bentley_1.HttpStatus.ServerError;
|
|
131
|
-
default:
|
|
132
|
-
return core_bentley_1.HttpStatus.Success;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* @internal
|
|
137
|
-
*/
|
|
138
|
-
logMessage() {
|
|
139
|
-
return `${this.status} ${this.name}: ${this.message}`;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Logs this error
|
|
143
|
-
* @internal
|
|
144
|
-
*/
|
|
145
|
-
log() {
|
|
146
|
-
core_bentley_1.Logger.logError(loggerCategory, this.logMessage(), () => this.getMetaData());
|
|
11
|
+
class HttpResponseError extends Error {
|
|
12
|
+
constructor(status, responseText) {
|
|
13
|
+
let message = `HTTP response status code: ${status}.`;
|
|
14
|
+
if (responseText)
|
|
15
|
+
message += ` Response body: ${responseText}`;
|
|
16
|
+
super(message);
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.responseText = responseText;
|
|
147
19
|
}
|
|
148
20
|
}
|
|
149
|
-
exports.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const retries = typeof options.retries === "undefined" ? RequestGlobalOptions.maxRetries : options.retries;
|
|
176
|
-
sareq = sareq.retry(retries, options.retryCallback);
|
|
177
|
-
if (core_bentley_1.Logger.isEnabled(loggerCategory, core_bentley_1.LogLevel.Trace))
|
|
178
|
-
sareq = sareq.use(logRequest);
|
|
179
|
-
if (options.headers)
|
|
180
|
-
sareq = sareq.set(options.headers);
|
|
181
|
-
let queryStr = "";
|
|
182
|
-
let fullUrl = "";
|
|
183
|
-
if (options.qs && Object.keys(options.qs).length > 0) {
|
|
184
|
-
const stringifyOptions = { delimiter: "&", encode: false };
|
|
185
|
-
queryStr = (0, qs_1.stringify)(options.qs, stringifyOptions);
|
|
186
|
-
sareq = sareq.query(queryStr);
|
|
187
|
-
fullUrl = `${url}?${queryStr}`;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
fullUrl = url;
|
|
191
|
-
}
|
|
192
|
-
core_bentley_1.Logger.logInfo(loggerCategory, fullUrl);
|
|
193
|
-
if (options.auth)
|
|
194
|
-
sareq = sareq.auth(options.auth.user, options.auth.password);
|
|
195
|
-
if (options.accept)
|
|
196
|
-
sareq = sareq.accept(options.accept);
|
|
197
|
-
if (options.body)
|
|
198
|
-
sareq = sareq.send(options.body);
|
|
199
|
-
if (options.timeout)
|
|
200
|
-
sareq = sareq.timeout(options.timeout);
|
|
201
|
-
else
|
|
202
|
-
sareq = sareq.timeout(RequestGlobalOptions.timeout);
|
|
203
|
-
if (options.responseType)
|
|
204
|
-
sareq = sareq.responseType(options.responseType);
|
|
205
|
-
if (options.redirects)
|
|
206
|
-
sareq = sareq.redirects(options.redirects);
|
|
207
|
-
else
|
|
208
|
-
sareq = sareq.redirects(0);
|
|
209
|
-
if (options.buffer)
|
|
210
|
-
sareq = sareq.buffer(options.buffer);
|
|
211
|
-
if (options.parser)
|
|
212
|
-
sareq = sareq.parse(options.parser);
|
|
213
|
-
/** Default to any globally supplied proxy, unless an agent is specified in this call */
|
|
214
|
-
if (options.agent)
|
|
215
|
-
sareq = sareq.agent(options.agent);
|
|
216
|
-
else if (RequestGlobalOptions.httpsProxy)
|
|
217
|
-
sareq = sareq.agent(RequestGlobalOptions.httpsProxy);
|
|
218
|
-
if (options.progressCallback) {
|
|
219
|
-
sareq = sareq.on("progress", (event) => {
|
|
220
|
-
if (event) {
|
|
221
|
-
options.progressCallback({
|
|
222
|
-
loaded: event.loaded,
|
|
223
|
-
total: event.total,
|
|
224
|
-
percent: event.percent,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
const errorCallback = options.errorCallback ? options.errorCallback : ResponseError.parse;
|
|
230
|
-
if (options.readStream) {
|
|
231
|
-
if (typeof window !== "undefined")
|
|
232
|
-
throw new Error("This option is not supported on browsers");
|
|
233
|
-
return new Promise((resolve, reject) => {
|
|
234
|
-
sareq = sareq.type("blob");
|
|
235
|
-
options
|
|
236
|
-
.readStream
|
|
237
|
-
.pipe(sareq)
|
|
238
|
-
.on("error", (error) => {
|
|
239
|
-
const parsedError = errorCallback(error);
|
|
240
|
-
reject(parsedError);
|
|
241
|
-
})
|
|
242
|
-
.on("end", () => {
|
|
243
|
-
const retResponse = {
|
|
244
|
-
status: 201,
|
|
245
|
-
header: undefined,
|
|
246
|
-
body: undefined,
|
|
247
|
-
text: undefined,
|
|
248
|
-
};
|
|
249
|
-
resolve(retResponse);
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
if (options.stream) {
|
|
254
|
-
if (typeof window !== "undefined")
|
|
255
|
-
throw new Error("This option is not supported on browsers");
|
|
256
|
-
return new Promise((resolve, reject) => {
|
|
257
|
-
sareq
|
|
258
|
-
.on("response", (res) => {
|
|
259
|
-
if (res.statusCode !== 200) {
|
|
260
|
-
const parsedError = errorCallback(res);
|
|
261
|
-
reject(parsedError);
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
})
|
|
265
|
-
.pipe(options.stream)
|
|
266
|
-
.on("error", (error) => {
|
|
267
|
-
const parsedError = errorCallback(error);
|
|
268
|
-
reject(parsedError);
|
|
269
|
-
})
|
|
270
|
-
.on("finish", () => {
|
|
271
|
-
const retResponse = {
|
|
272
|
-
status: 200,
|
|
273
|
-
header: undefined,
|
|
274
|
-
body: undefined,
|
|
275
|
-
text: undefined,
|
|
276
|
-
};
|
|
277
|
-
resolve(retResponse);
|
|
278
|
-
});
|
|
279
|
-
});
|
|
21
|
+
exports.HttpResponseError = HttpResponseError;
|
|
22
|
+
/** @internal */
|
|
23
|
+
async function request(url, responseType, options) {
|
|
24
|
+
const headers = {
|
|
25
|
+
...options?.headers,
|
|
26
|
+
};
|
|
27
|
+
if (options?.auth)
|
|
28
|
+
headers.authorization = `Basic ${window.btoa(`${options.auth.user}:${options.auth.password}`)}`;
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
if (options?.timeout)
|
|
31
|
+
setTimeout(() => controller.abort(), options.timeout);
|
|
32
|
+
const fetchOptions = {
|
|
33
|
+
headers,
|
|
34
|
+
signal: controller.signal,
|
|
35
|
+
};
|
|
36
|
+
const fetchFunc = async () => fetch(url, fetchOptions);
|
|
37
|
+
const response = await fetchWithRetry(fetchFunc, options?.retryCount ?? 4);
|
|
38
|
+
if (!response.ok)
|
|
39
|
+
throw new HttpResponseError(response.status, await response.text());
|
|
40
|
+
switch (responseType) {
|
|
41
|
+
case "arraybuffer":
|
|
42
|
+
return response.arrayBuffer();
|
|
43
|
+
case "json":
|
|
44
|
+
return response.json();
|
|
45
|
+
case "text":
|
|
46
|
+
return response.text();
|
|
280
47
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
* Javascript's fetch returns status.OK if error is between 200-299 inclusive, and doesn't reject in this case.
|
|
285
|
-
* Fetch only rejects if there's some network issue (permissions issue or similar)
|
|
286
|
-
* Superagent rejects network issues, and errors outside the range of 200-299. We are currently using
|
|
287
|
-
* superagent, but may eventually switch to JavaScript's fetch library.
|
|
288
|
-
*/
|
|
48
|
+
}
|
|
49
|
+
exports.request = request;
|
|
50
|
+
async function fetchWithRetry(fetchFunc, remainingRetries) {
|
|
289
51
|
try {
|
|
290
|
-
|
|
291
|
-
const retResponse = {
|
|
292
|
-
body: response.body,
|
|
293
|
-
text: response.text,
|
|
294
|
-
header: response.header,
|
|
295
|
-
status: response.status,
|
|
296
|
-
};
|
|
297
|
-
return retResponse;
|
|
52
|
+
return await fetchFunc();
|
|
298
53
|
}
|
|
299
54
|
catch (error) {
|
|
300
|
-
|
|
301
|
-
|
|
55
|
+
if (error instanceof Error && error.name === "AbortError")
|
|
56
|
+
throw error;
|
|
57
|
+
if (remainingRetries === 0)
|
|
58
|
+
throw error;
|
|
59
|
+
return fetchWithRetry(fetchFunc, --remainingRetries);
|
|
302
60
|
}
|
|
303
61
|
}
|
|
304
|
-
exports.request = request;
|
|
305
|
-
/**
|
|
306
|
-
* fetch json from HTTP request
|
|
307
|
-
* @param url server URL to address the request
|
|
308
|
-
* @internal
|
|
309
|
-
*/
|
|
310
|
-
async function getJson(url) {
|
|
311
|
-
const options = {
|
|
312
|
-
method: "GET",
|
|
313
|
-
responseType: "json",
|
|
314
|
-
};
|
|
315
|
-
const data = await request(url, options);
|
|
316
|
-
return data.body;
|
|
317
|
-
}
|
|
318
|
-
exports.getJson = getJson;
|
|
319
62
|
//# sourceMappingURL=Request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/request/Request.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,wDAA0C;AAE1C,2BAAkD;AAClD,sDAAwC;AACxC,sDAAsG;AACtG,sEAAmE;AAEnE,MAAM,cAAc,GAAW,+CAAsB,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AAM,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 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"]}
|
|
1
|
+
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/request/Request.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAQ/F;;GAEG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAE1C,YACS,MAAc,EACd,YAAqB;QAE5B,IAAI,OAAO,GAAG,8BAA8B,MAAM,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OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzB,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;KAC1B;AACH,CAAC;AA/BD,0BA+BC;AAED,KAAK,UAAU,cAAc,CAAC,SAAkC,EAAE,gBAAwB;IACxF,IAAI;QACF,OAAO,MAAM,SAAS,EAAE,CAAC;KAC1B;IAAC,OAAO,KAAc,EAAE;QACvB,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY;YACvD,MAAM,KAAK,CAAC;QAEd,IAAI,gBAAgB,KAAK,CAAC;YACxB,MAAM,KAAK,CAAC;QAEd,OAAO,cAAc,CAAC,SAAS,EAAE,EAAE,gBAAgB,CAAC,CAAC;KACtD;AACH,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\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/** Error object that's thrown if the status is *not* in the range of 200-299 (inclusive).\r\n * @internal\r\n */\r\nexport class HttpResponseError extends Error {\r\n\r\n public constructor(\r\n public status: number,\r\n public responseText?: string,\r\n ) {\r\n let message = `HTTP response status code: ${status}.`;\r\n if (responseText)\r\n message += ` Response body: ${responseText}`;\r\n\r\n super(message);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport interface RequestOptions {\r\n retryCount?: number;\r\n headers?: any;\r\n timeout?: number;\r\n auth?: RequestBasicCredentials;\r\n}\r\n\r\n/** @internal */\r\nexport async function request(url: string, responseType: \"arraybuffer\", options?: RequestOptions): Promise<ArrayBuffer>;\r\n\r\n/** @internal */\r\nexport async function request(url: string, responseType: \"json\", options?: RequestOptions): Promise<any>;\r\n\r\n/** @internal */\r\nexport async function request(url: string, responseType: \"text\", options?: RequestOptions): Promise<string>;\r\n\r\n/** @internal */\r\nexport async function request(url: string, responseType: \"arraybuffer\" | \"json\" | \"text\", options?: RequestOptions): Promise<any> {\r\n const headers: any = {\r\n ...options?.headers,\r\n };\r\n\r\n if (options?.auth)\r\n headers.authorization = `Basic ${window.btoa(`${options.auth.user}:${options.auth.password}`)}`;\r\n\r\n const controller = new AbortController();\r\n if (options?.timeout)\r\n setTimeout(() => controller.abort(), options.timeout);\r\n\r\n const fetchOptions: RequestInit = {\r\n headers,\r\n signal: controller.signal,\r\n };\r\n\r\n const fetchFunc = async () => fetch(url, fetchOptions);\r\n const response = await fetchWithRetry(fetchFunc, options?.retryCount ?? 4);\r\n\r\n if (!response.ok)\r\n throw new HttpResponseError(response.status, await response.text());\r\n\r\n switch (responseType) {\r\n case \"arraybuffer\":\r\n return response.arrayBuffer();\r\n case \"json\":\r\n return response.json();\r\n case \"text\":\r\n return response.text();\r\n }\r\n}\r\n\r\nasync function fetchWithRetry(fetchFunc: () => Promise<Response>, remainingRetries: number): Promise<Response> {\r\n try {\r\n return await fetchFunc();\r\n } catch (error: unknown) {\r\n if (error instanceof Error && error.name === \"AbortError\")\r\n throw error;\r\n\r\n if (remainingRetries === 0)\r\n throw error;\r\n\r\n return fetchWithRetry(fetchFunc, --remainingRetries);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n * @deprecated in 4.0. Use [[DownloadProgressInfo]].\r\n */\r\nexport interface ProgressInfo {\r\n percent?: number;\r\n total?: number;\r\n loaded: number;\r\n}\r\n\r\n/**\r\n * @internal\r\n * @deprecated in 4.0. Use [[OnDownloadProgress]].\r\n */\r\n// eslint-disable-next-line deprecation/deprecation\r\nexport type ProgressCallback = (progress: ProgressInfo) => void;\r\n"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @module Tiles
|
|
3
3
|
*/
|
|
4
4
|
import { ByteStream, Id64String } from "@itwin/core-bentley";
|
|
5
|
+
import { Point3d } from "@itwin/core-geometry";
|
|
5
6
|
import { ElementAlignedBox3d } from "@itwin/core-common";
|
|
6
7
|
import { IModelConnection } from "../IModelConnection";
|
|
7
8
|
import { RenderGraphic } from "../render/RenderGraphic";
|
|
@@ -9,5 +10,8 @@ import { RenderSystem } from "../render/RenderSystem";
|
|
|
9
10
|
/** Deserialize a point cloud tile and return it as a RenderGraphic.
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
|
-
export declare function readPointCloudTileContent(stream: ByteStream, iModel: IModelConnection, modelId: Id64String, _is3d: boolean, range: ElementAlignedBox3d, system: RenderSystem): Promise<
|
|
13
|
+
export declare function readPointCloudTileContent(stream: ByteStream, iModel: IModelConnection, modelId: Id64String, _is3d: boolean, range: ElementAlignedBox3d, system: RenderSystem): Promise<{
|
|
14
|
+
graphic: RenderGraphic | undefined;
|
|
15
|
+
rtcCenter: Point3d | undefined;
|
|
16
|
+
}>;
|
|
13
17
|
//# sourceMappingURL=PntsReader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PntsReader.d.ts","sourceRoot":"","sources":["../../../src/tile/PntsReader.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAwB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"PntsReader.d.ts","sourceRoot":"","sources":["../../../src/tile/PntsReader.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAwB,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,OAAO,EAAW,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAa,mBAAmB,EAA4F,MAAM,oBAAoB,CAAC;AAE9J,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAyLtD;;GAEG;AACH,wBAAsB,yBAAyB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,GAAG,SAAS,CAAC;IAAC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,CAAC,CAiFpQ"}
|
|
@@ -80,22 +80,10 @@ function readPnts(stream, dataOffset, pnts) {
|
|
|
80
80
|
points = new Uint16Array(stream.arrayBuffer, dataOffset + qpos.byteOffset, 3 * nPts);
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
range.extendXYZ(fpts[i], fpts[i + 1], fpts[i + 2]);
|
|
88
|
-
params = core_common_1.QParams3d.fromRange(range);
|
|
89
|
-
const qpt = new core_common_1.QPoint3d();
|
|
90
|
-
const fpt = new core_geometry_1.Point3d();
|
|
91
|
-
points = new Uint16Array(3 * nPts);
|
|
92
|
-
for (let i = 0; i < nCoords; i += 3) {
|
|
93
|
-
fpt.set(fpts[i], fpts[i + 1], fpts[i + 2]);
|
|
94
|
-
qpt.init(fpt, params);
|
|
95
|
-
points[i] = qpt.x;
|
|
96
|
-
points[i + 1] = qpt.y;
|
|
97
|
-
points[i + 2] = qpt.z;
|
|
98
|
-
}
|
|
83
|
+
const qOrigin = new core_geometry_1.Point3d(0, 0, 0);
|
|
84
|
+
const qScale = new core_geometry_1.Point3d(1, 1, 1);
|
|
85
|
+
params = core_common_1.QParams3d.fromOriginAndScale(qOrigin, qScale);
|
|
86
|
+
points = new Float32Array(stream.arrayBuffer, dataOffset + pnts.POSITION.byteOffset, 3 * nPts);
|
|
99
87
|
}
|
|
100
88
|
const colors = readPntsColors(stream, dataOffset, pnts);
|
|
101
89
|
return { params, points, colors };
|
|
@@ -157,15 +145,17 @@ async function decodeDracoPointCloud(buf) {
|
|
|
157
145
|
* @internal
|
|
158
146
|
*/
|
|
159
147
|
async function readPointCloudTileContent(stream, iModel, modelId, _is3d, range, system) {
|
|
148
|
+
let graphic;
|
|
149
|
+
let rtcCenter;
|
|
160
150
|
const header = new core_common_1.PntsHeader(stream);
|
|
161
151
|
if (!header.isValid)
|
|
162
|
-
return
|
|
152
|
+
return { graphic, rtcCenter };
|
|
163
153
|
const featureTableJsonOffset = stream.curPos;
|
|
164
154
|
const featureStrData = stream.nextBytes(header.featureTableJsonLength);
|
|
165
155
|
const featureStr = (0, core_bentley_1.utf8ToString)(featureStrData);
|
|
166
156
|
const featureValue = JSON.parse(featureStr);
|
|
167
157
|
if (undefined === featureValue)
|
|
168
|
-
return
|
|
158
|
+
return { graphic, rtcCenter };
|
|
169
159
|
let props;
|
|
170
160
|
const dataOffset = featureTableJsonOffset + header.featureTableJsonLength;
|
|
171
161
|
const draco = featureValue.extensions ? featureValue.extensions["3DTILES_draco_point_compression"] : undefined;
|
|
@@ -182,9 +172,14 @@ async function readPointCloudTileContent(stream, iModel, modelId, _is3d, range,
|
|
|
182
172
|
props = readPnts(stream, dataOffset, featureValue);
|
|
183
173
|
}
|
|
184
174
|
if (!props)
|
|
185
|
-
return
|
|
186
|
-
|
|
187
|
-
|
|
175
|
+
return { graphic, rtcCenter };
|
|
176
|
+
let batchRange = range;
|
|
177
|
+
if (featureValue.RTC_CENTER) {
|
|
178
|
+
rtcCenter = core_geometry_1.Point3d.fromJSON(featureValue.RTC_CENTER);
|
|
179
|
+
batchRange = range.clone();
|
|
180
|
+
batchRange.low.minus(rtcCenter, batchRange.low);
|
|
181
|
+
batchRange.high.minus(rtcCenter, batchRange.high);
|
|
182
|
+
}
|
|
188
183
|
if (!props.colors) {
|
|
189
184
|
// ###TODO we really should support uniform color instead of allocating an RGB value per point...
|
|
190
185
|
props.colors = new Uint8Array(3 * featureValue.POINTS_LENGTH);
|
|
@@ -205,8 +200,16 @@ async function readPointCloudTileContent(stream, iModel, modelId, _is3d, range,
|
|
|
205
200
|
const featureTable = new core_common_1.FeatureTable(1, modelId, core_common_1.BatchType.Primary);
|
|
206
201
|
const features = new MeshPrimitives_1.Mesh.Features(featureTable);
|
|
207
202
|
features.add(new core_common_1.Feature(modelId), 1);
|
|
208
|
-
|
|
209
|
-
|
|
203
|
+
let params = props.params;
|
|
204
|
+
if (props.points instanceof Float32Array) {
|
|
205
|
+
// we don't have a true range for unquantized points, so calc one here for voxelSize
|
|
206
|
+
const rng = core_geometry_1.Range3d.createNull();
|
|
207
|
+
for (let i = 0; i < props.points.length; i += 3)
|
|
208
|
+
rng.extendXYZ(props.points[i], props.points[i + 1], props.points[i + 2]);
|
|
209
|
+
params = core_common_1.QParams3d.fromRange(rng);
|
|
210
|
+
}
|
|
211
|
+
const voxelSize = params.rangeDiagonal.maxAbs() / 256;
|
|
212
|
+
graphic = system.createPointCloud({
|
|
210
213
|
positions: props.points,
|
|
211
214
|
qparams: props.params,
|
|
212
215
|
colors: props.colors,
|
|
@@ -214,8 +217,8 @@ async function readPointCloudTileContent(stream, iModel, modelId, _is3d, range,
|
|
|
214
217
|
voxelSize,
|
|
215
218
|
colorFormat: "rgb",
|
|
216
219
|
}, iModel);
|
|
217
|
-
|
|
218
|
-
return
|
|
220
|
+
graphic = system.createBatch(graphic, core_common_1.PackedFeatureTable.pack(featureTable), batchRange);
|
|
221
|
+
return { graphic, rtcCenter };
|
|
219
222
|
}
|
|
220
223
|
exports.readPointCloudTileContent = readPointCloudTileContent;
|
|
221
224
|
//# sourceMappingURL=PntsReader.js.map
|