@itwin/core-mobile 3.0.0-dev.127 → 3.0.0-dev.128
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/MobileAuthorizationBackend.d.ts +49 -7
- package/lib/cjs/backend/MobileAuthorizationBackend.d.ts.map +1 -1
- package/lib/cjs/backend/MobileAuthorizationBackend.js +59 -11
- package/lib/cjs/backend/MobileAuthorizationBackend.js.map +1 -1
- package/lib/cjs/backend/MobileHost.d.ts +5 -5
- package/lib/cjs/backend/MobileHost.d.ts.map +1 -1
- package/lib/cjs/backend/MobileHost.js.map +1 -1
- package/package.json +15 -15
|
@@ -2,22 +2,64 @@
|
|
|
2
2
|
* @module OIDC
|
|
3
3
|
*/
|
|
4
4
|
import { AccessToken } from "@itwin/core-bentley";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @
|
|
5
|
+
import { AuthorizationClient } from "@itwin/core-common";
|
|
6
|
+
/**
|
|
7
|
+
* Client configuration to generate OIDC/OAuth tokens for mobile applications
|
|
8
|
+
* @beta
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
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
|
+
}
|
|
32
|
+
/** Utility to provide OIDC/OAuth tokens from native ios app to frontend
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
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;;KAEK;AACL,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;IAM/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;IAWjD;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM;CAiBf"}
|
|
@@ -9,22 +9,32 @@
|
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
class MobileAuthorizationBackend
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
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; }
|
|
24
|
+
// public getClientRequestContext() { return ClientRequestContext.fromJSON(IModelHost.session); }
|
|
22
25
|
/** Used to initialize the client - must be awaited before any other methods are called */
|
|
23
26
|
async initialize(config) {
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
var _a;
|
|
28
|
+
this.config = config !== null && config !== void 0 ? config : this.config;
|
|
29
|
+
if (!this.config)
|
|
30
|
+
throw new core_common_1.IModelError(core_bentley_1.AuthStatus.Error, "Must specify a valid configuration when initializing authorization");
|
|
31
|
+
if (this.config.expiryBuffer)
|
|
32
|
+
this.expireSafety = this.config.expiryBuffer;
|
|
33
|
+
this.issuerUrl = (_a = this.config.issuerUrl) !== null && _a !== void 0 ? _a : this.getUrl();
|
|
34
|
+
if (!this.issuerUrl)
|
|
35
|
+
throw new core_common_1.IModelError(core_bentley_1.AuthStatus.Error, "The URL of the authorization provider was not initialized");
|
|
26
36
|
MobileHost_1.MobileHost.device.authStateChanged = (tokenString) => {
|
|
27
|
-
this.setAccessToken(tokenString
|
|
37
|
+
this.setAccessToken(tokenString);
|
|
28
38
|
};
|
|
29
39
|
return new Promise((resolve, reject) => {
|
|
30
40
|
(0, core_bentley_1.assert)(this.config !== undefined);
|
|
@@ -64,14 +74,52 @@ class MobileAuthorizationBackend extends core_backend_1.NativeAppAuthorizationBa
|
|
|
64
74
|
});
|
|
65
75
|
});
|
|
66
76
|
}
|
|
77
|
+
setAccessToken(token) {
|
|
78
|
+
if (token === this._accessToken)
|
|
79
|
+
return;
|
|
80
|
+
this._accessToken = token;
|
|
81
|
+
}
|
|
82
|
+
async getAccessToken() {
|
|
83
|
+
var _a;
|
|
84
|
+
if (!this._accessToken)
|
|
85
|
+
this.setAccessToken(await this.refreshToken());
|
|
86
|
+
return (_a = this._accessToken) !== null && _a !== void 0 ? _a : "";
|
|
87
|
+
}
|
|
67
88
|
/** return accessToken */
|
|
68
89
|
async refreshToken() {
|
|
69
|
-
return new Promise((resolve) => {
|
|
70
|
-
MobileHost_1.MobileHost.device.authGetAccessToken((tokenStringJson) => {
|
|
71
|
-
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
MobileHost_1.MobileHost.device.authGetAccessToken((tokenStringJson, err) => {
|
|
92
|
+
if (!err && tokenStringJson) {
|
|
93
|
+
resolve(tokenStringJson);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
reject(new Error(err));
|
|
97
|
+
}
|
|
72
98
|
});
|
|
73
99
|
});
|
|
74
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Gets the URL of the service. Uses the default URL provided by client implementations.
|
|
103
|
+
* If defined, the value of `IMJS_URL_PREFIX` will be used as a prefix to all urls provided
|
|
104
|
+
* by the client implementations.
|
|
105
|
+
*
|
|
106
|
+
* Note that for consistency sake, the URL is stripped of any trailing "/".
|
|
107
|
+
* @returns URL for the service
|
|
108
|
+
*/
|
|
109
|
+
getUrl() {
|
|
110
|
+
var _a, _b, _c;
|
|
111
|
+
if (this._url)
|
|
112
|
+
return this._url;
|
|
113
|
+
if (!this._baseUrl) {
|
|
114
|
+
throw new Error("The client is missing a default url.");
|
|
115
|
+
}
|
|
116
|
+
const prefix = process.env.IMJS_URL_PREFIX;
|
|
117
|
+
const authority = new URL((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.issuerUrl) !== null && _b !== void 0 ? _b : this._baseUrl);
|
|
118
|
+
if (prefix && !((_c = this.config) === null || _c === void 0 ? void 0 : _c.issuerUrl))
|
|
119
|
+
authority.hostname = prefix + authority.hostname;
|
|
120
|
+
this._url = authority.href.replace(/\/$/, "");
|
|
121
|
+
return this._url;
|
|
122
|
+
}
|
|
75
123
|
}
|
|
76
124
|
exports.MobileAuthorizationBackend = MobileAuthorizationBackend;
|
|
77
125
|
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":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAsE;AACtE,oDAAsE;AACtE,6CAA0C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HH,gEAsHC;AAjHe,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 * @internal\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 // public getClientRequestContext() { return ClientRequestContext.fromJSON(IModelHost.session); }\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 * 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"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BeEvent } from "@itwin/core-bentley";
|
|
2
2
|
import { NativeHostOpts } from "@itwin/core-backend";
|
|
3
|
-
import {
|
|
3
|
+
import { RpcInterfaceDefinition } from "@itwin/core-common";
|
|
4
4
|
import { CancelRequest, ProgressCallback } from "@bentley/itwin-client";
|
|
5
5
|
import { BatteryState, DeviceEvents, Orientation } from "../common/MobileAppProps";
|
|
6
|
-
import { MobileAuthorizationBackend } from "./MobileAuthorizationBackend";
|
|
6
|
+
import { MobileAppAuthorizationConfiguration, MobileAuthorizationBackend } from "./MobileAuthorizationBackend";
|
|
7
7
|
/** @beta */
|
|
8
8
|
export declare type MobileCompletionCallback = (downloadUrl: string, downloadFileUrl: string, cancelled: boolean, err?: string) => void;
|
|
9
9
|
/** @beta */
|
|
@@ -39,7 +39,7 @@ export declare abstract class MobileDevice {
|
|
|
39
39
|
abstract authSignIn(callback: (err?: string) => void): void;
|
|
40
40
|
abstract authSignOut(callback: (err?: string) => void): void;
|
|
41
41
|
abstract authGetAccessToken(callback: (accessToken?: string, err?: string) => void): void;
|
|
42
|
-
authInit(_config:
|
|
42
|
+
authInit(_config: MobileAppAuthorizationConfiguration, callback: (err?: string) => void): void;
|
|
43
43
|
abstract authStateChanged(accessToken?: string, err?: string): void;
|
|
44
44
|
}
|
|
45
45
|
/** @beta */
|
|
@@ -48,8 +48,8 @@ export interface MobileHostOpts extends NativeHostOpts {
|
|
|
48
48
|
device?: MobileDevice;
|
|
49
49
|
/** list of RPC interface definitions to register */
|
|
50
50
|
rpcInterfaces?: RpcInterfaceDefinition[];
|
|
51
|
-
/** if present, [[NativeHost.authorizationClient]] will be set to an instance of
|
|
52
|
-
authConfig?:
|
|
51
|
+
/** if present, [[NativeHost.authorizationClient]] will be set to an instance of MobileAppAuthorizationConfiguration and will be initialized. */
|
|
52
|
+
authConfig?: MobileAppAuthorizationConfiguration;
|
|
53
53
|
/** if true, do not attempt to initialize AuthorizationClient on startup */
|
|
54
54
|
noInitializeAuthClient?: boolean;
|
|
55
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileHost.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileHost.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAmB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAA+C,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAClG,OAAO,EACuE,
|
|
1
|
+
{"version":3,"file":"MobileHost.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileHost.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAmB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAA+C,cAAc,EAAE,MAAM,qBAAqB,CAAC;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AoB,CAAC,UAAU,CAAC,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,UAAU,CAAC,CAAC;SACpE;QACD,yBAAU,CAAC,mBAAmB,GAAG,oBAAoB,CAAC;IACxD,CAAC;;AApFH,gCAqFC;AAlFwB,0BAAe,GAAG,IAAI,sBAAO,EAAE,CAAC;AAChC,+BAAoB,GAAG,IAAI,sBAAO,EAAE,CAAC;AACrC,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AAClC,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AAClC,0BAAe,GAAG,IAAI,sBAAO,EAAE,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 { BeEvent, BriefcaseStatus } from \"@itwin/core-bentley\";\r\nimport { IModelHost, IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\r\nimport {\r\n IModelReadRpcInterface, IModelTileRpcInterface, InternetConnectivityStatus, NativeAppAuthorizationConfiguration, RpcInterfaceDefinition,\r\n SnapshotIModelRpcInterface,\r\n} from \"@itwin/core-common\";\r\nimport { CancelRequest, DownloadFailed, ProgressCallback, UserCancelledError } from \"@bentley/itwin-client\";\r\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\r\nimport { BatteryState, DeviceEvents, mobileAppChannel, MobileAppFunctions, Orientation } from \"../common/MobileAppProps\";\r\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\r\nimport { MobileAuthorizationBackend } from \"./MobileAuthorizationBackend\";\r\nimport { setupMobileRpc } from \"./MobileRpcServer\";\r\n\r\n/** @beta */\r\nexport type MobileCompletionCallback = (downloadUrl: string, downloadFileUrl: string, cancelled: boolean, err?: string) => void;\r\n/** @beta */\r\nexport type MobileProgressCallback = (bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => void;\r\n/** @beta */\r\nexport type MobileCancelCallback = () => boolean;\r\n\r\n/** @beta */\r\nexport interface DownloadTask {\r\n url: string;\r\n downloadPath: string;\r\n isDetached: boolean;\r\n isRunning: boolean;\r\n totalBytes?: number;\r\n doneBytes?: number;\r\n cancelId?: number;\r\n isBackground?: boolean;\r\n cancel?: MobileCancelCallback;\r\n toBackground: () => boolean;\r\n toForeground: () => boolean;\r\n}\r\n\r\n/** @beta */\r\nexport abstract class MobileDevice {\r\n public emit(eventName: DeviceEvents, ...args: any[]) {\r\n switch (eventName) {\r\n case \"memoryWarning\":\r\n MobileHost.onMemoryWarning.raiseEvent(...args); break;\r\n case \"orientationChanged\":\r\n MobileHost.onOrientationChanged.raiseEvent(...args); break;\r\n case \"enterForeground\":\r\n MobileHost.onEnterForeground.raiseEvent(...args); break;\r\n case \"enterBackground\":\r\n MobileHost.onEnterBackground.raiseEvent(...args); break;\r\n case \"willTerminate\":\r\n MobileHost.onWillTerminate.raiseEvent(...args); break;\r\n }\r\n }\r\n\r\n public abstract getOrientation(): Orientation;\r\n public abstract getBatteryState(): BatteryState;\r\n public abstract getBatteryLevel(): number;\r\n public abstract createDownloadTask(downloadUrl: string, isBackground: boolean, downloadTo: string, completion: MobileCompletionCallback, progress?: MobileProgressCallback): number;\r\n public abstract cancelDownloadTask(cancelId: number): boolean;\r\n public abstract getDownloadTasks(): DownloadTask[];\r\n public abstract resumeDownloadInForeground(requestId: number): boolean;\r\n public abstract resumeDownloadInBackground(requestId: number): boolean;\r\n public abstract reconnect(connection: number): void;\r\n public abstract authSignIn(callback: (err?: string) => void): void;\r\n public abstract authSignOut(callback: (err?: string) => void): void;\r\n public abstract authGetAccessToken(callback: (accessToken?: string, err?: string) => void): void;\r\n public authInit(_config: NativeAppAuthorizationConfiguration, callback: (err?: string) => void): void { callback(); }\r\n public abstract authStateChanged(accessToken?: string, err?: string): void;\r\n}\r\n\r\nclass MobileAppHandler extends IpcHandler implements MobileAppFunctions {\r\n public get channelName() { return mobileAppChannel; }\r\n public async reconnect(connection: number) {\r\n MobileHost.reconnect(connection);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport interface MobileHostOpts extends NativeHostOpts {\r\n mobileHost?: {\r\n device?: MobileDevice;\r\n /** list of RPC interface definitions to register */\r\n rpcInterfaces?: RpcInterfaceDefinition[];\r\n /** if present, [[NativeHost.authorizationClient]] will be set to an instance of NativeAppAuthorizationBackend and will be initialized. */\r\n authConfig?: NativeAppAuthorizationConfiguration;\r\n /** if true, do not attempt to initialize AuthorizationClient on startup */\r\n noInitializeAuthClient?: boolean;\r\n };\r\n}\r\n\r\n/**\r\n * @beta\r\n */\r\nexport class MobileHost {\r\n private static _device?: MobileDevice;\r\n public static get device() { return this._device!; }\r\n public static readonly onMemoryWarning = new BeEvent();\r\n public static readonly onOrientationChanged = new BeEvent();\r\n public static readonly onEnterForeground = new BeEvent();\r\n public static readonly onEnterBackground = new BeEvent();\r\n public static readonly onWillTerminate = new BeEvent();\r\n\r\n /** @internal */\r\n public static get authorization() { return IModelHost.authorizationClient as MobileAuthorizationBackend; }\r\n\r\n /** @internal */\r\n public static reconnect(connection: number) {\r\n this.device.reconnect(connection);\r\n }\r\n\r\n /** @internal */\r\n public static async downloadFile(downloadUrl: string, downloadTo: string, progress?: ProgressCallback, cancelRequest?: CancelRequest): Promise<void> {\r\n return new Promise<void>((resolve, reject) => {\r\n\r\n let progressCb: MobileProgressCallback | undefined;\r\n let lastReportedOn = Date.now();\r\n const minTimeBeforeReportingProgress = 1000;\r\n if (progress) {\r\n progressCb = (_bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => {\r\n const currentTime = Date.now();\r\n const timeSinceLastEvent = currentTime - lastReportedOn;\r\n // report all event for last 5 Mbs so we never miss 100% progress event\r\n const lastEvent = (totalBytesExpectedToWrite - totalBytesWritten) < 1024 * 1024 * 5;\r\n if (timeSinceLastEvent < minTimeBeforeReportingProgress && !lastEvent)\r\n return;\r\n\r\n lastReportedOn = currentTime;\r\n const percent = Number((100 * (totalBytesWritten / totalBytesExpectedToWrite)).toFixed(2));\r\n progress({ total: totalBytesExpectedToWrite, loaded: totalBytesWritten, percent });\r\n };\r\n }\r\n const requestId = this.device.createDownloadTask(downloadUrl, false, downloadTo, (_downloadUrl: string, _downloadFileUrl: string, cancelled: boolean, err?: string) => {\r\n if (cancelled)\r\n reject(new UserCancelledError(BriefcaseStatus.DownloadCancelled, \"User cancelled download\"));\r\n else if (err)\r\n reject(new DownloadFailed(400, \"Download failed\"));\r\n else\r\n resolve();\r\n }, progressCb);\r\n if (cancelRequest) {\r\n // eslint-disable-next-line @typescript-eslint/unbound-method\r\n cancelRequest.cancel = () => { return this.device.cancelDownloadTask(requestId); };\r\n }\r\n });\r\n }\r\n\r\n public static get isValid() { return undefined !== this._device; }\r\n\r\n /** Start the backend of a mobile app. */\r\n public static async startup(opt?: MobileHostOpts): Promise<void> {\r\n if (!this.isValid) {\r\n this._device = opt?.mobileHost?.device ?? new (MobileDevice as any)();\r\n // set global device interface.\r\n (global as any).__iTwinJsNativeBridge = this._device;\r\n // following will provide impl for device specific api.\r\n setupMobileRpc();\r\n }\r\n\r\n await NativeHost.startup(opt);\r\n if (IpcHost.isValid)\r\n MobileAppHandler.register();\r\n\r\n const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? [\r\n IModelReadRpcInterface,\r\n IModelTileRpcInterface,\r\n SnapshotIModelRpcInterface,\r\n PresentationRpcInterface,\r\n ];\r\n\r\n MobileRpcManager.initializeImpl(rpcInterfaces);\r\n\r\n const authorizationBackend = new MobileAuthorizationBackend(opt?.mobileHost?.authConfig);\r\n const connectivityStatus = NativeHost.checkInternetConnectivity();\r\n if (opt?.mobileHost?.authConfig && true !== opt?.mobileHost?.noInitializeAuthClient && connectivityStatus === InternetConnectivityStatus.Online) {\r\n await authorizationBackend.initialize(opt?.mobileHost?.authConfig);\r\n }\r\n IModelHost.authorizationClient = authorizationBackend;\r\n }\r\n}\r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,aAAa,GAAG,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,aAAa,mCAAI;YACtD,oCAAsB;YACtB,oCAAsB;YACtB,wCAA0B;YAC1B,8CAAwB;SACzB,CAAC;QAEF,mCAAgB,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAE/C,MAAM,oBAAoB,GAAG,IAAI,uDAA0B,CAAC,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,UAAU,CAAC,CAAC;QACzF,MAAM,kBAAkB,GAAG,yBAAU,CAAC,yBAAyB,EAAE,CAAC;QAClE,IAAI,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,UAAU,KAAI,IAAI,MAAK,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,sBAAsB,CAAA,IAAI,kBAAkB,KAAK,wCAA0B,CAAC,MAAM,EAAE;YAC/I,MAAM,oBAAoB,CAAC,UAAU,CAAC,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,UAAU,CAAC,CAAC;SACpE;QACD,yBAAU,CAAC,mBAAmB,GAAG,oBAAoB,CAAC;IACxD,CAAC;;AApFH,gCAqFC;AAlFwB,0BAAe,GAAG,IAAI,sBAAO,EAAE,CAAC;AAChC,+BAAoB,GAAG,IAAI,sBAAO,EAAE,CAAC;AACrC,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AAClC,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AAClC,0BAAe,GAAG,IAAI,sBAAO,EAAE,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 { BeEvent, BriefcaseStatus } from \"@itwin/core-bentley\";\r\nimport { IModelHost, IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\r\nimport {\r\n IModelReadRpcInterface, IModelTileRpcInterface, InternetConnectivityStatus, RpcInterfaceDefinition,\r\n SnapshotIModelRpcInterface,\r\n} from \"@itwin/core-common\";\r\nimport { CancelRequest, DownloadFailed, ProgressCallback, UserCancelledError } from \"@bentley/itwin-client\";\r\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\r\nimport { BatteryState, DeviceEvents, mobileAppChannel, MobileAppFunctions, Orientation } from \"../common/MobileAppProps\";\r\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\r\nimport { MobileAppAuthorizationConfiguration, MobileAuthorizationBackend } from \"./MobileAuthorizationBackend\";\r\nimport { setupMobileRpc } from \"./MobileRpcServer\";\r\n\r\n/** @beta */\r\nexport type MobileCompletionCallback = (downloadUrl: string, downloadFileUrl: string, cancelled: boolean, err?: string) => void;\r\n/** @beta */\r\nexport type MobileProgressCallback = (bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => void;\r\n/** @beta */\r\nexport type MobileCancelCallback = () => boolean;\r\n\r\n/** @beta */\r\nexport interface DownloadTask {\r\n url: string;\r\n downloadPath: string;\r\n isDetached: boolean;\r\n isRunning: boolean;\r\n totalBytes?: number;\r\n doneBytes?: number;\r\n cancelId?: number;\r\n isBackground?: boolean;\r\n cancel?: MobileCancelCallback;\r\n toBackground: () => boolean;\r\n toForeground: () => boolean;\r\n}\r\n\r\n/** @beta */\r\nexport abstract class MobileDevice {\r\n public emit(eventName: DeviceEvents, ...args: any[]) {\r\n switch (eventName) {\r\n case \"memoryWarning\":\r\n MobileHost.onMemoryWarning.raiseEvent(...args); break;\r\n case \"orientationChanged\":\r\n MobileHost.onOrientationChanged.raiseEvent(...args); break;\r\n case \"enterForeground\":\r\n MobileHost.onEnterForeground.raiseEvent(...args); break;\r\n case \"enterBackground\":\r\n MobileHost.onEnterBackground.raiseEvent(...args); break;\r\n case \"willTerminate\":\r\n MobileHost.onWillTerminate.raiseEvent(...args); break;\r\n }\r\n }\r\n\r\n public abstract getOrientation(): Orientation;\r\n public abstract getBatteryState(): BatteryState;\r\n public abstract getBatteryLevel(): number;\r\n public abstract createDownloadTask(downloadUrl: string, isBackground: boolean, downloadTo: string, completion: MobileCompletionCallback, progress?: MobileProgressCallback): number;\r\n public abstract cancelDownloadTask(cancelId: number): boolean;\r\n public abstract getDownloadTasks(): DownloadTask[];\r\n public abstract resumeDownloadInForeground(requestId: number): boolean;\r\n public abstract resumeDownloadInBackground(requestId: number): boolean;\r\n public abstract reconnect(connection: number): void;\r\n public abstract authSignIn(callback: (err?: string) => void): void;\r\n public abstract authSignOut(callback: (err?: string) => void): void;\r\n public abstract authGetAccessToken(callback: (accessToken?: string, err?: string) => void): void;\r\n public authInit(_config: MobileAppAuthorizationConfiguration, callback: (err?: string) => void): void { callback(); }\r\n public abstract authStateChanged(accessToken?: string, err?: string): void;\r\n}\r\n\r\nclass MobileAppHandler extends IpcHandler implements MobileAppFunctions {\r\n public get channelName() { return mobileAppChannel; }\r\n public async reconnect(connection: number) {\r\n MobileHost.reconnect(connection);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport interface MobileHostOpts extends NativeHostOpts {\r\n mobileHost?: {\r\n device?: MobileDevice;\r\n /** list of RPC interface definitions to register */\r\n rpcInterfaces?: RpcInterfaceDefinition[];\r\n /** if present, [[NativeHost.authorizationClient]] will be set to an instance of MobileAppAuthorizationConfiguration and will be initialized. */\r\n authConfig?: MobileAppAuthorizationConfiguration;\r\n /** if true, do not attempt to initialize AuthorizationClient on startup */\r\n noInitializeAuthClient?: boolean;\r\n };\r\n}\r\n\r\n/**\r\n * @beta\r\n */\r\nexport class MobileHost {\r\n private static _device?: MobileDevice;\r\n public static get device() { return this._device!; }\r\n public static readonly onMemoryWarning = new BeEvent();\r\n public static readonly onOrientationChanged = new BeEvent();\r\n public static readonly onEnterForeground = new BeEvent();\r\n public static readonly onEnterBackground = new BeEvent();\r\n public static readonly onWillTerminate = new BeEvent();\r\n\r\n /** @internal */\r\n public static get authorization() { return IModelHost.authorizationClient as MobileAuthorizationBackend; }\r\n\r\n /** @internal */\r\n public static reconnect(connection: number) {\r\n this.device.reconnect(connection);\r\n }\r\n\r\n /** @internal */\r\n public static async downloadFile(downloadUrl: string, downloadTo: string, progress?: ProgressCallback, cancelRequest?: CancelRequest): Promise<void> {\r\n return new Promise<void>((resolve, reject) => {\r\n\r\n let progressCb: MobileProgressCallback | undefined;\r\n let lastReportedOn = Date.now();\r\n const minTimeBeforeReportingProgress = 1000;\r\n if (progress) {\r\n progressCb = (_bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => {\r\n const currentTime = Date.now();\r\n const timeSinceLastEvent = currentTime - lastReportedOn;\r\n // report all event for last 5 Mbs so we never miss 100% progress event\r\n const lastEvent = (totalBytesExpectedToWrite - totalBytesWritten) < 1024 * 1024 * 5;\r\n if (timeSinceLastEvent < minTimeBeforeReportingProgress && !lastEvent)\r\n return;\r\n\r\n lastReportedOn = currentTime;\r\n const percent = Number((100 * (totalBytesWritten / totalBytesExpectedToWrite)).toFixed(2));\r\n progress({ total: totalBytesExpectedToWrite, loaded: totalBytesWritten, percent });\r\n };\r\n }\r\n const requestId = this.device.createDownloadTask(downloadUrl, false, downloadTo, (_downloadUrl: string, _downloadFileUrl: string, cancelled: boolean, err?: string) => {\r\n if (cancelled)\r\n reject(new UserCancelledError(BriefcaseStatus.DownloadCancelled, \"User cancelled download\"));\r\n else if (err)\r\n reject(new DownloadFailed(400, \"Download failed\"));\r\n else\r\n resolve();\r\n }, progressCb);\r\n if (cancelRequest) {\r\n // eslint-disable-next-line @typescript-eslint/unbound-method\r\n cancelRequest.cancel = () => { return this.device.cancelDownloadTask(requestId); };\r\n }\r\n });\r\n }\r\n\r\n public static get isValid() { return undefined !== this._device; }\r\n\r\n /** Start the backend of a mobile app. */\r\n public static async startup(opt?: MobileHostOpts): Promise<void> {\r\n if (!this.isValid) {\r\n this._device = opt?.mobileHost?.device ?? new (MobileDevice as any)();\r\n // set global device interface.\r\n (global as any).__iTwinJsNativeBridge = this._device;\r\n // following will provide impl for device specific api.\r\n setupMobileRpc();\r\n }\r\n\r\n await NativeHost.startup(opt);\r\n if (IpcHost.isValid)\r\n MobileAppHandler.register();\r\n\r\n const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? [\r\n IModelReadRpcInterface,\r\n IModelTileRpcInterface,\r\n SnapshotIModelRpcInterface,\r\n PresentationRpcInterface,\r\n ];\r\n\r\n MobileRpcManager.initializeImpl(rpcInterfaces);\r\n\r\n const authorizationBackend = new MobileAuthorizationBackend(opt?.mobileHost?.authConfig);\r\n const connectivityStatus = NativeHost.checkInternetConnectivity();\r\n if (opt?.mobileHost?.authConfig && true !== opt?.mobileHost?.noInitializeAuthClient && connectivityStatus === InternetConnectivityStatus.Online) {\r\n await authorizationBackend.initialize(opt?.mobileHost?.authConfig);\r\n }\r\n IModelHost.authorizationClient = authorizationBackend;\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-mobile",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.128",
|
|
4
4
|
"description": "iTwin.js MobileHost and MobileApp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -21,24 +21,24 @@
|
|
|
21
21
|
"url": "http://www.bentley.com"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@itwin
|
|
25
|
-
"@itwin/core-backend": "^3.0.0-dev.
|
|
26
|
-
"@itwin/core-
|
|
27
|
-
"@itwin/core-
|
|
28
|
-
"@
|
|
29
|
-
"@itwin/presentation-common": "^3.0.0-dev.
|
|
24
|
+
"@bentley/itwin-client": "^3.0.0-dev.128",
|
|
25
|
+
"@itwin/core-backend": "^3.0.0-dev.128",
|
|
26
|
+
"@itwin/core-bentley": "^3.0.0-dev.128",
|
|
27
|
+
"@itwin/core-common": "^3.0.0-dev.128",
|
|
28
|
+
"@itwin/core-frontend": "^3.0.0-dev.128",
|
|
29
|
+
"@itwin/presentation-common": "^3.0.0-dev.128",
|
|
30
30
|
"js-base64": "^3.6.1",
|
|
31
31
|
"ws": "^7.5.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@itwin
|
|
35
|
-
"@itwin/build-tools": "3.0.0-dev.
|
|
36
|
-
"@itwin/
|
|
37
|
-
"@
|
|
38
|
-
"@itwin/core-
|
|
39
|
-
"@itwin/core-
|
|
40
|
-
"@itwin/
|
|
41
|
-
"@itwin/presentation-common": "3.0.0-dev.
|
|
34
|
+
"@bentley/itwin-client": "3.0.0-dev.128",
|
|
35
|
+
"@itwin/build-tools": "3.0.0-dev.128",
|
|
36
|
+
"@itwin/core-backend": "3.0.0-dev.128",
|
|
37
|
+
"@itwin/core-bentley": "3.0.0-dev.128",
|
|
38
|
+
"@itwin/core-common": "3.0.0-dev.128",
|
|
39
|
+
"@itwin/core-frontend": "3.0.0-dev.128",
|
|
40
|
+
"@itwin/eslint-plugin": "3.0.0-dev.128",
|
|
41
|
+
"@itwin/presentation-common": "3.0.0-dev.128",
|
|
42
42
|
"@types/chai": "^4.1.4",
|
|
43
43
|
"@types/fs-extra": "^4.0.7",
|
|
44
44
|
"@types/mocha": "^8.2.2",
|