@itwin/core-mobile 3.5.0-dev.8 → 3.6.0-dev.1
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
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
# Change Log - @itwin/core-mobile
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 30 Nov 2022 14:28:19 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 3.4.7
|
|
6
|
+
Wed, 30 Nov 2022 14:28:19 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 3.4.6
|
|
11
|
+
Tue, 22 Nov 2022 14:24:19 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 3.4.5
|
|
16
|
+
Thu, 17 Nov 2022 21:32:50 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
19
|
+
|
|
20
|
+
## 3.4.4
|
|
21
|
+
Thu, 10 Nov 2022 19:32:17 GMT
|
|
22
|
+
|
|
23
|
+
_Version update only_
|
|
24
|
+
|
|
25
|
+
## 3.4.3
|
|
26
|
+
Fri, 28 Oct 2022 13:34:58 GMT
|
|
27
|
+
|
|
28
|
+
_Version update only_
|
|
29
|
+
|
|
30
|
+
## 3.4.2
|
|
31
|
+
Mon, 24 Oct 2022 13:23:45 GMT
|
|
32
|
+
|
|
33
|
+
_Version update only_
|
|
34
|
+
|
|
35
|
+
## 3.4.1
|
|
36
|
+
Mon, 17 Oct 2022 20:06:51 GMT
|
|
37
|
+
|
|
38
|
+
_Version update only_
|
|
39
|
+
|
|
40
|
+
## 3.4.0
|
|
41
|
+
Thu, 13 Oct 2022 20:24:47 GMT
|
|
42
|
+
|
|
43
|
+
### Updates
|
|
44
|
+
|
|
45
|
+
- Updated Node types declaration to support latest v16
|
|
46
|
+
|
|
47
|
+
## 3.3.5
|
|
48
|
+
Tue, 27 Sep 2022 11:50:59 GMT
|
|
49
|
+
|
|
50
|
+
_Version update only_
|
|
51
|
+
|
|
52
|
+
## 3.3.4
|
|
53
|
+
Thu, 08 Sep 2022 19:00:05 GMT
|
|
54
|
+
|
|
55
|
+
_Version update only_
|
|
56
|
+
|
|
57
|
+
## 3.3.3
|
|
58
|
+
Tue, 06 Sep 2022 20:54:19 GMT
|
|
59
|
+
|
|
60
|
+
_Version update only_
|
|
4
61
|
|
|
5
62
|
## 3.3.2
|
|
6
63
|
Thu, 01 Sep 2022 14:37:22 GMT
|
|
@@ -145,7 +145,7 @@ class MobileFileHandler {
|
|
|
145
145
|
const chunkSize = 4 * 1024 * 1024;
|
|
146
146
|
let buffer = Buffer.alloc(chunkSize);
|
|
147
147
|
const bytesRead = fs.readSync(fileDescriptor, buffer, 0, chunkSize, chunkSize * blockId);
|
|
148
|
-
buffer = buffer.
|
|
148
|
+
buffer = buffer.subarray(0, bytesRead);
|
|
149
149
|
const options = {
|
|
150
150
|
method: "PUT",
|
|
151
151
|
headers: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileFileHandler.js","sourceRoot":"","sources":["../../../src/backend/MobileFileHandler.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,yBAAyB;AAEzB,6BAA6B;AAC7B,sDAA6F;AAC7F,uCAAoF;AACpF,6CAA0C;AAC1C,yCAAmC;AAEnC,MAAM,cAAc,GAAW,oBAAoB,CAAC;AAEpD,MAAM,OAAO,GAAG,CAAC,YAAoB,EAAE,QAAc,EAAE,aAAsB,KAAK,EAAE,EAAE;IACpF,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,IAAI,CAAC,QAAQ,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC;QACjF,MAAM,KAAK,CAAC,YAAY,YAAY,uBAAuB,CAAC,CAAC;AACjE,CAAC,CAAC;AAUF;;IAEI;AACJ,MAAa,k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D;iBAChG;gBACD,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,OAAO,EAAE;oBACP,QAAQ,EAAE,IAAI;oBACd,QAAQ,EAAE,KAAK;iBAChB;aACF,CAAC;YAEF,MAAM,SAAS,GAAG,GAAG,eAAe,iBAAiB,CAAC;YACtD,MAAM,IAAA,iBAAO,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;SACnC;gBAAS;YACR,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SACpB;IACH,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,QAAgB;QACjC,OAAO,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,QAAgB;QACjC,OAAO,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAgB;QAC5B,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,QAAgB;QAC5B,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,QAAgB;QAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,GAAG,KAAe;QAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AArOD,8CAqOC","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 iModelHub\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport * as https from \"https\";\r\nimport * as path from \"path\";\r\nimport { AccessToken, BentleyError, GetMetaDataFunction, Logger } from \"@itwin/core-bentley\";\r\nimport { ProgressCallback, ProgressInfo, request, RequestOptions } from \"./Request\";\r\nimport { MobileHost } from \"./MobileHost\";\r\nimport { Base64 } from \"js-base64\";\r\n\r\nconst loggerCategory: string = \"mobile.filehandler\";\r\n\r\nconst defined = (argumentName: string, argument?: any, allowEmpty: boolean = false) => {\r\n if (argument === undefined || argument === null || (argument === \"\" && !allowEmpty))\r\n throw Error(`Argument ${argumentName} is null or undefined`);\r\n};\r\n\r\n/** Interface to cancel a request\r\n * @beta\r\n */\r\nexport interface CancelRequest {\r\n /** Returns true if cancel request was acknowledged */\r\n cancel: () => boolean;\r\n}\r\n\r\n/** Error thrown when user cancelled operation\r\n * @internal\r\n */\r\nexport class UserCancelledError extends BentleyError {\r\n public constructor(errorNumber: number, message: string, getMetaData?: GetMetaDataFunction) {\r\n super(errorNumber, message, getMetaData);\r\n this.name = \"User cancelled operation\";\r\n }\r\n}\r\n\r\n/** Error thrown fail to download file. ErrorNumber will correspond to HTTP error code.\r\n * @internal\r\n */\r\nexport class DownloadFailed extends BentleyError {\r\n public constructor(errorNumber: number, message: string, getMetaData?: GetMetaDataFunction) {\r\n super(errorNumber, message, getMetaData);\r\n this.name = \"Fail to download file\";\r\n }\r\n}\r\n\r\n/** Error thrown when sas-url provided for download has expired\r\n * @internal\r\n */\r\nexport class SasUrlExpired extends BentleyError {\r\n public constructor(errorNumber: number, message: string, getMetaData?: GetMetaDataFunction) {\r\n super(errorNumber, message, getMetaData);\r\n this.name = \"SaS url has expired\";\r\n }\r\n}\r\n\r\n/**\r\n * Provides methods to work with the file system and azure storage. An instance of this class has to be provided to [[IModelClient]] for file upload/download methods to work.\r\n * @internal\r\n */\r\nexport class MobileFileHandler {\r\n /** @internal */\r\n public agent?: https.Agent;\r\n\r\n /**\r\n * Constructor for MobileFileHandler.\r\n */\r\n constructor() {\r\n }\r\n\r\n /** Create a directory, recursively setting up the path as necessary. */\r\n private static makeDirectoryRecursive(dirPath: string) {\r\n if (fs.existsSync(dirPath))\r\n return;\r\n\r\n MobileFileHandler.makeDirectoryRecursive(path.dirname(dirPath));\r\n fs.mkdirSync(dirPath);\r\n }\r\n\r\n /**\r\n * Make url safe for logging by removing sensitive information\r\n * @param url input url that will be strip of search and query parameters and replace them by ... for security reason\r\n */\r\n private static getSafeUrlForLogging(url: string): string {\r\n const safeToLogDownloadUrl = new URL(url);\r\n if (safeToLogDownloadUrl.search && safeToLogDownloadUrl.search.length > 0)\r\n safeToLogDownloadUrl.search = \"...\";\r\n if (safeToLogDownloadUrl.hash && safeToLogDownloadUrl.hash.length > 0)\r\n safeToLogDownloadUrl.hash = \"...\";\r\n return safeToLogDownloadUrl.toString();\r\n }\r\n\r\n /**\r\n * Check if sas url has expired\r\n * @param download sas url for download\r\n * @param futureSeconds should be valid in future for given seconds.\r\n */\r\n public static isUrlExpired(downloadUrl: string, futureSeconds?: number): boolean {\r\n const sasUrl = new URL(downloadUrl);\r\n const se = sasUrl.searchParams.get(\"se\");\r\n if (se) {\r\n const expiryUTC = new Date(se);\r\n const now = new Date();\r\n const currentUTC = new Date(now.toUTCString());\r\n if (futureSeconds) {\r\n currentUTC.setSeconds(futureSeconds + currentUTC.getSeconds());\r\n }\r\n return expiryUTC <= currentUTC;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Download a file from AzureBlobStorage for iModelHub. Creates the directory containing the file if necessary. If there is an error in the operation, incomplete file is deleted from disk.\r\n * @param downloadUrl URL to download file from.\r\n * @param downloadToPathname Pathname to download the file to.\r\n * @param fileSize Size of the file that's being downloaded.\r\n * @param progressCallback Callback for tracking progress.\r\n * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) if one of the arguments is undefined or empty.\r\n */\r\n public async downloadFile(_accessToken: AccessToken, downloadUrl: string, downloadToPathname: string, fileSize?: number, progressCallback?: ProgressCallback, cancelRequest?: CancelRequest): Promise<void> {\r\n // strip search and hash parameters from download Url for logging purpose\r\n const safeToLogUrl = MobileFileHandler.getSafeUrlForLogging(downloadUrl);\r\n Logger.logInfo(loggerCategory, `Downloading file from ${safeToLogUrl}`);\r\n\r\n defined(\"downloadUrl\", downloadUrl);\r\n defined(\"downloadToPathname\", downloadToPathname);\r\n if (MobileFileHandler.isUrlExpired(downloadUrl)) {\r\n Logger.logError(loggerCategory, `Sas url has expired ${safeToLogUrl}`);\r\n throw new SasUrlExpired(403, \"Download URL has expired\");\r\n }\r\n if (fs.existsSync(downloadToPathname))\r\n fs.unlinkSync(downloadToPathname);\r\n\r\n MobileFileHandler.makeDirectoryRecursive(path.dirname(downloadToPathname));\r\n try {\r\n await MobileHost.downloadFile(downloadUrl, downloadToPathname, progressCallback, cancelRequest);\r\n } catch (err) {\r\n if (fs.existsSync(downloadToPathname))\r\n fs.unlinkSync(downloadToPathname); // Just in case there was a partial download, delete the file\r\n\r\n if (!(err instanceof UserCancelledError))\r\n Logger.logError(loggerCategory, `Error downloading file`);\r\n throw err;\r\n }\r\n if (fileSize && fs.existsSync(downloadToPathname)) {\r\n if (fs.lstatSync(downloadToPathname).size !== fileSize) {\r\n fs.unlinkSync(downloadToPathname);\r\n Logger.logError(loggerCategory, `Downloaded file is of incorrect size ${safeToLogUrl}`);\r\n throw new DownloadFailed(403, \"Download failed. Expected filesize does not match\");\r\n }\r\n }\r\n Logger.logTrace(loggerCategory, `Downloaded file from ${safeToLogUrl}`);\r\n }\r\n /** Get encoded block id from its number. */\r\n private getBlockId(blockId: number) {\r\n return Base64.encode(blockId.toString(16).padStart(5, \"0\"));\r\n }\r\n\r\n private async uploadChunk(_accessToken: AccessToken, uploadUrlString: string, fileDescriptor: number, blockId: number, callback?: ProgressCallback) {\r\n const chunkSize = 4 * 1024 * 1024;\r\n let buffer = Buffer.alloc(chunkSize);\r\n const bytesRead = fs.readSync(fileDescriptor, buffer, 0, chunkSize, chunkSize * blockId);\r\n buffer = buffer.slice(0, bytesRead);\r\n\r\n const options: RequestOptions = {\r\n method: \"PUT\",\r\n headers: {\r\n \"x-ms-blob-type\": \"BlockBlob\",\r\n \"Content-Type\": \"application/octet-stream\", // eslint-disable-line @typescript-eslint/naming-convention\r\n \"Content-Length\": buffer.length, // eslint-disable-line @typescript-eslint/naming-convention\r\n },\r\n body: buffer,\r\n progressCallback: callback,\r\n agent: this.agent,\r\n timeout: {\r\n deadline: 60000,\r\n response: 60000,\r\n },\r\n };\r\n\r\n const uploadUrl = `${uploadUrlString}&comp=block&blockid=${this.getBlockId(blockId)}`;\r\n await request(uploadUrl, options);\r\n }\r\n\r\n /**\r\n * Upload a file to AzureBlobStorage for iModelHub.\r\n * @param uploadUrl URL to upload the file to.\r\n * @param uploadFromPathname Pathname to upload the file from.\r\n * @param progressCallback Callback for tracking progress.\r\n * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) if one of the arguments is undefined or empty.\r\n */\r\n public async uploadFile(accessToken: AccessToken, uploadUrlString: string, uploadFromPathname: string, progressCallback?: ProgressCallback): Promise<void> {\r\n const safeToLogUrl = MobileFileHandler.getSafeUrlForLogging(uploadUrlString);\r\n Logger.logTrace(loggerCategory, `Uploading file to ${safeToLogUrl}`);\r\n defined(\"uploadUrlString\", uploadUrlString);\r\n defined(\"uploadFromPathname\", uploadFromPathname);\r\n\r\n const fileSize = this.getFileSize(uploadFromPathname);\r\n const file = fs.openSync(uploadFromPathname, \"r\");\r\n const chunkSize = 4 * 1024 * 1024;\r\n\r\n try {\r\n let blockList = '<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?><BlockList>';\r\n let i = 0;\r\n const callback: ProgressCallback = (progress: ProgressInfo) => {\r\n const uploaded = i * chunkSize + progress.loaded;\r\n if (progressCallback)\r\n progressCallback({ loaded: uploaded, percent: uploaded / fileSize, total: fileSize });\r\n };\r\n for (; i * chunkSize < fileSize; ++i) {\r\n await this.uploadChunk(accessToken, uploadUrlString, file, i, progressCallback ? callback : undefined);\r\n blockList += `<Latest>${this.getBlockId(i)}</Latest>`;\r\n }\r\n blockList += \"</BlockList>\";\r\n\r\n const options: RequestOptions = {\r\n method: \"PUT\",\r\n headers: {\r\n \"Content-Type\": \"application/xml\", // eslint-disable-line @typescript-eslint/naming-convention\r\n \"Content-Length\": blockList.length, // eslint-disable-line @typescript-eslint/naming-convention\r\n },\r\n body: blockList,\r\n agent: this.agent,\r\n timeout: {\r\n response: 5000,\r\n deadline: 60000,\r\n },\r\n };\r\n\r\n const uploadUrl = `${uploadUrlString}&comp=blocklist`;\r\n await request(uploadUrl, options);\r\n } finally {\r\n fs.closeSync(file);\r\n }\r\n }\r\n\r\n /**\r\n * Get size of a file.\r\n * @param filePath Path of the file.\r\n * @returns Size of the file.\r\n */\r\n public getFileSize(filePath: string): number {\r\n return fs.statSync(filePath).size;\r\n }\r\n\r\n /**\r\n * Check if path is a directory.\r\n * @param filePath Path of the file.\r\n * @returns True if path is directory.\r\n */\r\n public isDirectory(filePath: string): boolean {\r\n return fs.statSync(filePath).isDirectory();\r\n }\r\n\r\n /**\r\n * Check if path exists.\r\n * @param filePath Path of the file.\r\n * @returns True if path exists.\r\n */\r\n public exists(filePath: string): boolean {\r\n return fs.existsSync(filePath);\r\n }\r\n\r\n /**\r\n * Deletes file.\r\n * @param filePath Path of the file.\r\n */\r\n public unlink(filePath: string): void {\r\n fs.unlinkSync(filePath);\r\n }\r\n\r\n /**\r\n * Get file name from the path.\r\n * @param filePath Path of the file.\r\n * @returns File name.\r\n */\r\n public basename(filePath: string): string {\r\n return path.basename(filePath);\r\n }\r\n\r\n /**\r\n * Join multiple strings into a single path.\r\n * @param paths Strings to join.\r\n * @returns Joined path.\r\n */\r\n public join(...paths: string[]): string {\r\n return path.join(...paths);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"MobileFileHandler.js","sourceRoot":"","sources":["../../../src/backend/MobileFileHandler.ts"],"names":[],"mappings":";AAAA;;;+FAG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C;IAC1B,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,QAAgB;QAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,GAAG,KAAe;QAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAC7B,CAAC;CACF;AArOD,8CAqOC","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 iModelHub\r\n */\r\n\r\nimport * as fs from \"fs\";\r\nimport * as https from \"https\";\r\nimport * as path from \"path\";\r\nimport { AccessToken, BentleyError, GetMetaDataFunction, Logger } from \"@itwin/core-bentley\";\r\nimport { ProgressCallback, ProgressInfo, request, RequestOptions } from \"./Request\";\r\nimport { MobileHost } from \"./MobileHost\";\r\nimport { Base64 } from \"js-base64\";\r\n\r\nconst loggerCategory: string = \"mobile.filehandler\";\r\n\r\nconst defined = (argumentName: string, argument?: any, allowEmpty: boolean = false) => {\r\n if (argument === undefined || argument === null || (argument === \"\" && !allowEmpty))\r\n throw Error(`Argument ${argumentName} is null or undefined`);\r\n};\r\n\r\n/** Interface to cancel a request\r\n * @beta\r\n */\r\nexport interface CancelRequest {\r\n /** Returns true if cancel request was acknowledged */\r\n cancel: () => boolean;\r\n}\r\n\r\n/** Error thrown when user cancelled operation\r\n * @internal\r\n */\r\nexport class UserCancelledError extends BentleyError {\r\n public constructor(errorNumber: number, message: string, getMetaData?: GetMetaDataFunction) {\r\n super(errorNumber, message, getMetaData);\r\n this.name = \"User cancelled operation\";\r\n }\r\n}\r\n\r\n/** Error thrown fail to download file. ErrorNumber will correspond to HTTP error code.\r\n * @internal\r\n */\r\nexport class DownloadFailed extends BentleyError {\r\n public constructor(errorNumber: number, message: string, getMetaData?: GetMetaDataFunction) {\r\n super(errorNumber, message, getMetaData);\r\n this.name = \"Fail to download file\";\r\n }\r\n}\r\n\r\n/** Error thrown when sas-url provided for download has expired\r\n * @internal\r\n */\r\nexport class SasUrlExpired extends BentleyError {\r\n public constructor(errorNumber: number, message: string, getMetaData?: GetMetaDataFunction) {\r\n super(errorNumber, message, getMetaData);\r\n this.name = \"SaS url has expired\";\r\n }\r\n}\r\n\r\n/**\r\n * Provides methods to work with the file system and azure storage. An instance of this class has to be provided to [[IModelClient]] for file upload/download methods to work.\r\n * @internal\r\n */\r\nexport class MobileFileHandler {\r\n /** @internal */\r\n public agent?: https.Agent;\r\n\r\n /**\r\n * Constructor for MobileFileHandler.\r\n */\r\n constructor() {\r\n }\r\n\r\n /** Create a directory, recursively setting up the path as necessary. */\r\n private static makeDirectoryRecursive(dirPath: string) {\r\n if (fs.existsSync(dirPath))\r\n return;\r\n\r\n MobileFileHandler.makeDirectoryRecursive(path.dirname(dirPath));\r\n fs.mkdirSync(dirPath);\r\n }\r\n\r\n /**\r\n * Make url safe for logging by removing sensitive information\r\n * @param url input url that will be strip of search and query parameters and replace them by ... for security reason\r\n */\r\n private static getSafeUrlForLogging(url: string): string {\r\n const safeToLogDownloadUrl = new URL(url);\r\n if (safeToLogDownloadUrl.search && safeToLogDownloadUrl.search.length > 0)\r\n safeToLogDownloadUrl.search = \"...\";\r\n if (safeToLogDownloadUrl.hash && safeToLogDownloadUrl.hash.length > 0)\r\n safeToLogDownloadUrl.hash = \"...\";\r\n return safeToLogDownloadUrl.toString();\r\n }\r\n\r\n /**\r\n * Check if sas url has expired\r\n * @param download sas url for download\r\n * @param futureSeconds should be valid in future for given seconds.\r\n */\r\n public static isUrlExpired(downloadUrl: string, futureSeconds?: number): boolean {\r\n const sasUrl = new URL(downloadUrl);\r\n const se = sasUrl.searchParams.get(\"se\");\r\n if (se) {\r\n const expiryUTC = new Date(se);\r\n const now = new Date();\r\n const currentUTC = new Date(now.toUTCString());\r\n if (futureSeconds) {\r\n currentUTC.setSeconds(futureSeconds + currentUTC.getSeconds());\r\n }\r\n return expiryUTC <= currentUTC;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Download a file from AzureBlobStorage for iModelHub. Creates the directory containing the file if necessary. If there is an error in the operation, incomplete file is deleted from disk.\r\n * @param downloadUrl URL to download file from.\r\n * @param downloadToPathname Pathname to download the file to.\r\n * @param fileSize Size of the file that's being downloaded.\r\n * @param progressCallback Callback for tracking progress.\r\n * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) if one of the arguments is undefined or empty.\r\n */\r\n public async downloadFile(_accessToken: AccessToken, downloadUrl: string, downloadToPathname: string, fileSize?: number, progressCallback?: ProgressCallback, cancelRequest?: CancelRequest): Promise<void> {\r\n // strip search and hash parameters from download Url for logging purpose\r\n const safeToLogUrl = MobileFileHandler.getSafeUrlForLogging(downloadUrl);\r\n Logger.logInfo(loggerCategory, `Downloading file from ${safeToLogUrl}`);\r\n\r\n defined(\"downloadUrl\", downloadUrl);\r\n defined(\"downloadToPathname\", downloadToPathname);\r\n if (MobileFileHandler.isUrlExpired(downloadUrl)) {\r\n Logger.logError(loggerCategory, `Sas url has expired ${safeToLogUrl}`);\r\n throw new SasUrlExpired(403, \"Download URL has expired\");\r\n }\r\n if (fs.existsSync(downloadToPathname))\r\n fs.unlinkSync(downloadToPathname);\r\n\r\n MobileFileHandler.makeDirectoryRecursive(path.dirname(downloadToPathname));\r\n try {\r\n await MobileHost.downloadFile(downloadUrl, downloadToPathname, progressCallback, cancelRequest);\r\n } catch (err) {\r\n if (fs.existsSync(downloadToPathname))\r\n fs.unlinkSync(downloadToPathname); // Just in case there was a partial download, delete the file\r\n\r\n if (!(err instanceof UserCancelledError))\r\n Logger.logError(loggerCategory, `Error downloading file`);\r\n throw err;\r\n }\r\n if (fileSize && fs.existsSync(downloadToPathname)) {\r\n if (fs.lstatSync(downloadToPathname).size !== fileSize) {\r\n fs.unlinkSync(downloadToPathname);\r\n Logger.logError(loggerCategory, `Downloaded file is of incorrect size ${safeToLogUrl}`);\r\n throw new DownloadFailed(403, \"Download failed. Expected filesize does not match\");\r\n }\r\n }\r\n Logger.logTrace(loggerCategory, `Downloaded file from ${safeToLogUrl}`);\r\n }\r\n /** Get encoded block id from its number. */\r\n private getBlockId(blockId: number) {\r\n return Base64.encode(blockId.toString(16).padStart(5, \"0\"));\r\n }\r\n\r\n private async uploadChunk(_accessToken: AccessToken, uploadUrlString: string, fileDescriptor: number, blockId: number, callback?: ProgressCallback) {\r\n const chunkSize = 4 * 1024 * 1024;\r\n let buffer = Buffer.alloc(chunkSize);\r\n const bytesRead = fs.readSync(fileDescriptor, buffer, 0, chunkSize, chunkSize * blockId);\r\n buffer = buffer.subarray(0, bytesRead);\r\n\r\n const options: RequestOptions = {\r\n method: \"PUT\",\r\n headers: {\r\n \"x-ms-blob-type\": \"BlockBlob\",\r\n \"Content-Type\": \"application/octet-stream\", // eslint-disable-line @typescript-eslint/naming-convention\r\n \"Content-Length\": buffer.length, // eslint-disable-line @typescript-eslint/naming-convention\r\n },\r\n body: buffer,\r\n progressCallback: callback,\r\n agent: this.agent,\r\n timeout: {\r\n deadline: 60000,\r\n response: 60000,\r\n },\r\n };\r\n\r\n const uploadUrl = `${uploadUrlString}&comp=block&blockid=${this.getBlockId(blockId)}`;\r\n await request(uploadUrl, options);\r\n }\r\n\r\n /**\r\n * Upload a file to AzureBlobStorage for iModelHub.\r\n * @param uploadUrl URL to upload the file to.\r\n * @param uploadFromPathname Pathname to upload the file from.\r\n * @param progressCallback Callback for tracking progress.\r\n * @throws [[IModelHubClientError]] with [IModelHubStatus.UndefinedArgumentError]($bentley) if one of the arguments is undefined or empty.\r\n */\r\n public async uploadFile(accessToken: AccessToken, uploadUrlString: string, uploadFromPathname: string, progressCallback?: ProgressCallback): Promise<void> {\r\n const safeToLogUrl = MobileFileHandler.getSafeUrlForLogging(uploadUrlString);\r\n Logger.logTrace(loggerCategory, `Uploading file to ${safeToLogUrl}`);\r\n defined(\"uploadUrlString\", uploadUrlString);\r\n defined(\"uploadFromPathname\", uploadFromPathname);\r\n\r\n const fileSize = this.getFileSize(uploadFromPathname);\r\n const file = fs.openSync(uploadFromPathname, \"r\");\r\n const chunkSize = 4 * 1024 * 1024;\r\n\r\n try {\r\n let blockList = '<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?><BlockList>';\r\n let i = 0;\r\n const callback: ProgressCallback = (progress: ProgressInfo) => {\r\n const uploaded = i * chunkSize + progress.loaded;\r\n if (progressCallback)\r\n progressCallback({ loaded: uploaded, percent: uploaded / fileSize, total: fileSize });\r\n };\r\n for (; i * chunkSize < fileSize; ++i) {\r\n await this.uploadChunk(accessToken, uploadUrlString, file, i, progressCallback ? callback : undefined);\r\n blockList += `<Latest>${this.getBlockId(i)}</Latest>`;\r\n }\r\n blockList += \"</BlockList>\";\r\n\r\n const options: RequestOptions = {\r\n method: \"PUT\",\r\n headers: {\r\n \"Content-Type\": \"application/xml\", // eslint-disable-line @typescript-eslint/naming-convention\r\n \"Content-Length\": blockList.length, // eslint-disable-line @typescript-eslint/naming-convention\r\n },\r\n body: blockList,\r\n agent: this.agent,\r\n timeout: {\r\n response: 5000,\r\n deadline: 60000,\r\n },\r\n };\r\n\r\n const uploadUrl = `${uploadUrlString}&comp=blocklist`;\r\n await request(uploadUrl, options);\r\n } finally {\r\n fs.closeSync(file);\r\n }\r\n }\r\n\r\n /**\r\n * Get size of a file.\r\n * @param filePath Path of the file.\r\n * @returns Size of the file.\r\n */\r\n public getFileSize(filePath: string): number {\r\n return fs.statSync(filePath).size;\r\n }\r\n\r\n /**\r\n * Check if path is a directory.\r\n * @param filePath Path of the file.\r\n * @returns True if path is directory.\r\n */\r\n public isDirectory(filePath: string): boolean {\r\n return fs.statSync(filePath).isDirectory();\r\n }\r\n\r\n /**\r\n * Check if path exists.\r\n * @param filePath Path of the file.\r\n * @returns True if path exists.\r\n */\r\n public exists(filePath: string): boolean {\r\n return fs.existsSync(filePath);\r\n }\r\n\r\n /**\r\n * Deletes file.\r\n * @param filePath Path of the file.\r\n */\r\n public unlink(filePath: string): void {\r\n fs.unlinkSync(filePath);\r\n }\r\n\r\n /**\r\n * Get file name from the path.\r\n * @param filePath Path of the file.\r\n * @returns File name.\r\n */\r\n public basename(filePath: string): string {\r\n return path.basename(filePath);\r\n }\r\n\r\n /**\r\n * Join multiple strings into a single path.\r\n * @param paths Strings to join.\r\n * @returns Joined path.\r\n */\r\n public join(...paths: string[]): string {\r\n return path.join(...paths);\r\n }\r\n}\r\n"]}
|
|
@@ -22,7 +22,7 @@ class MobileAppNotifyHandler extends core_frontend_1.NotificationHandler {
|
|
|
22
22
|
MobileApp.onMemoryWarning.raiseEvent();
|
|
23
23
|
}
|
|
24
24
|
notifyOrientationChanged() { MobileApp.onOrientationChanged.raiseEvent(); }
|
|
25
|
-
notifyEnterForeground() { MobileApp.
|
|
25
|
+
notifyEnterForeground() { MobileApp.onEnterForeground.raiseEvent(); }
|
|
26
26
|
notifyEnterBackground() { MobileApp.onEnterBackground.raiseEvent(); }
|
|
27
27
|
notifyWillTerminate() { MobileApp.onWillTerminate.raiseEvent(); }
|
|
28
28
|
notifyAuthAccessTokenChanged(accessToken, expirationDate) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileApp.js","sourceRoot":"","sources":["../../../src/frontend/MobileApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAAyF;AACzF,oDAA0G;AAC1G,wDAA+G;AAC/G,iEAA+E;AAE/E,iEAA8D;AAC9D,+EAA4E;AAK5E,yCAAyC;AACzC,MAAM,sBAAuB,SAAQ,mCAAmB;IACtD,IAAW,WAAW,KAAK,OAAO,kCAAe,CAAC,CAAC,CAAC;IAE7C,mBAAmB;QACxB,qBAAM,CAAC,UAAU,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;QACrD,IAAI,SAAS,CAAC,eAAe,CAAC,iBAAiB,KAAK,CAAC,EAAE;Y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WAAW,EAAE,cAAc,CAAC,CAAC;YAClE,CAAC,CAAC,CAAC;YAEH,MAAM,aAAa,GAAG,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,0CAAE,aAAa,mCAAI,CAAC,oCAAsB,EAAE,oCAAsB,CAAC,CAAC;YACzG,mCAAgB,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACjD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACtB;QAED,MAAM,MAAM,GAAG,IAAI,kCAAoB,EAAE,CAAC,CAAC,aAAa;QACxD,MAAM,yBAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;QAEvE,sBAAsB,CAAC,QAAQ,EAAE,CAAC,CAAC,sCAAsC;IAC3E,CAAC;;AAnCH,8BAoCC;AAnCe,yBAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC5C,8BAAoB,GAAG,IAAI,sBAAO,EAAc,CAAC;AACjD,2BAAiB,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC9C,2BAAiB,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC9C,yBAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC5C,kCAAwB,GAAG,IAAI,sBAAO,EAAiF,CAAC;AAKvH,kBAAQ,GAAG,KAAK,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 { AsyncMethodsOf, BeEvent, Logger, PromiseReturnType } from \"@itwin/core-bentley\";\r\nimport { IModelReadRpcInterface, IModelTileRpcInterface, IpcWebSocketFrontend } from \"@itwin/core-common\";\r\nimport { IModelAppOptions, IpcApp, NativeApp, NativeAppOpts, NotificationHandler } from \"@itwin/core-frontend\";\r\nimport { mobileAppChannel, mobileAppNotify } from \"../common/MobileAppChannel\";\r\nimport { MobileAppFunctions, MobileNotifications } from \"../common/MobileAppProps\";\r\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\r\nimport { MobileAuthorizationFrontend } from \"./MobileAuthorizationFrontend\";\r\n\r\n/** @beta */\r\nexport type MobileAppOpts = NativeAppOpts & { iModelApp: { authorizationClient?: never } };\r\n\r\n/** receive notifications from backend */\r\nclass MobileAppNotifyHandler extends NotificationHandler implements MobileNotifications {\r\n public get channelName() { return mobileAppNotify; }\r\n\r\n public notifyMemoryWarning() {\r\n Logger.logWarning(\"mobileApp\", \"Low memory warning\");\r\n if (MobileApp.onMemoryWarning.numberOfListeners === 0) {\r\n alert(\"Low memory warning\");\r\n }\r\n MobileApp.onMemoryWarning.raiseEvent();\r\n }\r\n public notifyOrientationChanged() { MobileApp.onOrientationChanged.raiseEvent(); }\r\n public notifyEnterForeground() { MobileApp.
|
|
1
|
+
{"version":3,"file":"MobileApp.js","sourceRoot":"","sources":["../../../src/frontend/MobileApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAAyF;AACzF,oDAA0G;AAC1G,wDAA+G;AAC/G,iEAA+E;AAE/E,iEAA8D;AAC9D,+EAA4E;AAK5E,yCAAyC;AACzC,MAAM,sBAAuB,SAAQ,mCAAmB;IACtD,IAAW,WAAW,KAAK,OAAO,kCAAe,CAAC,CAAC,CAAC;IAE7C,mBAAmB;QACxB,qBAAM,CAAC,UAAU,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;QACrD,IAAI,SAAS,CAAC,eAAe,CAAC,iBAAiB,KAAK,CAAC,EAAE;YACrD,KAAK,CAAC,oBAAoB,CAAC,CAAC;SAC7B;QACD,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC;IACzC,CAAC;IACM,wBAAwB,KAAK,SAAS,CAAC,oBAAoB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC3E,qBAAqB,KAAK,SAAS,CAAC,i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AC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACjD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACtB;QAED,MAAM,MAAM,GAAG,IAAI,kCAAoB,EAAE,CAAC,CAAC,aAAa;QACxD,MAAM,yBAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;QAEvE,sBAAsB,CAAC,QAAQ,EAAE,CAAC,CAAC,sCAAsC;IAC3E,CAAC;;AAnCH,8BAoCC;AAnCe,yBAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC5C,8BAAoB,GAAG,IAAI,sBAAO,EAAc,CAAC;AACjD,2BAAiB,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC9C,2BAAiB,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC9C,yBAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC5C,kCAAwB,GAAG,IAAI,sBAAO,EAAiF,CAAC;AAKvH,kBAAQ,GAAG,KAAK,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 { AsyncMethodsOf, BeEvent, Logger, PromiseReturnType } from \"@itwin/core-bentley\";\r\nimport { IModelReadRpcInterface, IModelTileRpcInterface, IpcWebSocketFrontend } from \"@itwin/core-common\";\r\nimport { IModelAppOptions, IpcApp, NativeApp, NativeAppOpts, NotificationHandler } from \"@itwin/core-frontend\";\r\nimport { mobileAppChannel, mobileAppNotify } from \"../common/MobileAppChannel\";\r\nimport { MobileAppFunctions, MobileNotifications } from \"../common/MobileAppProps\";\r\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\r\nimport { MobileAuthorizationFrontend } from \"./MobileAuthorizationFrontend\";\r\n\r\n/** @beta */\r\nexport type MobileAppOpts = NativeAppOpts & { iModelApp: { authorizationClient?: never } };\r\n\r\n/** receive notifications from backend */\r\nclass MobileAppNotifyHandler extends NotificationHandler implements MobileNotifications {\r\n public get channelName() { return mobileAppNotify; }\r\n\r\n public notifyMemoryWarning() {\r\n Logger.logWarning(\"mobileApp\", \"Low memory warning\");\r\n if (MobileApp.onMemoryWarning.numberOfListeners === 0) {\r\n alert(\"Low memory warning\");\r\n }\r\n MobileApp.onMemoryWarning.raiseEvent();\r\n }\r\n public notifyOrientationChanged() { MobileApp.onOrientationChanged.raiseEvent(); }\r\n public notifyEnterForeground() { MobileApp.onEnterForeground.raiseEvent(); }\r\n public notifyEnterBackground() { MobileApp.onEnterBackground.raiseEvent(); }\r\n public notifyWillTerminate() { MobileApp.onWillTerminate.raiseEvent(); }\r\n public notifyAuthAccessTokenChanged(accessToken: string | undefined, expirationDate: string | undefined) {\r\n MobileApp.onAuthAccessTokenChanged.raiseEvent(accessToken, expirationDate);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport class MobileApp {\r\n public static onMemoryWarning = new BeEvent<() => void>();\r\n public static onOrientationChanged = new BeEvent<() => void>();\r\n public static onEnterForeground = new BeEvent<() => void>();\r\n public static onEnterBackground = new BeEvent<() => void>();\r\n public static onWillTerminate = new BeEvent<() => void>();\r\n public static onAuthAccessTokenChanged = new BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>();\r\n public static async callBackend<T extends AsyncMethodsOf<MobileAppFunctions>>(methodName: T, ...args: Parameters<MobileAppFunctions[T]>) {\r\n return IpcApp.callIpcChannel(mobileAppChannel, methodName, ...args) as PromiseReturnType<MobileAppFunctions[T]>;\r\n }\r\n\r\n private static _isValid = false;\r\n public static get isValid() { return this._isValid; }\r\n /** @beta */\r\n public static async startup(opts?: MobileAppOpts) {\r\n const iModelAppOpts: IModelAppOptions = {\r\n ...opts?.iModelApp,\r\n };\r\n const authorizationClient = new MobileAuthorizationFrontend();\r\n iModelAppOpts.authorizationClient = authorizationClient;\r\n\r\n if (!this._isValid) {\r\n this.onAuthAccessTokenChanged.addListener((accessToken: string | undefined, expirationDate: string | undefined) => {\r\n authorizationClient.setAccessToken(accessToken, expirationDate);\r\n });\r\n\r\n const rpcInterfaces = opts?.iModelApp?.rpcInterfaces ?? [IModelReadRpcInterface, IModelTileRpcInterface];\r\n MobileRpcManager.initializeClient(rpcInterfaces);\r\n this._isValid = true;\r\n }\r\n\r\n const socket = new IpcWebSocketFrontend(); // needs work\r\n await NativeApp.startup(socket, { ...opts, iModelApp: iModelAppOpts });\r\n\r\n MobileAppNotifyHandler.register(); // receives notifications from backend\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-mobile",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0-dev.1",
|
|
4
4
|
"description": "iTwin.js MobileHost and MobileApp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=12.22.0 < 14.0 || >=14.17.0 <
|
|
7
|
+
"node": ">=12.22.0 < 14.0 || >=14.17.0 < 19.0"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"url": "http://www.bentley.com"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@itwin/core-backend": "^3.
|
|
25
|
-
"@itwin/core-bentley": "^3.
|
|
26
|
-
"@itwin/core-common": "^3.
|
|
27
|
-
"@itwin/core-frontend": "^3.
|
|
28
|
-
"@itwin/presentation-common": "^3.
|
|
24
|
+
"@itwin/core-backend": "^3.6.0-dev.1",
|
|
25
|
+
"@itwin/core-bentley": "^3.6.0-dev.1",
|
|
26
|
+
"@itwin/core-common": "^3.6.0-dev.1",
|
|
27
|
+
"@itwin/core-frontend": "^3.6.0-dev.1",
|
|
28
|
+
"@itwin/presentation-common": "^3.6.0-dev.1"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"deep-assign": "^2.0.0",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"ws": "^7.5.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@itwin/build-tools": "3.
|
|
40
|
-
"@itwin/core-backend": "3.
|
|
41
|
-
"@itwin/core-bentley": "3.
|
|
42
|
-
"@itwin/core-common": "3.
|
|
43
|
-
"@itwin/core-frontend": "3.
|
|
44
|
-
"@itwin/eslint-plugin": "3.
|
|
45
|
-
"@itwin/presentation-common": "3.
|
|
39
|
+
"@itwin/build-tools": "3.6.0-dev.1",
|
|
40
|
+
"@itwin/core-backend": "3.6.0-dev.1",
|
|
41
|
+
"@itwin/core-bentley": "3.6.0-dev.1",
|
|
42
|
+
"@itwin/core-common": "3.6.0-dev.1",
|
|
43
|
+
"@itwin/core-frontend": "3.6.0-dev.1",
|
|
44
|
+
"@itwin/eslint-plugin": "3.6.0-dev.1",
|
|
45
|
+
"@itwin/presentation-common": "3.6.0-dev.1",
|
|
46
46
|
"@types/chai": "4.3.1",
|
|
47
47
|
"@types/deep-assign": "^0.1.0",
|
|
48
48
|
"@types/fs-extra": "^4.0.7",
|
|
49
49
|
"@types/lodash": "^4.14.0",
|
|
50
50
|
"@types/mocha": "^8.2.2",
|
|
51
|
-
"@types/node": "
|
|
51
|
+
"@types/node": "18.11.5",
|
|
52
52
|
"@types/qs": "^6.5.0",
|
|
53
53
|
"@types/superagent": "^4.1.14",
|
|
54
54
|
"@types/ws": "^7.0.0",
|