@itwin/core-mobile 3.0.0-extension.0 → 3.1.0-dev.11
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 +76 -1
- package/LICENSE.md +1 -1
- package/lib/cjs/MobileBackend.d.ts +5 -2
- package/lib/cjs/MobileBackend.d.ts.map +1 -1
- package/lib/cjs/MobileBackend.js +5 -2
- package/lib/cjs/MobileBackend.js.map +1 -1
- package/lib/cjs/MobileFrontend.d.ts +4 -1
- package/lib/cjs/MobileFrontend.d.ts.map +1 -1
- package/lib/cjs/MobileFrontend.js +4 -1
- package/lib/cjs/MobileFrontend.js.map +1 -1
- package/lib/cjs/__DOC_ONLY__.d.ts +2 -8
- package/lib/cjs/__DOC_ONLY__.d.ts.map +1 -1
- package/lib/cjs/__DOC_ONLY__.js +2 -8
- package/lib/cjs/__DOC_ONLY__.js.map +1 -1
- package/lib/cjs/backend/MobileAuthorizationBackend.d.ts +48 -6
- package/lib/cjs/backend/MobileAuthorizationBackend.d.ts.map +1 -1
- package/lib/cjs/backend/MobileAuthorizationBackend.js +57 -10
- package/lib/cjs/backend/MobileAuthorizationBackend.js.map +1 -1
- package/lib/cjs/backend/MobileFileHandler.d.ts +28 -3
- package/lib/cjs/backend/MobileFileHandler.d.ts.map +1 -1
- package/lib/cjs/backend/MobileFileHandler.js +39 -8
- package/lib/cjs/backend/MobileFileHandler.js.map +1 -1
- package/lib/cjs/backend/MobileHost.d.ts +7 -10
- package/lib/cjs/backend/MobileHost.d.ts.map +1 -1
- package/lib/cjs/backend/MobileHost.js +6 -15
- package/lib/cjs/backend/MobileHost.js.map +1 -1
- package/lib/cjs/backend/MobileRpcServer.d.ts +1 -0
- package/lib/cjs/backend/MobileRpcServer.d.ts.map +1 -1
- package/lib/cjs/backend/MobileRpcServer.js +2 -1
- package/lib/cjs/backend/MobileRpcServer.js.map +1 -1
- package/lib/cjs/backend/Request.d.ts +150 -0
- package/lib/cjs/backend/Request.d.ts.map +1 -0
- package/lib/cjs/backend/Request.js +268 -0
- package/lib/cjs/backend/Request.js.map +1 -0
- package/lib/cjs/common/MobileAppChannel.d.ts +5 -0
- package/lib/cjs/common/MobileAppChannel.d.ts.map +1 -0
- package/lib/cjs/common/MobileAppChannel.js +12 -0
- package/lib/cjs/common/MobileAppChannel.js.map +1 -0
- package/lib/cjs/common/MobileAppProps.d.ts +5 -5
- package/lib/cjs/common/MobileAppProps.d.ts.map +1 -1
- package/lib/cjs/common/MobileAppProps.js +3 -5
- package/lib/cjs/common/MobileAppProps.js.map +1 -1
- package/lib/cjs/frontend/MobileApp.d.ts +1 -1
- package/lib/cjs/frontend/MobileApp.d.ts.map +1 -1
- package/lib/cjs/frontend/MobileApp.js +4 -4
- package/lib/cjs/frontend/MobileApp.js.map +1 -1
- package/package.json +26 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
1
|
# Change Log - @itwin/core-mobile
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 12 Jan 2022 14:52:38 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 2.19.28
|
|
6
|
+
Wed, 12 Jan 2022 14:52:38 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 2.19.27
|
|
11
|
+
Wed, 05 Jan 2022 20:07:20 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 2.19.26
|
|
16
|
+
Wed, 08 Dec 2021 20:54:53 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
19
|
+
|
|
20
|
+
## 2.19.25
|
|
21
|
+
Fri, 03 Dec 2021 20:05:49 GMT
|
|
22
|
+
|
|
23
|
+
_Version update only_
|
|
24
|
+
|
|
25
|
+
## 2.19.24
|
|
26
|
+
Mon, 29 Nov 2021 18:44:31 GMT
|
|
27
|
+
|
|
28
|
+
_Version update only_
|
|
29
|
+
|
|
30
|
+
## 2.19.23
|
|
31
|
+
Mon, 22 Nov 2021 20:41:40 GMT
|
|
32
|
+
|
|
33
|
+
_Version update only_
|
|
34
|
+
|
|
35
|
+
## 2.19.22
|
|
36
|
+
Wed, 17 Nov 2021 01:23:26 GMT
|
|
37
|
+
|
|
38
|
+
_Version update only_
|
|
39
|
+
|
|
40
|
+
## 2.19.21
|
|
41
|
+
Wed, 10 Nov 2021 10:58:24 GMT
|
|
42
|
+
|
|
43
|
+
_Version update only_
|
|
44
|
+
|
|
45
|
+
## 2.19.20
|
|
46
|
+
Fri, 29 Oct 2021 16:14:22 GMT
|
|
47
|
+
|
|
48
|
+
_Version update only_
|
|
49
|
+
|
|
50
|
+
## 2.19.19
|
|
51
|
+
Mon, 25 Oct 2021 16:16:25 GMT
|
|
52
|
+
|
|
53
|
+
_Version update only_
|
|
54
|
+
|
|
55
|
+
## 2.19.18
|
|
56
|
+
Thu, 21 Oct 2021 20:59:44 GMT
|
|
57
|
+
|
|
58
|
+
_Version update only_
|
|
59
|
+
|
|
60
|
+
## 2.19.17
|
|
61
|
+
Thu, 14 Oct 2021 21:19:43 GMT
|
|
62
|
+
|
|
63
|
+
_Version update only_
|
|
64
|
+
|
|
65
|
+
## 2.19.16
|
|
66
|
+
Mon, 11 Oct 2021 17:37:46 GMT
|
|
67
|
+
|
|
68
|
+
_Version update only_
|
|
69
|
+
|
|
70
|
+
## 2.19.15
|
|
71
|
+
Fri, 08 Oct 2021 16:44:23 GMT
|
|
72
|
+
|
|
73
|
+
_Version update only_
|
|
74
|
+
|
|
75
|
+
## 2.19.14
|
|
76
|
+
Fri, 01 Oct 2021 13:07:03 GMT
|
|
77
|
+
|
|
78
|
+
_Version update only_
|
|
4
79
|
|
|
5
80
|
## 2.19.13
|
|
6
81
|
Tue, 21 Sep 2021 21:06:40 GMT
|
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright © 2017-
|
|
3
|
+
Copyright © 2017-2022 Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from "./backend/AndroidHost";
|
|
2
2
|
export * from "./backend/iOSHost";
|
|
3
|
-
export * from "./backend/MobileHost";
|
|
4
3
|
export * from "./backend/MobileAuthorizationBackend";
|
|
5
|
-
export * from "./common/MobileRpcManager";
|
|
6
4
|
export * from "./backend/MobileFileHandler";
|
|
5
|
+
export * from "./backend/MobileHost";
|
|
6
|
+
export * from "./common/MobileAppProps";
|
|
7
|
+
export * from "./common/MobileRpcManager";
|
|
8
|
+
export * from "./common/MobileRpcProtocol";
|
|
9
|
+
export * from "./common/MobileRpcRequest";
|
|
7
10
|
//# sourceMappingURL=MobileBackend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileBackend.d.ts","sourceRoot":"","sources":["../../src/MobileBackend.ts"],"names":[],"mappings":"AAOA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,
|
|
1
|
+
{"version":3,"file":"MobileBackend.d.ts","sourceRoot":"","sources":["../../src/MobileBackend.ts"],"names":[],"mappings":"AAOA,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sCAAsC,CAAC;AACrD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC"}
|
package/lib/cjs/MobileBackend.js
CHANGED
|
@@ -17,8 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
// Barrel file for backend of a mobile application
|
|
18
18
|
__exportStar(require("./backend/AndroidHost"), exports);
|
|
19
19
|
__exportStar(require("./backend/iOSHost"), exports);
|
|
20
|
-
__exportStar(require("./backend/MobileHost"), exports);
|
|
21
20
|
__exportStar(require("./backend/MobileAuthorizationBackend"), exports);
|
|
22
|
-
__exportStar(require("./common/MobileRpcManager"), exports);
|
|
23
21
|
__exportStar(require("./backend/MobileFileHandler"), exports);
|
|
22
|
+
__exportStar(require("./backend/MobileHost"), exports);
|
|
23
|
+
__exportStar(require("./common/MobileAppProps"), exports);
|
|
24
|
+
__exportStar(require("./common/MobileRpcManager"), exports);
|
|
25
|
+
__exportStar(require("./common/MobileRpcProtocol"), exports);
|
|
26
|
+
__exportStar(require("./common/MobileRpcRequest"), exports);
|
|
24
27
|
//# sourceMappingURL=MobileBackend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileBackend.js","sourceRoot":"","sources":["../../src/MobileBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;AAE/F,kDAAkD;AAElD,wDAAsC;AACtC,oDAAkC;AAClC,uDAAqC;AACrC,
|
|
1
|
+
{"version":3,"file":"MobileBackend.js","sourceRoot":"","sources":["../../src/MobileBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;AAE/F,kDAAkD;AAElD,wDAAsC;AACtC,oDAAkC;AAClC,uEAAqD;AACrD,8DAA4C;AAC5C,uDAAqC;AACrC,0DAAwC;AACxC,4DAA0C;AAC1C,6DAA2C;AAC3C,4DAA0C","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// Barrel file for backend of a mobile application\r\n\r\nexport * from \"./backend/AndroidHost\";\r\nexport * from \"./backend/iOSHost\";\r\nexport * from \"./backend/MobileAuthorizationBackend\";\r\nexport * from \"./backend/MobileFileHandler\";\r\nexport * from \"./backend/MobileHost\";\r\nexport * from \"./common/MobileAppProps\";\r\nexport * from \"./common/MobileRpcManager\";\r\nexport * from \"./common/MobileRpcProtocol\";\r\nexport * from \"./common/MobileRpcRequest\";\r\n"]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export * from "./common/MobileAppProps";
|
|
2
|
+
export * from "./common/MobileRpcManager";
|
|
3
|
+
export * from "./common/MobileRpcProtocol";
|
|
4
|
+
export * from "./common/MobileRpcRequest";
|
|
1
5
|
export * from "./frontend/AndroidApp";
|
|
2
6
|
export * from "./frontend/IOSApp";
|
|
3
7
|
export * from "./frontend/MobileApp";
|
|
4
|
-
export * from "./common/MobileRpcManager";
|
|
5
8
|
//# sourceMappingURL=MobileFrontend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileFrontend.d.ts","sourceRoot":"","sources":["../../src/MobileFrontend.ts"],"names":[],"mappings":"AAKA,cAAc,
|
|
1
|
+
{"version":3,"file":"MobileFrontend.d.ts","sourceRoot":"","sources":["../../src/MobileFrontend.ts"],"names":[],"mappings":"AAKA,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
|
@@ -14,8 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common/MobileAppProps"), exports);
|
|
18
|
+
__exportStar(require("./common/MobileRpcManager"), exports);
|
|
19
|
+
__exportStar(require("./common/MobileRpcProtocol"), exports);
|
|
20
|
+
__exportStar(require("./common/MobileRpcRequest"), exports);
|
|
17
21
|
__exportStar(require("./frontend/AndroidApp"), exports);
|
|
18
22
|
__exportStar(require("./frontend/IOSApp"), exports);
|
|
19
23
|
__exportStar(require("./frontend/MobileApp"), exports);
|
|
20
|
-
__exportStar(require("./common/MobileRpcManager"), exports);
|
|
21
24
|
//# sourceMappingURL=MobileFrontend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileFrontend.js","sourceRoot":"","sources":["../../src/MobileFrontend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;AAE/F,wDAAsC;AACtC,oDAAkC;AAClC,uDAAqC
|
|
1
|
+
{"version":3,"file":"MobileFrontend.js","sourceRoot":"","sources":["../../src/MobileFrontend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;AAE/F,0DAAwC;AACxC,4DAA0C;AAC1C,6DAA2C;AAC3C,4DAA0C;AAC1C,wDAAsC;AACtC,oDAAkC;AAClC,uDAAqC","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\nexport * from \"./common/MobileAppProps\";\r\nexport * from \"./common/MobileRpcManager\";\r\nexport * from \"./common/MobileRpcProtocol\";\r\nexport * from \"./common/MobileRpcRequest\";\r\nexport * from \"./frontend/AndroidApp\";\r\nexport * from \"./frontend/IOSApp\";\r\nexport * from \"./frontend/MobileApp\";\r\n"]}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./frontend/MobileApp";
|
|
4
|
-
export * from "./common/MobileRpcManager";
|
|
5
|
-
export * from "./backend/AndroidHost";
|
|
6
|
-
export * from "./backend/iOSHost";
|
|
7
|
-
export * from "./backend/MobileHost";
|
|
8
|
-
export * from "./common/MobileRpcManager";
|
|
1
|
+
export * from "./MobileBackend";
|
|
2
|
+
export * from "./MobileFrontend";
|
|
9
3
|
//# sourceMappingURL=__DOC_ONLY__.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__DOC_ONLY__.d.ts","sourceRoot":"","sources":["../../src/__DOC_ONLY__.ts"],"names":[],"mappings":"AASA,cAAc,
|
|
1
|
+
{"version":3,"file":"__DOC_ONLY__.d.ts","sourceRoot":"","sources":["../../src/__DOC_ONLY__.ts"],"names":[],"mappings":"AASA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
package/lib/cjs/__DOC_ONLY__.js
CHANGED
|
@@ -17,12 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
// THIS FILE EXISTS ONLY FOR DOCUMENTATION GENERATION.
|
|
18
18
|
// It imports both frontend and backend code, which is not legal anywhere.
|
|
19
19
|
// Do not import it in real code!
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./frontend/MobileApp"), exports);
|
|
23
|
-
__exportStar(require("./common/MobileRpcManager"), exports);
|
|
24
|
-
__exportStar(require("./backend/AndroidHost"), exports);
|
|
25
|
-
__exportStar(require("./backend/iOSHost"), exports);
|
|
26
|
-
__exportStar(require("./backend/MobileHost"), exports);
|
|
27
|
-
__exportStar(require("./common/MobileRpcManager"), exports);
|
|
20
|
+
__exportStar(require("./MobileBackend"), exports);
|
|
21
|
+
__exportStar(require("./MobileFrontend"), exports);
|
|
28
22
|
//# sourceMappingURL=__DOC_ONLY__.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__DOC_ONLY__.js","sourceRoot":"","sources":["../../src/__DOC_ONLY__.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;AAE/F,sDAAsD;AACtD,0EAA0E;AAC1E,iCAAiC;AAEjC,
|
|
1
|
+
{"version":3,"file":"__DOC_ONLY__.js","sourceRoot":"","sources":["../../src/__DOC_ONLY__.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;AAE/F,sDAAsD;AACtD,0EAA0E;AAC1E,iCAAiC;AAEjC,kDAAgC;AAChC,mDAAiC","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// THIS FILE EXISTS ONLY FOR DOCUMENTATION GENERATION.\r\n// It imports both frontend and backend code, which is not legal anywhere.\r\n// Do not import it in real code!\r\n\r\nexport * from \"./MobileBackend\";\r\nexport * from \"./MobileFrontend\";\r\n"]}
|
|
@@ -2,22 +2,64 @@
|
|
|
2
2
|
* @module OIDC
|
|
3
3
|
*/
|
|
4
4
|
import { AccessToken } from "@itwin/core-bentley";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { AuthorizationClient } from "@itwin/core-common";
|
|
6
|
+
/**
|
|
7
|
+
* Client configuration to generate OIDC/OAuth tokens for mobile applications
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export interface MobileAppAuthorizationConfiguration {
|
|
11
|
+
/**
|
|
12
|
+
* The OAuth token issuer URL. Defaults to Bentley's auth URL if undefined.
|
|
13
|
+
*/
|
|
14
|
+
issuerUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Upon signing in, the client application receives a response from the Bentley IMS OIDC/OAuth2 provider at this URI
|
|
17
|
+
* For mobile/desktop applications, must start with `http://localhost:${redirectPort}` or `https://localhost:${redirectPort}`
|
|
18
|
+
*/
|
|
19
|
+
readonly redirectUri?: string;
|
|
20
|
+
/** Client application's identifier as registered with the OIDC/OAuth2 provider. */
|
|
21
|
+
readonly clientId: string;
|
|
22
|
+
/** List of space separated scopes to request access to various resources. */
|
|
23
|
+
readonly scope: string;
|
|
24
|
+
/**
|
|
25
|
+
* Time in seconds that's used as a buffer to check the token for validity/expiry.
|
|
26
|
+
* The checks for authorization, and refreshing access tokens all use this buffer - i.e., the token is considered expired if the current time is within the specified
|
|
27
|
+
* time of the actual expiry.
|
|
28
|
+
* @note If unspecified this defaults to 10 minutes.
|
|
29
|
+
*/
|
|
30
|
+
readonly expiryBuffer?: number;
|
|
31
|
+
}
|
|
7
32
|
/** Utility to provide OIDC/OAuth tokens from native ios app to frontend
|
|
8
|
-
* @
|
|
33
|
+
* @beta
|
|
9
34
|
*/
|
|
10
|
-
export declare class MobileAuthorizationBackend
|
|
35
|
+
export declare class MobileAuthorizationBackend implements AuthorizationClient {
|
|
36
|
+
protected _accessToken?: AccessToken;
|
|
37
|
+
config?: MobileAppAuthorizationConfiguration;
|
|
38
|
+
expireSafety: number;
|
|
39
|
+
issuerUrl?: string;
|
|
11
40
|
static defaultRedirectUri: string;
|
|
12
41
|
get redirectUri(): string;
|
|
13
|
-
|
|
42
|
+
protected _baseUrl: string;
|
|
43
|
+
protected _url?: string;
|
|
44
|
+
constructor(config?: MobileAppAuthorizationConfiguration);
|
|
14
45
|
/** Used to initialize the client - must be awaited before any other methods are called */
|
|
15
|
-
initialize(config?:
|
|
46
|
+
initialize(config?: MobileAppAuthorizationConfiguration): Promise<void>;
|
|
16
47
|
/** Start the sign-in process */
|
|
17
48
|
signIn(): Promise<void>;
|
|
18
49
|
/** Start the sign-out process */
|
|
19
50
|
signOut(): Promise<void>;
|
|
51
|
+
setAccessToken(token?: AccessToken): void;
|
|
52
|
+
getAccessToken(): Promise<AccessToken>;
|
|
20
53
|
/** return accessToken */
|
|
21
54
|
refreshToken(): Promise<AccessToken>;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the URL of the service. Uses the default URL provided by client implementations.
|
|
57
|
+
* If defined, the value of `IMJS_URL_PREFIX` will be used as a prefix to all urls provided
|
|
58
|
+
* by the client implementations.
|
|
59
|
+
*
|
|
60
|
+
* Note that for consistency sake, the URL is stripped of any trailing "/".
|
|
61
|
+
* @returns URL for the service
|
|
62
|
+
*/
|
|
63
|
+
private getUrl;
|
|
22
64
|
}
|
|
23
65
|
//# sourceMappingURL=MobileAuthorizationBackend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileAuthorizationBackend.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileAuthorizationBackend.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"MobileAuthorizationBackend.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileAuthorizationBackend.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAsB,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAe,MAAM,oBAAoB,CAAC;AAGtE;;;GAGG;AACH,MAAM,WAAW,mCAAmC;IAClD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B,mFAAmF;IACnF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IACpE,SAAS,CAAC,YAAY,CAAC,EAAE,WAAW,CAAC;IAC9B,MAAM,CAAC,EAAE,mCAAmC,CAAC;IAC7C,YAAY,SAAW;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAc,kBAAkB,SAAoC;IACpE,IAAW,WAAW,WAAwF;IAC9G,SAAS,CAAC,QAAQ,SAA6B;IAC/C,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEL,MAAM,CAAC,EAAE,mCAAmC;IAI/D,0FAA0F;IAC7E,UAAU,CAAC,MAAM,CAAC,EAAE,mCAAmC,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BpF,gCAAgC;IACnB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAYpC,iCAAiC;IACpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAY9B,cAAc,CAAC,KAAK,CAAC,EAAE,WAAW;IAM5B,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAMnD,yBAAyB;IACZ,YAAY,IAAI,OAAO,CAAC,WAAW,CAAC;IAYjD;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM;CAiBf"}
|
|
@@ -9,22 +9,31 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.MobileAuthorizationBackend = void 0;
|
|
11
11
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
-
const
|
|
12
|
+
const core_common_1 = require("@itwin/core-common");
|
|
13
13
|
const MobileHost_1 = require("./MobileHost");
|
|
14
14
|
/** Utility to provide OIDC/OAuth tokens from native ios app to frontend
|
|
15
|
-
* @
|
|
15
|
+
* @beta
|
|
16
16
|
*/
|
|
17
|
-
class MobileAuthorizationBackend
|
|
17
|
+
class MobileAuthorizationBackend {
|
|
18
18
|
constructor(config) {
|
|
19
|
-
|
|
19
|
+
this.expireSafety = 60 * 10; // refresh token 10 minutes before real expiration time
|
|
20
|
+
this._baseUrl = "https://ims.bentley.com";
|
|
21
|
+
this.config = config;
|
|
20
22
|
}
|
|
21
23
|
get redirectUri() { var _a, _b; return (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.redirectUri) !== null && _b !== void 0 ? _b : MobileAuthorizationBackend.defaultRedirectUri; }
|
|
22
24
|
/** Used to initialize the client - must be awaited before any other methods are called */
|
|
23
25
|
async initialize(config) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
var _a;
|
|
27
|
+
this.config = config !== null && config !== void 0 ? config : this.config;
|
|
28
|
+
if (!this.config)
|
|
29
|
+
throw new core_common_1.IModelError(core_bentley_1.AuthStatus.Error, "Must specify a valid configuration when initializing authorization");
|
|
30
|
+
if (this.config.expiryBuffer)
|
|
31
|
+
this.expireSafety = this.config.expiryBuffer;
|
|
32
|
+
this.issuerUrl = (_a = this.config.issuerUrl) !== null && _a !== void 0 ? _a : this.getUrl();
|
|
33
|
+
if (!this.issuerUrl)
|
|
34
|
+
throw new core_common_1.IModelError(core_bentley_1.AuthStatus.Error, "The URL of the authorization provider was not initialized");
|
|
26
35
|
MobileHost_1.MobileHost.device.authStateChanged = (tokenString) => {
|
|
27
|
-
this.setAccessToken(tokenString
|
|
36
|
+
this.setAccessToken(tokenString);
|
|
28
37
|
};
|
|
29
38
|
return new Promise((resolve, reject) => {
|
|
30
39
|
(0, core_bentley_1.assert)(this.config !== undefined);
|
|
@@ -64,14 +73,52 @@ class MobileAuthorizationBackend extends core_backend_1.NativeAppAuthorizationBa
|
|
|
64
73
|
});
|
|
65
74
|
});
|
|
66
75
|
}
|
|
76
|
+
setAccessToken(token) {
|
|
77
|
+
if (token === this._accessToken)
|
|
78
|
+
return;
|
|
79
|
+
this._accessToken = token;
|
|
80
|
+
}
|
|
81
|
+
async getAccessToken() {
|
|
82
|
+
var _a;
|
|
83
|
+
if (!this._accessToken)
|
|
84
|
+
this.setAccessToken(await this.refreshToken());
|
|
85
|
+
return (_a = this._accessToken) !== null && _a !== void 0 ? _a : "";
|
|
86
|
+
}
|
|
67
87
|
/** return accessToken */
|
|
68
88
|
async refreshToken() {
|
|
69
|
-
return new Promise((resolve) => {
|
|
70
|
-
MobileHost_1.MobileHost.device.authGetAccessToken((tokenStringJson) => {
|
|
71
|
-
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
MobileHost_1.MobileHost.device.authGetAccessToken((tokenStringJson, err) => {
|
|
91
|
+
if (!err && tokenStringJson) {
|
|
92
|
+
resolve(tokenStringJson);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
reject(new Error(err));
|
|
96
|
+
}
|
|
72
97
|
});
|
|
73
98
|
});
|
|
74
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets the URL of the service. Uses the default URL provided by client implementations.
|
|
102
|
+
* If defined, the value of `IMJS_URL_PREFIX` will be used as a prefix to all urls provided
|
|
103
|
+
* by the client implementations.
|
|
104
|
+
*
|
|
105
|
+
* Note that for consistency sake, the URL is stripped of any trailing "/".
|
|
106
|
+
* @returns URL for the service
|
|
107
|
+
*/
|
|
108
|
+
getUrl() {
|
|
109
|
+
var _a, _b, _c;
|
|
110
|
+
if (this._url)
|
|
111
|
+
return this._url;
|
|
112
|
+
if (!this._baseUrl) {
|
|
113
|
+
throw new Error("The client is missing a default url.");
|
|
114
|
+
}
|
|
115
|
+
const prefix = process.env.IMJS_URL_PREFIX;
|
|
116
|
+
const authority = new URL((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.issuerUrl) !== null && _b !== void 0 ? _b : this._baseUrl);
|
|
117
|
+
if (prefix && !((_c = this.config) === null || _c === void 0 ? void 0 : _c.issuerUrl))
|
|
118
|
+
authority.hostname = prefix + authority.hostname;
|
|
119
|
+
this._url = authority.href.replace(/\/$/, "");
|
|
120
|
+
return this._url;
|
|
121
|
+
}
|
|
75
122
|
}
|
|
76
123
|
exports.MobileAuthorizationBackend = MobileAuthorizationBackend;
|
|
77
124
|
MobileAuthorizationBackend.defaultRedirectUri = "imodeljs://app/signin-callback";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileAuthorizationBackend.js","sourceRoot":"","sources":["../../../src/backend/MobileAuthorizationBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"MobileAuthorizationBackend.js","sourceRoot":"","sources":["../../../src/backend/MobileAuthorizationBackend.ts"],"names":[],"mappings":";AAA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AC;QAE9C,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;;AApHH,gEAqHC;AAhHe,6CAAkB,GAAG,gCAAgC,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 OIDC\r\n */\r\n\r\nimport { AccessToken, assert, AuthStatus } from \"@itwin/core-bentley\";\r\nimport { AuthorizationClient, IModelError } from \"@itwin/core-common\";\r\nimport { MobileHost } from \"./MobileHost\";\r\n\r\n/**\r\n * Client configuration to generate OIDC/OAuth tokens for mobile applications\r\n * @beta\r\n */\r\nexport interface MobileAppAuthorizationConfiguration {\r\n /**\r\n * The OAuth token issuer URL. Defaults to Bentley's auth URL if undefined.\r\n */\r\n issuerUrl?: string;\r\n\r\n /**\r\n * Upon signing in, the client application receives a response from the Bentley IMS OIDC/OAuth2 provider at this URI\r\n * For mobile/desktop applications, must start with `http://localhost:${redirectPort}` or `https://localhost:${redirectPort}`\r\n */\r\n readonly redirectUri?: string;\r\n\r\n /** Client application's identifier as registered with the OIDC/OAuth2 provider. */\r\n readonly clientId: string;\r\n\r\n /** List of space separated scopes to request access to various resources. */\r\n readonly scope: string;\r\n\r\n /**\r\n * Time in seconds that's used as a buffer to check the token for validity/expiry.\r\n * The checks for authorization, and refreshing access tokens all use this buffer - i.e., the token is considered expired if the current time is within the specified\r\n * time of the actual expiry.\r\n * @note If unspecified this defaults to 10 minutes.\r\n */\r\n readonly expiryBuffer?: number;\r\n}\r\n\r\n/** Utility to provide OIDC/OAuth tokens from native ios app to frontend\r\n * @beta\r\n */\r\nexport class MobileAuthorizationBackend implements AuthorizationClient {\r\n protected _accessToken?: AccessToken;\r\n public config?: MobileAppAuthorizationConfiguration;\r\n public expireSafety = 60 * 10; // refresh token 10 minutes before real expiration time\r\n public issuerUrl?: string;\r\n public static defaultRedirectUri = \"imodeljs://app/signin-callback\";\r\n public get redirectUri() { return this.config?.redirectUri ?? MobileAuthorizationBackend.defaultRedirectUri; }\r\n protected _baseUrl = \"https://ims.bentley.com\";\r\n protected _url?: string;\r\n\r\n public constructor(config?: MobileAppAuthorizationConfiguration) {\r\n this.config = config;\r\n }\r\n\r\n /** Used to initialize the client - must be awaited before any other methods are called */\r\n public async initialize(config?: MobileAppAuthorizationConfiguration): Promise<void> {\r\n this.config = config ?? this.config;\r\n if (!this.config)\r\n throw new IModelError(AuthStatus.Error, \"Must specify a valid configuration when initializing authorization\");\r\n if (this.config.expiryBuffer)\r\n this.expireSafety = this.config.expiryBuffer;\r\n this.issuerUrl = this.config.issuerUrl ?? this.getUrl();\r\n if (!this.issuerUrl)\r\n throw new IModelError(AuthStatus.Error, \"The URL of the authorization provider was not initialized\");\r\n\r\n MobileHost.device.authStateChanged = (tokenString?: AccessToken) => {\r\n this.setAccessToken(tokenString);\r\n };\r\n\r\n return new Promise<void>((resolve, reject) => {\r\n assert(this.config !== undefined);\r\n MobileHost.device.authInit({ ...this.config, issuerUrl: this.issuerUrl }, (err?: string) => {\r\n if (!err) {\r\n resolve();\r\n } else {\r\n reject(new Error(err));\r\n }\r\n });\r\n });\r\n }\r\n\r\n /** Start the sign-in process */\r\n public async signIn(): Promise<void> {\r\n return new Promise<void>((resolve, reject) => {\r\n MobileHost.device.authSignIn((err?: string) => {\r\n if (!err) {\r\n resolve();\r\n } else {\r\n reject(new Error(err));\r\n }\r\n });\r\n });\r\n }\r\n\r\n /** Start the sign-out process */\r\n public async signOut(): Promise<void> {\r\n return new Promise<void>((resolve, reject) => {\r\n MobileHost.device.authSignOut((err?: string) => {\r\n if (!err) {\r\n resolve();\r\n } else {\r\n reject(new Error(err));\r\n }\r\n });\r\n });\r\n }\r\n\r\n public setAccessToken(token?: AccessToken) {\r\n if (token === this._accessToken)\r\n return;\r\n this._accessToken = token;\r\n }\r\n\r\n public async getAccessToken(): Promise<AccessToken> {\r\n if (!this._accessToken)\r\n this.setAccessToken(await this.refreshToken());\r\n return this._accessToken ?? \"\";\r\n }\r\n\r\n /** return accessToken */\r\n public async refreshToken(): Promise<AccessToken> {\r\n return new Promise<AccessToken>((resolve, reject) => {\r\n MobileHost.device.authGetAccessToken((tokenStringJson?: AccessToken, err?: string) => {\r\n if (!err && tokenStringJson) {\r\n resolve(tokenStringJson);\r\n } else {\r\n reject(new Error(err));\r\n }\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Gets the URL of the service. Uses the default URL provided by client implementations.\r\n * If defined, the value of `IMJS_URL_PREFIX` will be used as a prefix to all urls provided\r\n * by the client implementations.\r\n *\r\n * Note that for consistency sake, the URL is stripped of any trailing \"/\".\r\n * @returns URL for the service\r\n */\r\n private getUrl(): string {\r\n if (this._url)\r\n return this._url;\r\n\r\n if (!this._baseUrl) {\r\n throw new Error(\"The client is missing a default url.\");\r\n }\r\n\r\n const prefix = process.env.IMJS_URL_PREFIX;\r\n const authority = new URL(this.config?.issuerUrl ?? this._baseUrl);\r\n\r\n if (prefix && !this.config?.issuerUrl)\r\n authority.hostname = prefix + authority.hostname;\r\n this._url = authority.href.replace(/\\/$/, \"\");\r\n\r\n return this._url;\r\n }\r\n}\r\n"]}
|
|
@@ -3,13 +3,38 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/// <reference types="node" />
|
|
5
5
|
import * as https from "https";
|
|
6
|
-
import { AccessToken } from "@itwin/core-bentley";
|
|
7
|
-
import {
|
|
6
|
+
import { AccessToken, BentleyError, GetMetaDataFunction } from "@itwin/core-bentley";
|
|
7
|
+
import { ProgressCallback } from "./Request";
|
|
8
|
+
/** Interface to cancel a request
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export interface CancelRequest {
|
|
12
|
+
/** Returns true if cancel request was acknowledged */
|
|
13
|
+
cancel: () => boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Error thrown when user cancelled operation
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare class UserCancelledError extends BentleyError {
|
|
19
|
+
constructor(errorNumber: number, message: string, getMetaData?: GetMetaDataFunction);
|
|
20
|
+
}
|
|
21
|
+
/** Error thrown fail to download file. ErrorNumber will correspond to HTTP error code.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare class DownloadFailed extends BentleyError {
|
|
25
|
+
constructor(errorNumber: number, message: string, getMetaData?: GetMetaDataFunction);
|
|
26
|
+
}
|
|
27
|
+
/** Error thrown when sas-url provided for download has expired
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare class SasUrlExpired extends BentleyError {
|
|
31
|
+
constructor(errorNumber: number, message: string, getMetaData?: GetMetaDataFunction);
|
|
32
|
+
}
|
|
8
33
|
/**
|
|
9
34
|
* 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.
|
|
10
35
|
* @internal
|
|
11
36
|
*/
|
|
12
|
-
export declare class MobileFileHandler
|
|
37
|
+
export declare class MobileFileHandler {
|
|
13
38
|
/** @internal */
|
|
14
39
|
agent?: https.Agent;
|
|
15
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileFileHandler.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileFileHandler.ts"],"names":[],"mappings":"AAIA;;GAEG;;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAU,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"MobileFileHandler.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileFileHandler.ts"],"names":[],"mappings":"AAIA;;GAEG;;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAU,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAyC,MAAM,WAAW,CAAC;AAWpF;;IAEI;AAC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AO,CAAC,IAAI,CAAC;IA6C1J;;;;OAIG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAI5C;;;;OAIG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI7C;;;;OAIG;IACI,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIxC;;;OAGG;IACI,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIrC;;;;OAIG;IACI,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIzC;;;;OAIG;IACI,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;CAGxC"}
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* @module iModelHub
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.MobileFileHandler = void 0;
|
|
10
|
+
exports.MobileFileHandler = exports.SasUrlExpired = exports.DownloadFailed = exports.UserCancelledError = void 0;
|
|
11
11
|
const fs = require("fs");
|
|
12
12
|
const path = require("path");
|
|
13
13
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
14
|
-
const
|
|
14
|
+
const Request_1 = require("./Request");
|
|
15
15
|
const MobileHost_1 = require("./MobileHost");
|
|
16
16
|
const js_base64_1 = require("js-base64");
|
|
17
17
|
const loggerCategory = "mobile.filehandler";
|
|
@@ -19,6 +19,36 @@ const defined = (argumentName, argument, allowEmpty = false) => {
|
|
|
19
19
|
if (argument === undefined || argument === null || (argument === "" && !allowEmpty))
|
|
20
20
|
throw Error(`Argument ${argumentName} is null or undefined`);
|
|
21
21
|
};
|
|
22
|
+
/** Error thrown when user cancelled operation
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
class UserCancelledError extends core_bentley_1.BentleyError {
|
|
26
|
+
constructor(errorNumber, message, getMetaData) {
|
|
27
|
+
super(errorNumber, message, getMetaData);
|
|
28
|
+
this.name = "User cancelled operation";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.UserCancelledError = UserCancelledError;
|
|
32
|
+
/** Error thrown fail to download file. ErrorNumber will correspond to HTTP error code.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
class DownloadFailed extends core_bentley_1.BentleyError {
|
|
36
|
+
constructor(errorNumber, message, getMetaData) {
|
|
37
|
+
super(errorNumber, message, getMetaData);
|
|
38
|
+
this.name = "Fail to download file";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.DownloadFailed = DownloadFailed;
|
|
42
|
+
/** Error thrown when sas-url provided for download has expired
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
class SasUrlExpired extends core_bentley_1.BentleyError {
|
|
46
|
+
constructor(errorNumber, message, getMetaData) {
|
|
47
|
+
super(errorNumber, message, getMetaData);
|
|
48
|
+
this.name = "SaS url has expired";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.SasUrlExpired = SasUrlExpired;
|
|
22
52
|
/**
|
|
23
53
|
* 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.
|
|
24
54
|
* @internal
|
|
@@ -83,7 +113,7 @@ class MobileFileHandler {
|
|
|
83
113
|
defined("downloadToPathname", downloadToPathname);
|
|
84
114
|
if (MobileFileHandler.isUrlExpired(downloadUrl)) {
|
|
85
115
|
core_bentley_1.Logger.logError(loggerCategory, `Sas url has expired ${safeToLogUrl}`);
|
|
86
|
-
throw new
|
|
116
|
+
throw new SasUrlExpired(403, "Download URL has expired");
|
|
87
117
|
}
|
|
88
118
|
if (fs.existsSync(downloadToPathname))
|
|
89
119
|
fs.unlinkSync(downloadToPathname);
|
|
@@ -94,7 +124,7 @@ class MobileFileHandler {
|
|
|
94
124
|
catch (err) {
|
|
95
125
|
if (fs.existsSync(downloadToPathname))
|
|
96
126
|
fs.unlinkSync(downloadToPathname); // Just in case there was a partial download, delete the file
|
|
97
|
-
if (!(err instanceof
|
|
127
|
+
if (!(err instanceof UserCancelledError))
|
|
98
128
|
core_bentley_1.Logger.logError(loggerCategory, `Error downloading file`);
|
|
99
129
|
throw err;
|
|
100
130
|
}
|
|
@@ -102,7 +132,7 @@ class MobileFileHandler {
|
|
|
102
132
|
if (fs.lstatSync(downloadToPathname).size !== fileSize) {
|
|
103
133
|
fs.unlinkSync(downloadToPathname);
|
|
104
134
|
core_bentley_1.Logger.logError(loggerCategory, `Downloaded file is of incorrect size ${safeToLogUrl}`);
|
|
105
|
-
throw new
|
|
135
|
+
throw new DownloadFailed(403, "Download failed. Expected filesize does not match");
|
|
106
136
|
}
|
|
107
137
|
}
|
|
108
138
|
core_bentley_1.Logger.logTrace(loggerCategory, `Downloaded file from ${safeToLogUrl}`);
|
|
@@ -132,7 +162,7 @@ class MobileFileHandler {
|
|
|
132
162
|
},
|
|
133
163
|
};
|
|
134
164
|
const uploadUrl = `${uploadUrlString}&comp=block&blockid=${this.getBlockId(blockId)}`;
|
|
135
|
-
await (0,
|
|
165
|
+
await (0, Request_1.request)(uploadUrl, options);
|
|
136
166
|
}
|
|
137
167
|
/**
|
|
138
168
|
* Upload a file to AzureBlobStorage for iModelHub.
|
|
@@ -154,7 +184,8 @@ class MobileFileHandler {
|
|
|
154
184
|
let i = 0;
|
|
155
185
|
const callback = (progress) => {
|
|
156
186
|
const uploaded = i * chunkSize + progress.loaded;
|
|
157
|
-
progressCallback
|
|
187
|
+
if (progressCallback)
|
|
188
|
+
progressCallback({ loaded: uploaded, percent: uploaded / fileSize, total: fileSize });
|
|
158
189
|
};
|
|
159
190
|
for (; i * chunkSize < fileSize; ++i) {
|
|
160
191
|
await this.uploadChunk(accessToken, uploadUrlString, file, i, progressCallback ? callback : undefined);
|
|
@@ -175,7 +206,7 @@ class MobileFileHandler {
|
|
|
175
206
|
},
|
|
176
207
|
};
|
|
177
208
|
const uploadUrl = `${uploadUrlString}&comp=blocklist`;
|
|
178
|
-
await (0,
|
|
209
|
+
await (0, Request_1.request)(uploadUrl, options);
|
|
179
210
|
}
|
|
180
211
|
finally {
|
|
181
212
|
fs.closeSync(file);
|