@itwin/core-mobile 4.10.0-dev.31 → 4.10.0-dev.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/backend/MobileFileHandler.d.ts +0 -1
- package/lib/cjs/backend/MobileFileHandler.d.ts.map +1 -1
- package/lib/cjs/backend/MobileRpcServer.js +2 -2
- package/lib/cjs/backend/MobileRpcServer.js.map +1 -1
- package/lib/cjs/backend/Request.d.ts +0 -1
- package/lib/cjs/backend/Request.d.ts.map +1 -1
- package/lib/cjs/backend/Request.js +3 -3
- package/lib/cjs/backend/Request.js.map +1 -1
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileFileHandler.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileFileHandler.ts"],"names":[],"mappings":"AAIA;;GAEG
|
|
1
|
+
{"version":3,"file":"MobileFileHandler.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileFileHandler.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAU,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAyC,MAAM,WAAW,CAAC;AAUpF;;IAEI;AACJ,MAAM,WAAW,aAAa;IAC5B,sDAAsD;IACtD,MAAM,EAAE,MAAM,OAAO,CAAC;CACvB;AAED;;IAEI;AACJ,qBAAa,kBAAmB,SAAQ,YAAY;gBAC/B,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,mBAAmB;CAI3F;AAED;;IAEI;AACJ,qBAAa,cAAe,SAAQ,YAAY;gBAC3B,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,mBAAmB;CAI3F;AAED;;IAEI;AACJ,qBAAa,aAAc,SAAQ,YA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,EAAE,MAAM,EAAE,GAAG,MAAM;CAGxC"}
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.MobileRpcServer = void 0;
|
|
8
|
+
exports.setupMobileRpc = setupMobileRpc;
|
|
8
9
|
const ws = require("ws");
|
|
9
10
|
const core_common_1 = require("@itwin/core-common");
|
|
10
11
|
const MobileRpcProtocol_1 = require("../common/MobileRpcProtocol");
|
|
@@ -178,5 +179,4 @@ function setupMobileRpc() {
|
|
|
178
179
|
MobileRpcProtocol_1.MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;
|
|
179
180
|
mobileReady = true;
|
|
180
181
|
}
|
|
181
|
-
exports.setupMobileRpc = setupMobileRpc;
|
|
182
182
|
//# sourceMappingURL=MobileRpcServer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,oDAAgE;AAChE,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAsD;AAStD,IAAI,KAA8B,CAAC;AAEnC,gBAAgB;AAChB,MAAa,eAAe;IAgB1B,YAA2B,mBAA2D,SAAS;QAApE,qBAAgB,GAAhB,gBAAgB,CAAoD;QAC7F;;;;;;;;WAQG;QACH,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,yCAAsB,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CA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H,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,GAAG,IAAI,eAAe,CAAC,eAAe,CAAC,CAAC;QAC9C,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5B,YAAY,GAAG,SAAS,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;QAC1C,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,WAAW,EAAE,CAAC;YAC1C,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5B,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,qCAAiB,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;IAChE,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AApED,wCAoEC","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\nimport * as ws from \"ws\";\r\nimport { BentleyStatus, IModelError } from \"@itwin/core-common\";\r\nimport { MobileRpcGateway, MobileRpcProtocol } from \"../common/MobileRpcProtocol\";\r\nimport { MobileRpcConfiguration } from \"../common/MobileRpcManager\";\r\nimport { MobileHost } from \"./MobileHost\";\r\nimport { ProcessDetector } from \"@itwin/core-bentley\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\ninterface MobileAddon {\r\n notifyListening: (port: number) => void;\r\n registerDeviceImpl: () => void;\r\n}\r\n\r\nlet addon: MobileAddon | undefined;\r\n\r\n/** @internal */\r\nexport class MobileRpcServer {\r\n private static _nextId = -1;\r\n\r\n public static interop: MobileRpcGateway = {\r\n handler: (_payload: ArrayBuffer | string) => { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); },\r\n sendString: (_message: string, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\r\n sendBinary: (_message: Uint8Array, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\r\n port: 0,\r\n connectionId: 0,\r\n };\r\n\r\n private _server: ws.Server;\r\n private _connection: ws | undefined;\r\n private _port: number;\r\n private _connectionId: number;\r\n private _pingTimer: NodeJS.Timeout;\r\n public constructor(private _pendingMessages: Array<string | Uint8Array> | undefined = undefined) {\r\n /* _pingTime is a fix for ios/mobile case where when the app moves into foreground from\r\n * background backend restart ws.Server and then notify frontend to reconnect. But ws.Server\r\n * listening event is not fired as node yield to kevent and wait for some io event to happen.\r\n * This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we\r\n * create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.\r\n * This allow listening event to go through quickly (max 5ms). Once the listening event occur we\r\n * clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally\r\n * be effective\r\n */\r\n this._pingTimer = setInterval(() => { }, 5);\r\n this._port = MobileRpcConfiguration.setup.obtainPort();\r\n this._server = new ws.Server({ port: this._port });\r\n this._connectionId = ++MobileRpcServer._nextId;\r\n MobileRpcServer.interop.connectionId = this._connectionId;\r\n this._onListening();\r\n this._onConnection();\r\n }\r\n\r\n private _onListening() {\r\n this._server.on(\"listening\", () => {\r\n const address = this._server.address() as ws.AddressInfo;\r\n this._port = address.port;\r\n clearInterval(this._pingTimer);\r\n this._notifyListening();\r\n });\r\n }\r\n\r\n private _notifyListening() {\r\n MobileRpcServer.interop.port = this._port;\r\n\r\n if (addon) {\r\n addon.notifyListening(this._port);\r\n }\r\n\r\n if (this._connectionId !== 0) {\r\n MobileHost.reconnect(this._port);\r\n }\r\n }\r\n\r\n private _onConnection() {\r\n this._server.on(\"connection\", (connection) => {\r\n this._connection = connection;\r\n this._connection.on(\"message\", (data) => this._onConnectionMessage(data));\r\n this._createSender();\r\n this._sendPending();\r\n (global as any).__iTwinJsRpcReady = true;\r\n MobileHost.onConnected.raiseEvent();\r\n });\r\n }\r\n\r\n private _createSender() {\r\n const sender = (message: string | Uint8Array, connectionId: number) => {\r\n if (connectionId !== this._connectionId) {\r\n return;\r\n }\r\n\r\n this._connection!.send(message, (err) => {\r\n if (err) {\r\n throw err;\r\n }\r\n });\r\n };\r\n\r\n MobileRpcServer.interop.sendString = sender;\r\n MobileRpcServer.interop.sendBinary = sender;\r\n }\r\n\r\n private _sendPending() {\r\n if (this._pendingMessages === undefined)\r\n return;\r\n\r\n for (const message of this._pendingMessages) {\r\n this._connection!.send(message, (err) => {\r\n if (err) {\r\n throw err;\r\n }\r\n });\r\n }\r\n this._pendingMessages.length = 0;\r\n }\r\n\r\n private _onConnectionMessage(data: ws.Data) {\r\n let message = data;\r\n if (Array.isArray(message)) {\r\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported data type\");\r\n }\r\n\r\n if (Buffer.isBuffer(message)) {\r\n if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {\r\n message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);\r\n } else {\r\n message = message.buffer;\r\n }\r\n }\r\n\r\n MobileRpcServer.interop.handler(message, this._connectionId);\r\n }\r\n\r\n public dispose() {\r\n clearInterval(this._pingTimer);\r\n if (this._connection) {\r\n MobileRpcServer.interop.sendString = () => { };\r\n MobileRpcServer.interop.sendBinary = () => { };\r\n this._connection.close();\r\n }\r\n\r\n this._server.close();\r\n }\r\n}\r\n\r\nlet mobileReady = false;\r\nlet hasSuspended = false;\r\n\r\nexport function setupMobileRpc() {\r\n if (mobileReady) {\r\n return;\r\n }\r\n\r\n if (ProcessDetector.isMobileAppBackend) {\r\n addon = (process as any)._linkedBinding(\"iModelJsMobile\");\r\n addon?.registerDeviceImpl();\r\n }\r\n\r\n let server: MobileRpcServer | null = new MobileRpcServer();\r\n\r\n /* The UV event loop (internal to node) is retained by handles,\r\n such as those created for setInterval/setTimeout and client/server connections.\r\n In a simple app, the RPC server may be the only handle retaining the UV loop.\r\n Thus, we install a temporary timer on suspend to prevent the loop from exiting prematurely.\r\n */\r\n let retainUvLoop: NodeJS.Timeout | undefined;\r\n const pendingMessages: Array<string | Uint8Array> = [];\r\n\r\n function usePendingSender() {\r\n const sender = (message: string | Uint8Array, _connectionId: number) => {\r\n pendingMessages.push(message);\r\n };\r\n MobileRpcServer.interop.sendString = sender;\r\n MobileRpcServer.interop.sendBinary = sender;\r\n }\r\n\r\n MobileHost.onEnterBackground.addListener(() => {\r\n hasSuspended = true;\r\n\r\n if (server === null) {\r\n return;\r\n }\r\n\r\n retainUvLoop = setInterval(() => { }, 1000);\r\n server.dispose();\r\n usePendingSender();\r\n server = null;\r\n (global as any).__iTwinJsRpcReady = false;\r\n });\r\n\r\n MobileHost.onEnterForeground.addListener(() => {\r\n if (!hasSuspended) {\r\n return;\r\n }\r\n\r\n server = new MobileRpcServer(pendingMessages);\r\n clearInterval(retainUvLoop);\r\n retainUvLoop = undefined;\r\n });\r\n\r\n MobileHost.onWillTerminate.addListener(() => {\r\n if (typeof (retainUvLoop) !== \"undefined\") {\r\n clearInterval(retainUvLoop);\r\n retainUvLoop = undefined;\r\n }\r\n\r\n if (server === null) {\r\n return;\r\n }\r\n\r\n server.dispose();\r\n server = null;\r\n });\r\n\r\n MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;\r\n mobileReady = true;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAqJ/F,wCAoEC;AAvND,yBAAyB;AACzB,oDAAgE;AAChE,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC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;IAC9C,CAAC;IAED,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,YAAY,GAAG,IAAI,CAAC;QAEpB,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,gBAAgB,EAAE,CAAC;QACnB,MAAM,GAAG,IAAI,CAAC;QACb,MAAc,CAAC,iBAAiB,GAAG,KAAK,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,GAAG,IAAI,eAAe,CAAC,eAAe,CAAC,CAAC;QAC9C,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5B,YAAY,GAAG,SAAS,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;QAC1C,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,WAAW,EAAE,CAAC;YAC1C,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5B,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,qCAAiB,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;IAChE,WAAW,GAAG,IAAI,CAAC;AACrB,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\nimport * as ws from \"ws\";\r\nimport { BentleyStatus, IModelError } from \"@itwin/core-common\";\r\nimport { MobileRpcGateway, MobileRpcProtocol } from \"../common/MobileRpcProtocol\";\r\nimport { MobileRpcConfiguration } from \"../common/MobileRpcManager\";\r\nimport { MobileHost } from \"./MobileHost\";\r\nimport { ProcessDetector } from \"@itwin/core-bentley\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\ninterface MobileAddon {\r\n notifyListening: (port: number) => void;\r\n registerDeviceImpl: () => void;\r\n}\r\n\r\nlet addon: MobileAddon | undefined;\r\n\r\n/** @internal */\r\nexport class MobileRpcServer {\r\n private static _nextId = -1;\r\n\r\n public static interop: MobileRpcGateway = {\r\n handler: (_payload: ArrayBuffer | string) => { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); },\r\n sendString: (_message: string, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\r\n sendBinary: (_message: Uint8Array, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\r\n port: 0,\r\n connectionId: 0,\r\n };\r\n\r\n private _server: ws.Server;\r\n private _connection: ws | undefined;\r\n private _port: number;\r\n private _connectionId: number;\r\n private _pingTimer: NodeJS.Timeout;\r\n public constructor(private _pendingMessages: Array<string | Uint8Array> | undefined = undefined) {\r\n /* _pingTime is a fix for ios/mobile case where when the app moves into foreground from\r\n * background backend restart ws.Server and then notify frontend to reconnect. But ws.Server\r\n * listening event is not fired as node yield to kevent and wait for some io event to happen.\r\n * This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we\r\n * create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.\r\n * This allow listening event to go through quickly (max 5ms). Once the listening event occur we\r\n * clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally\r\n * be effective\r\n */\r\n this._pingTimer = setInterval(() => { }, 5);\r\n this._port = MobileRpcConfiguration.setup.obtainPort();\r\n this._server = new ws.Server({ port: this._port });\r\n this._connectionId = ++MobileRpcServer._nextId;\r\n MobileRpcServer.interop.connectionId = this._connectionId;\r\n this._onListening();\r\n this._onConnection();\r\n }\r\n\r\n private _onListening() {\r\n this._server.on(\"listening\", () => {\r\n const address = this._server.address() as ws.AddressInfo;\r\n this._port = address.port;\r\n clearInterval(this._pingTimer);\r\n this._notifyListening();\r\n });\r\n }\r\n\r\n private _notifyListening() {\r\n MobileRpcServer.interop.port = this._port;\r\n\r\n if (addon) {\r\n addon.notifyListening(this._port);\r\n }\r\n\r\n if (this._connectionId !== 0) {\r\n MobileHost.reconnect(this._port);\r\n }\r\n }\r\n\r\n private _onConnection() {\r\n this._server.on(\"connection\", (connection) => {\r\n this._connection = connection;\r\n this._connection.on(\"message\", (data) => this._onConnectionMessage(data));\r\n this._createSender();\r\n this._sendPending();\r\n (global as any).__iTwinJsRpcReady = true;\r\n MobileHost.onConnected.raiseEvent();\r\n });\r\n }\r\n\r\n private _createSender() {\r\n const sender = (message: string | Uint8Array, connectionId: number) => {\r\n if (connectionId !== this._connectionId) {\r\n return;\r\n }\r\n\r\n this._connection!.send(message, (err) => {\r\n if (err) {\r\n throw err;\r\n }\r\n });\r\n };\r\n\r\n MobileRpcServer.interop.sendString = sender;\r\n MobileRpcServer.interop.sendBinary = sender;\r\n }\r\n\r\n private _sendPending() {\r\n if (this._pendingMessages === undefined)\r\n return;\r\n\r\n for (const message of this._pendingMessages) {\r\n this._connection!.send(message, (err) => {\r\n if (err) {\r\n throw err;\r\n }\r\n });\r\n }\r\n this._pendingMessages.length = 0;\r\n }\r\n\r\n private _onConnectionMessage(data: ws.Data) {\r\n let message = data;\r\n if (Array.isArray(message)) {\r\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported data type\");\r\n }\r\n\r\n if (Buffer.isBuffer(message)) {\r\n if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {\r\n message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);\r\n } else {\r\n message = message.buffer;\r\n }\r\n }\r\n\r\n MobileRpcServer.interop.handler(message, this._connectionId);\r\n }\r\n\r\n public dispose() {\r\n clearInterval(this._pingTimer);\r\n if (this._connection) {\r\n MobileRpcServer.interop.sendString = () => { };\r\n MobileRpcServer.interop.sendBinary = () => { };\r\n this._connection.close();\r\n }\r\n\r\n this._server.close();\r\n }\r\n}\r\n\r\nlet mobileReady = false;\r\nlet hasSuspended = false;\r\n\r\nexport function setupMobileRpc() {\r\n if (mobileReady) {\r\n return;\r\n }\r\n\r\n if (ProcessDetector.isMobileAppBackend) {\r\n addon = (process as any)._linkedBinding(\"iModelJsMobile\");\r\n addon?.registerDeviceImpl();\r\n }\r\n\r\n let server: MobileRpcServer | null = new MobileRpcServer();\r\n\r\n /* The UV event loop (internal to node) is retained by handles,\r\n such as those created for setInterval/setTimeout and client/server connections.\r\n In a simple app, the RPC server may be the only handle retaining the UV loop.\r\n Thus, we install a temporary timer on suspend to prevent the loop from exiting prematurely.\r\n */\r\n let retainUvLoop: NodeJS.Timeout | undefined;\r\n const pendingMessages: Array<string | Uint8Array> = [];\r\n\r\n function usePendingSender() {\r\n const sender = (message: string | Uint8Array, _connectionId: number) => {\r\n pendingMessages.push(message);\r\n };\r\n MobileRpcServer.interop.sendString = sender;\r\n MobileRpcServer.interop.sendBinary = sender;\r\n }\r\n\r\n MobileHost.onEnterBackground.addListener(() => {\r\n hasSuspended = true;\r\n\r\n if (server === null) {\r\n return;\r\n }\r\n\r\n retainUvLoop = setInterval(() => { }, 1000);\r\n server.dispose();\r\n usePendingSender();\r\n server = null;\r\n (global as any).__iTwinJsRpcReady = false;\r\n });\r\n\r\n MobileHost.onEnterForeground.addListener(() => {\r\n if (!hasSuspended) {\r\n return;\r\n }\r\n\r\n server = new MobileRpcServer(pendingMessages);\r\n clearInterval(retainUvLoop);\r\n retainUvLoop = undefined;\r\n });\r\n\r\n MobileHost.onWillTerminate.addListener(() => {\r\n if (typeof (retainUvLoop) !== \"undefined\") {\r\n clearInterval(retainUvLoop);\r\n retainUvLoop = undefined;\r\n }\r\n\r\n if (server === null) {\r\n return;\r\n }\r\n\r\n server.dispose();\r\n server = null;\r\n });\r\n\r\n MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;\r\n mobileReady = true;\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Request.d.ts","sourceRoot":"","sources":["../../../src/backend/Request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Request.d.ts","sourceRoot":"","sources":["../../../src/backend/Request.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAAoB,MAAM,qBAAqB,CAAC;AAItG,gBAAgB;AAChB,eAAO,MAAM,mBAAmB,qBAAqB,CAAC;AAEtD,gBAAgB;AAChB,MAAM,WAAW,4BAA4B;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,gBAAgB;AAChB,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAChC,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EA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,MAAM,GAAG,UAAU;IAiB7D;;OAEG;IACI,UAAU,IAAI,MAAM;IAI3B;;;OAGG;IACI,GAAG,IAAI,IAAI;CAGnB;AAcD;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmIrF;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAOvD"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ResponseError = exports.requestIdHeaderName = void 0;
|
|
4
|
+
exports.request = request;
|
|
5
|
+
exports.getJson = getJson;
|
|
4
6
|
/*---------------------------------------------------------------------------------------------
|
|
5
7
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
8
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
@@ -238,7 +240,6 @@ async function request(url, options) {
|
|
|
238
240
|
throw parsedError;
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
|
-
exports.request = request;
|
|
242
243
|
/**
|
|
243
244
|
* fetch json from HTTP request
|
|
244
245
|
* @param url server URL to address the request
|
|
@@ -252,5 +253,4 @@ async function getJson(url) {
|
|
|
252
253
|
const data = await request(url, options);
|
|
253
254
|
return data.body;
|
|
254
255
|
}
|
|
255
|
-
exports.getJson = getJson;
|
|
256
256
|
//# sourceMappingURL=Request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/backend/Request.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,4BAA4B;AAE5B,wCAAwC;AACxC,sDAAsG;AAEtG,MAAM,cAAc,GAAW,6BAA6B,CAAC;AAE7D,gBAAgB;AACH,QAAA,mB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K,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;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,WAAW,CAAC;IACpB,CAAC;AACH,CAAC;AAnID,0BAmIC;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 _ from \"lodash\";\r\nimport * as https from \"https\";\r\nimport * as sarequest from \"superagent\";\r\nimport { BentleyError, GetMetaDataFunction, HttpStatus, Logger, LogLevel } from \"@itwin/core-bentley\";\r\n\r\nconst loggerCategory: string = \"core-mobile-backend.Request\";\r\n\r\n/** @internal */\r\nexport const requestIdHeaderName = \"X-Correlation-Id\";\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 body?: any;\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/** 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 _.merge(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 let sareq: sarequest.SuperAgentRequest = sarequest(options.method, url);\r\n if (options.retries)\r\n sareq = sareq.retry(options.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 Logger.logInfo(loggerCategory, url);\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\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\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 : (response: any) => ResponseError.parse(response);\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/backend/Request.ts"],"names":[],"mappings":";;;AA8MA,0BAmIC;AAOD,0BAOC;AA/VD;;;+FAG+F;AAC/F;;GAEG;AACH,4BAA4B;AAE5B,wCAAwC;AACxC,sDAAsG;AAEtG,MAAM,cAAc,GAAW,6BAA6B,CAAC;AAE7D,gBAAgB;AACH,QAAA,mBAAmB,GAAG,kBAAkB,CAAC;AAoEtD;;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,CAAC,UAAU,CAAC,CAAC,CAAC;QACpF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,KAAK,CAAC,OAAO,GAAG,+BAA+B,CAAC;YAChD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,QAAQ,CAAC,QAAQ,EAAE,C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O,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,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/** @packageDocumentation\r\n * @module iTwinServiceClients\r\n */\r\nimport * as _ from \"lodash\";\r\nimport * as https from \"https\";\r\nimport * as sarequest from \"superagent\";\r\nimport { BentleyError, GetMetaDataFunction, HttpStatus, Logger, LogLevel } from \"@itwin/core-bentley\";\r\n\r\nconst loggerCategory: string = \"core-mobile-backend.Request\";\r\n\r\n/** @internal */\r\nexport const requestIdHeaderName = \"X-Correlation-Id\";\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 body?: any;\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/** 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 _.merge(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 let sareq: sarequest.SuperAgentRequest = sarequest(options.method, url);\r\n if (options.retries)\r\n sareq = sareq.retry(options.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 Logger.logInfo(loggerCategory, url);\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\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\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 : (response: any) => ResponseError.parse(response);\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-mobile",
|
|
3
|
-
"version": "4.10.0-dev.
|
|
3
|
+
"version": "4.10.0-dev.32",
|
|
4
4
|
"description": "iTwin.js MobileHost and MobileApp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"url": "http://www.bentley.com"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@itwin/core-backend": "^4.10.0-dev.
|
|
26
|
-
"@itwin/core-bentley": "^4.10.0-dev.
|
|
27
|
-
"@itwin/core-common": "^4.10.0-dev.
|
|
28
|
-
"@itwin/core-frontend": "^4.10.0-dev.
|
|
25
|
+
"@itwin/core-backend": "^4.10.0-dev.32",
|
|
26
|
+
"@itwin/core-bentley": "^4.10.0-dev.32",
|
|
27
|
+
"@itwin/core-common": "^4.10.0-dev.32",
|
|
28
|
+
"@itwin/core-frontend": "^4.10.0-dev.32"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"lodash": "^4.17.21",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"@types/ws": "^7.0.0",
|
|
44
44
|
"chai": "^4.3.10",
|
|
45
45
|
"chai-as-promised": "^7.1.1",
|
|
46
|
-
"dotenv": "^
|
|
46
|
+
"dotenv": "^16.4.5",
|
|
47
47
|
"dotenv-expand": "^5.1.0",
|
|
48
48
|
"eslint": "^8.56.0",
|
|
49
49
|
"mocha": "^10.2.0",
|
|
50
50
|
"rimraf": "^3.0.2",
|
|
51
|
-
"typescript": "~5.
|
|
52
|
-
"@itwin/build-tools": "4.10.0-dev.
|
|
53
|
-
"@itwin/core-
|
|
54
|
-
"@itwin/core-
|
|
55
|
-
"@itwin/core-
|
|
56
|
-
"@itwin/core-frontend": "4.10.0-dev.
|
|
51
|
+
"typescript": "~5.6.2",
|
|
52
|
+
"@itwin/build-tools": "4.10.0-dev.32",
|
|
53
|
+
"@itwin/core-bentley": "4.10.0-dev.32",
|
|
54
|
+
"@itwin/core-backend": "4.10.0-dev.32",
|
|
55
|
+
"@itwin/core-common": "4.10.0-dev.32",
|
|
56
|
+
"@itwin/core-frontend": "4.10.0-dev.32"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "npm run -s build:cjs",
|