@itwin/core-mobile 3.2.0-dev.9 → 3.3.0-dev.0

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,33 @@
1
1
  # Change Log - @itwin/core-mobile
2
2
 
3
- This log was last generated on Thu, 10 Mar 2022 21:18:13 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 15 Apr 2022 13:49:25 GMT and should not be manually modified.
4
+
5
+ ## 3.1.3
6
+ Fri, 15 Apr 2022 13:49:25 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 3.1.2
11
+ Wed, 06 Apr 2022 22:27:56 GMT
12
+
13
+ ### Updates
14
+
15
+ - Restore authorization support in MobileHost.
16
+
17
+ ## 3.1.1
18
+ Thu, 31 Mar 2022 15:55:48 GMT
19
+
20
+ _Version update only_
21
+
22
+ ## 3.1.0
23
+ Tue, 29 Mar 2022 20:53:47 GMT
24
+
25
+ _Version update only_
26
+
27
+ ## 3.0.3
28
+ Fri, 25 Mar 2022 15:10:02 GMT
29
+
30
+ _Version update only_
4
31
 
5
32
  ## 3.0.2
6
33
  Thu, 10 Mar 2022 21:18:13 GMT
@@ -3,63 +3,16 @@
3
3
  */
4
4
  import { AccessToken } from "@itwin/core-bentley";
5
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
- }
32
- /** Utility to provide OIDC/OAuth tokens from native ios app to frontend
33
- * @beta
6
+ /** Utility to provide and cache auth tokens from native mobile apps to IModelHost.
7
+ * @internal
34
8
  */
35
9
  export declare class MobileAuthorizationBackend implements AuthorizationClient {
36
- protected _accessToken?: AccessToken;
37
- config?: MobileAppAuthorizationConfiguration;
38
- expireSafety: number;
39
- issuerUrl?: string;
40
- static defaultRedirectUri: string;
41
- get redirectUri(): string;
42
- protected _baseUrl: string;
43
- protected _url?: string;
44
- constructor(config?: MobileAppAuthorizationConfiguration);
45
- /** Used to initialize the client - must be awaited before any other methods are called */
46
- initialize(config?: MobileAppAuthorizationConfiguration): Promise<void>;
47
- /** Start the sign-in process */
48
- signIn(): Promise<void>;
49
- /** Start the sign-out process */
50
- signOut(): Promise<void>;
51
- setAccessToken(token?: AccessToken): void;
10
+ private _accessToken;
11
+ private _expirationDate;
12
+ private _expiryBuffer;
13
+ private _fetchingToken;
14
+ private get _hasExpired();
52
15
  getAccessToken(): Promise<AccessToken>;
53
- /** return accessToken */
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;
16
+ setAccessToken(accessToken?: string, expirationDate?: string): void;
64
17
  }
65
18
  //# sourceMappingURL=MobileAuthorizationBackend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MobileAuthorizationBackend.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileAuthorizationBackend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,MAAM;CAiBf"}
1
+ {"version":3,"file":"MobileAuthorizationBackend.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileAuthorizationBackend.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD;;GAEG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IACpE,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,aAAa,CAAW;IAChC,OAAO,CAAC,cAAc,CAAS;IAE/B,OAAO,KAAK,WAAW,GAEtB;IAEY,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IA2B5C,cAAc,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM;CAIpE"}
@@ -8,118 +8,47 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.MobileAuthorizationBackend = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const core_common_1 = require("@itwin/core-common");
13
11
  const MobileHost_1 = require("./MobileHost");
14
- /** Utility to provide OIDC/OAuth tokens from native ios app to frontend
15
- * @beta
12
+ /** Utility to provide and cache auth tokens from native mobile apps to IModelHost.
13
+ * @internal
16
14
  */
17
15
  class MobileAuthorizationBackend {
18
- constructor(config) {
19
- this.expireSafety = 60 * 10; // refresh token 10 minutes before real expiration time
20
- this._baseUrl = "https://ims.bentley.com";
21
- this.config = config;
16
+ constructor() {
17
+ this._accessToken = "";
18
+ this._expiryBuffer = 60 * 10; // ten minutes
19
+ this._fetchingToken = false;
22
20
  }
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
- /** Used to initialize the client - must be awaited before any other methods are called */
25
- async initialize(config) {
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");
35
- MobileHost_1.MobileHost.device.authStateChanged = (tokenString) => {
36
- this.setAccessToken(tokenString);
37
- };
38
- return new Promise((resolve, reject) => {
39
- (0, core_bentley_1.assert)(this.config !== undefined);
40
- MobileHost_1.MobileHost.device.authInit({ ...this.config, issuerUrl: this.issuerUrl }, (err) => {
41
- if (!err) {
42
- resolve();
43
- }
44
- else {
45
- reject(new Error(err));
46
- }
47
- });
48
- });
49
- }
50
- /** Start the sign-in process */
51
- async signIn() {
52
- return new Promise((resolve, reject) => {
53
- MobileHost_1.MobileHost.device.authSignIn((err) => {
54
- if (!err) {
55
- resolve();
56
- }
57
- else {
58
- reject(new Error(err));
59
- }
60
- });
61
- });
62
- }
63
- /** Start the sign-out process */
64
- async signOut() {
65
- return new Promise((resolve, reject) => {
66
- MobileHost_1.MobileHost.device.authSignOut((err) => {
67
- if (!err) {
68
- resolve();
69
- }
70
- else {
71
- reject(new Error(err));
72
- }
73
- });
74
- });
75
- }
76
- setAccessToken(token) {
77
- if (token === this._accessToken)
78
- return;
79
- this._accessToken = token;
21
+ get _hasExpired() {
22
+ return this._expirationDate !== undefined && this._expirationDate.getTime() - Date.now() <= this._expiryBuffer * 1000;
80
23
  }
81
24
  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
- }
87
- /** return accessToken */
88
- async refreshToken() {
25
+ if (this._fetchingToken) {
26
+ return Promise.reject(); // short-circuits any recursive use of this function
27
+ }
89
28
  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
- }
97
- });
29
+ if (this._accessToken && !this._hasExpired) {
30
+ resolve(this._accessToken);
31
+ }
32
+ else {
33
+ this._fetchingToken = true;
34
+ MobileHost_1.MobileHost.device.authGetAccessToken((tokenString, expirationDate, error) => {
35
+ if (error) {
36
+ this._accessToken = "";
37
+ reject(error);
38
+ }
39
+ this._accessToken = tokenString !== null && tokenString !== void 0 ? tokenString : "";
40
+ if (expirationDate !== undefined)
41
+ this._expirationDate = new Date(expirationDate);
42
+ resolve(this._accessToken);
43
+ });
44
+ this._fetchingToken = false;
45
+ }
98
46
  });
99
47
  }
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;
48
+ setAccessToken(accessToken, expirationDate) {
49
+ this._accessToken = accessToken !== null && accessToken !== void 0 ? accessToken : "";
50
+ this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;
121
51
  }
122
52
  }
123
53
  exports.MobileAuthorizationBackend = MobileAuthorizationBackend;
124
- MobileAuthorizationBackend.defaultRedirectUri = "imodeljs://app/signin-callback";
125
54
  //# sourceMappingURL=MobileAuthorizationBackend.js.map
@@ -1 +1 @@
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;AAiC1C;;GAEG;AACH,MAAa,0BAA0B;IAUrC,YAAmB,MAA4C;QAPxD,iBAAY,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,uDAAuD;QAI5E,aAAQ,GAAG,yBAAyB,CAAC;QAI7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAND,IAAW,WAAW,iBAAK,OAAO,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,WAAW,mCAAI,0BAA0B,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAQ9G,0FAA0F;IACnF,KAAK,CAAC,UAAU,CAAC,MAA4C;;QAClE,IAAI,CAAC,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,IAAI,CAAC,MAAM,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,MAAM;YACd,MAAM,IAAI,yBAAW,CAAC,yBAAU,CAAC,KAAK,EAAE,oEAAoE,CAAC,CAAC;QAChH,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY;YAC1B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,MAAA,IAAI,CAAC,MAAM,CAAC,SAAS,mCAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QACxD,IAAI,CAAC,IAAI,CAAC,SAAS;YACjB,MAAM,IAAI,yBAAW,CAAC,yBAAU,CAAC,KAAK,EAAE,2DAA2D,CAAC,CAAC;QAEvG,uBAAU,CAAC,MAAM,CAAC,gBAA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AAA,MAAA,IAAI,CAAC,MAAM,0CAAE,SAAS,CAAA;YACnC,SAAS,CAAC,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC;QACnD,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;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"]}
1
+ {"version":3,"file":"MobileAuthorizationBackend.js","sourceRoot":"","sources":["../../../src/backend/MobileAuthorizationBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH,6CAA0C;AAE1C;;GAEG;AACH,MAAa,0BAA0B;IAAvC;QACU,iBAAY,GAAgB,EAAE,CAAC;QAE/B,kBAAa,GAAG,EAAE,GAAG,EAAE,CAA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aAAX,WAAW,cAAX,WAAW,GAAI,EAAE,CAAC;QACtC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;CACF;AAzCD,gEAyCC","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 } from \"@itwin/core-bentley\";\r\nimport { AuthorizationClient } from \"@itwin/core-common\";\r\nimport { MobileHost } from \"./MobileHost\";\r\n\r\n/** Utility to provide and cache auth tokens from native mobile apps to IModelHost.\r\n * @internal\r\n */\r\nexport class MobileAuthorizationBackend implements AuthorizationClient {\r\n private _accessToken: AccessToken = \"\";\r\n private _expirationDate: Date | undefined;\r\n private _expiryBuffer = 60 * 10; // ten minutes\r\n private _fetchingToken = false;\r\n\r\n private get _hasExpired(): boolean {\r\n return this._expirationDate !== undefined && this._expirationDate.getTime() - Date.now() <= this._expiryBuffer * 1000;\r\n }\r\n\r\n public async getAccessToken(): Promise<AccessToken> {\r\n if (this._fetchingToken) {\r\n return Promise.reject(); // short-circuits any recursive use of this function\r\n }\r\n\r\n return new Promise<AccessToken>((resolve, reject) => {\r\n if (this._accessToken && !this._hasExpired) {\r\n resolve(this._accessToken);\r\n } else {\r\n this._fetchingToken = true;\r\n MobileHost.device.authGetAccessToken((tokenString?: AccessToken, expirationDate?: string, error?: string) => {\r\n if (error) {\r\n this._accessToken = \"\";\r\n reject(error);\r\n }\r\n\r\n this._accessToken = tokenString ?? \"\";\r\n if (expirationDate !== undefined)\r\n this._expirationDate = new Date(expirationDate);\r\n\r\n resolve(this._accessToken);\r\n });\r\n this._fetchingToken = false;\r\n }\r\n });\r\n }\r\n\r\n public setAccessToken(accessToken?: string, expirationDate?: string) {\r\n this._accessToken = accessToken ?? \"\";\r\n this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;\r\n }\r\n}\r\n"]}
@@ -3,8 +3,7 @@ import { NativeHostOpts } from "@itwin/core-backend";
3
3
  import { RpcInterfaceDefinition } from "@itwin/core-common";
4
4
  import { CancelRequest } from "./MobileFileHandler";
5
5
  import { ProgressCallback } from "./Request";
6
- import { BatteryState, DeviceEvents, Orientation } from "../common/MobileAppProps";
7
- import { MobileAppAuthorizationConfiguration } from "./MobileAuthorizationBackend";
6
+ import { BatteryState, DeviceEvents, MobileNotifications, Orientation } from "../common/MobileAppProps";
8
7
  /** @beta */
9
8
  export declare type MobileCompletionCallback = (downloadUrl: string, downloadFileUrl: string, cancelled: boolean, err?: string) => void;
10
9
  /** @beta */
@@ -37,11 +36,7 @@ export declare abstract class MobileDevice {
37
36
  abstract resumeDownloadInForeground(requestId: number): boolean;
38
37
  abstract resumeDownloadInBackground(requestId: number): boolean;
39
38
  abstract reconnect(connection: number): void;
40
- abstract authSignIn(callback: (err?: string) => void): void;
41
- abstract authSignOut(callback: (err?: string) => void): void;
42
- abstract authGetAccessToken(callback: (accessToken?: string, err?: string) => void): void;
43
- authInit(_config: MobileAppAuthorizationConfiguration, callback: (err?: string) => void): void;
44
- abstract authStateChanged(accessToken?: string, err?: string): void;
39
+ abstract authGetAccessToken(callback: (accessToken?: string, expirationDate?: string, err?: string) => void): void;
45
40
  }
46
41
  /** @beta */
47
42
  export interface MobileHostOpts extends NativeHostOpts {
@@ -49,8 +44,6 @@ export interface MobileHostOpts extends NativeHostOpts {
49
44
  device?: MobileDevice;
50
45
  /** list of RPC interface definitions to register */
51
46
  rpcInterfaces?: RpcInterfaceDefinition[];
52
- /** if present, [[IModelHost.authorizationClient]] will be set to an instance of [[MobileAuthorizationBackend]]. */
53
- authConfig?: MobileAppAuthorizationConfiguration;
54
47
  };
55
48
  }
56
49
  /**
@@ -64,9 +57,14 @@ export declare class MobileHost {
64
57
  static readonly onEnterForeground: BeEvent<import("@itwin/core-bentley").Listener>;
65
58
  static readonly onEnterBackground: BeEvent<import("@itwin/core-bentley").Listener>;
66
59
  static readonly onWillTerminate: BeEvent<import("@itwin/core-bentley").Listener>;
60
+ static readonly onAuthAccessTokenChanged: BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>;
61
+ /** Send a notification to the MobileApp connected to this MobileHost. */
62
+ static notifyMobileFrontend<T extends keyof MobileNotifications>(methodName: T, ...args: Parameters<MobileNotifications[T]>): void;
67
63
  /** @internal */
68
64
  static reconnect(connection: number): void;
69
65
  /** @internal */
66
+ static authGetAccessToken(): Promise<[string, string]>;
67
+ /** @internal */
70
68
  static downloadFile(downloadUrl: string, downloadTo: string, progress?: ProgressCallback, cancelRequest?: CancelRequest): Promise<void>;
71
69
  static get isValid(): boolean;
72
70
  /** Start the backend of a mobile app. */
@@ -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,EAAmC,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAC2C,sBAAsB,EAEvE,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAsC,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAuB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAExG,OAAO,EAAE,mCAAmC,EAAE,MAAM,8BAA8B,CAAC;AAGnF,YAAY;AACZ,oBAAY,wBAAwB,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAChI,YAAY;AACZ,oBAAY,sBAAsB,GAAG,CAA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MAAM,GAAG,SAAS,KAAK,IAAI,EAAI;IAE/I,yEAAyE;WAC3D,oBAAoB,CAAC,CAAC,SAAS,MAAM,mBAAmB,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAIlI,iBAAiB;WACH,SAAS,CAAC,UAAU,EAAE,MAAM;IAI1C,iBAAiB;WACG,kBAAkB;IAWtC,iBAAiB;WACG,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,gBAAgB,EAAE,aAAa,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCpJ,WAAkB,OAAO,YAAyC;IAElE,yCAAyC;WACrB,OAAO,CAAC,GAAG,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CA6CjE"}
@@ -12,6 +12,7 @@ const MobileFileHandler_1 = require("./MobileFileHandler");
12
12
  const presentation_common_1 = require("@itwin/presentation-common");
13
13
  const MobileAppChannel_1 = require("../common/MobileAppChannel");
14
14
  const MobileRpcManager_1 = require("../common/MobileRpcManager");
15
+ const MobileAuthorizationBackend_1 = require("./MobileAuthorizationBackend");
15
16
  const MobileRpcServer_1 = require("./MobileRpcServer");
16
17
  /** @beta */
17
18
  class MobileDevice {
@@ -32,9 +33,11 @@ class MobileDevice {
32
33
  case "willTerminate":
33
34
  MobileHost.onWillTerminate.raiseEvent(...args);
34
35
  break;
36
+ case "authAccessTokenChanged":
37
+ MobileHost.onAuthAccessTokenChanged.raiseEvent(args[0], args[1]);
38
+ break;
35
39
  }
36
40
  }
37
- authInit(_config, callback) { callback(); }
38
41
  }
39
42
  exports.MobileDevice = MobileDevice;
40
43
  class MobileAppHandler extends core_backend_1.IpcHandler {
@@ -42,17 +45,35 @@ class MobileAppHandler extends core_backend_1.IpcHandler {
42
45
  async reconnect(connection) {
43
46
  MobileHost.reconnect(connection);
44
47
  }
48
+ async getAccessToken() {
49
+ return MobileHost.authGetAccessToken();
50
+ }
45
51
  }
46
52
  /**
47
53
  * @beta
48
54
  */
49
55
  class MobileHost {
50
56
  static get device() { return this._device; }
57
+ /** Send a notification to the MobileApp connected to this MobileHost. */
58
+ static notifyMobileFrontend(methodName, ...args) {
59
+ return core_backend_1.IpcHost.send(MobileAppChannel_1.mobileAppNotify, methodName, ...args);
60
+ }
51
61
  /** @internal */
52
62
  static reconnect(connection) {
53
63
  this.device.reconnect(connection);
54
64
  }
55
65
  /** @internal */
66
+ static async authGetAccessToken() {
67
+ return new Promise((resolve, reject) => {
68
+ MobileHost.device.authGetAccessToken((tokenString, expirationDate, error) => {
69
+ if (error) {
70
+ reject(error);
71
+ }
72
+ resolve([tokenString !== null && tokenString !== void 0 ? tokenString : "", expirationDate !== null && expirationDate !== void 0 ? expirationDate : ""]);
73
+ });
74
+ });
75
+ }
76
+ /** @internal */
56
77
  static async downloadFile(downloadUrl, downloadTo, progress, cancelRequest) {
57
78
  return new Promise((resolve, reject) => {
58
79
  let progressCb;
@@ -88,18 +109,40 @@ class MobileHost {
88
109
  static get isValid() { return undefined !== this._device; }
89
110
  /** Start the backend of a mobile app. */
90
111
  static async startup(opt) {
91
- var _a, _b, _c, _d;
112
+ var _a, _b, _c, _d, _e;
113
+ const authorizationClient = new MobileAuthorizationBackend_1.MobileAuthorizationBackend();
92
114
  if (!this.isValid) {
93
115
  this._device = (_b = (_a = opt === null || opt === void 0 ? void 0 : opt.mobileHost) === null || _a === void 0 ? void 0 : _a.device) !== null && _b !== void 0 ? _b : new MobileDevice();
94
116
  // set global device interface.
95
117
  global.__iTwinJsNativeBridge = this._device;
118
+ this.onMemoryWarning.addListener(() => {
119
+ MobileHost.notifyMobileFrontend("notifyMemoryWarning");
120
+ });
121
+ this.onOrientationChanged.addListener(() => {
122
+ MobileHost.notifyMobileFrontend("notifyOrientationChanged");
123
+ });
124
+ this.onEnterForeground.addListener(() => {
125
+ MobileHost.notifyMobileFrontend("notifyEnterForeground");
126
+ });
127
+ this.onEnterBackground.addListener(() => {
128
+ MobileHost.notifyMobileFrontend("notifyEnterBackground");
129
+ });
130
+ this.onWillTerminate.addListener(() => {
131
+ MobileHost.notifyMobileFrontend("notifyWillTerminate");
132
+ });
133
+ this.onAuthAccessTokenChanged.addListener((accessToken, expirationDate) => {
134
+ authorizationClient.setAccessToken(accessToken, expirationDate);
135
+ MobileHost.notifyMobileFrontend("notifyAuthAccessTokenChanged", accessToken, expirationDate);
136
+ });
96
137
  // following will provide impl for device specific api.
97
138
  (0, MobileRpcServer_1.setupMobileRpc)();
98
139
  }
99
- await core_backend_1.NativeHost.startup(opt);
140
+ const iModelHostConfiguration = (_c = opt === null || opt === void 0 ? void 0 : opt.iModelHost) !== null && _c !== void 0 ? _c : new core_backend_1.IModelHostConfiguration();
141
+ iModelHostConfiguration.authorizationClient = authorizationClient;
142
+ await core_backend_1.NativeHost.startup({ ...opt, iModelHost: iModelHostConfiguration });
100
143
  if (core_backend_1.IpcHost.isValid)
101
144
  MobileAppHandler.register();
102
- const rpcInterfaces = (_d = (_c = opt === null || opt === void 0 ? void 0 : opt.mobileHost) === null || _c === void 0 ? void 0 : _c.rpcInterfaces) !== null && _d !== void 0 ? _d : [
145
+ const rpcInterfaces = (_e = (_d = opt === null || opt === void 0 ? void 0 : opt.mobileHost) === null || _d === void 0 ? void 0 : _d.rpcInterfaces) !== null && _e !== void 0 ? _e : [
103
146
  core_common_1.IModelReadRpcInterface,
104
147
  core_common_1.IModelTileRpcInterface,
105
148
  core_common_1.SnapshotIModelRpcInterface,
@@ -114,4 +157,5 @@ MobileHost.onOrientationChanged = new core_bentley_1.BeEvent();
114
157
  MobileHost.onEnterForeground = new core_bentley_1.BeEvent();
115
158
  MobileHost.onEnterBackground = new core_bentley_1.BeEvent();
116
159
  MobileHost.onWillTerminate = new core_bentley_1.BeEvent();
160
+ MobileHost.onAuthAccessTokenChanged = new core_bentley_1.BeEvent();
117
161
  //# sourceMappingURL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,oCAAsB;YACtB,oCAAsB;YACtB,wCAA0B;YAC1B,8CAAwB;SACzB,CAAC;QAEF,mCAAgB,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IACjD,CAAC;;AA1EH,gCA2EC;AAxEwB,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 { IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\r\nimport {\r\n IModelReadRpcInterface, IModelTileRpcInterface, RpcInterfaceDefinition,\r\n SnapshotIModelRpcInterface,\r\n} from \"@itwin/core-common\";\r\nimport { CancelRequest, DownloadFailed, UserCancelledError } from \"./MobileFileHandler\";\r\nimport { ProgressCallback } from \"./Request\";\r\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\r\nimport { mobileAppChannel } from \"../common/MobileAppChannel\";\r\nimport { BatteryState, DeviceEvents, MobileAppFunctions, Orientation } from \"../common/MobileAppProps\";\r\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\r\nimport { MobileAppAuthorizationConfiguration } 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, [[IModelHost.authorizationClient]] will be set to an instance of [[MobileAuthorizationBackend]]. */\r\n authConfig?: MobileAppAuthorizationConfiguration;\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 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}\r\n"]}
1
+ {"version":3,"file":"MobileHost.js","sourceRoot":"","sources":["../../../src/backend/MobileHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAA4E;AAC5E,sDAA+G;AAC/G,oDAG4B;AAC5B,2DAAwF;AAExF,oEAAsE;AACtE,iEAA+E;AAE/E,iEAA8D;AAC9D,6EAA0E;AAC1E,uDAAmD;AAwBnD,YAAY;AACZ,MAAsB,YAAY;IACzB,IAAI,CAAC,SAAuB,EAAE,GAAG,IAAW;QACjD,QAAQ,SAAS,EAAE;YACjB,KAAK,eAAe;gBAClB,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC,GAA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jF,uBAAuB,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAClE,MAAM,yBAAU,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,EAAE,UAAU,EAAE,uBAAuB,EAAE,CAAC,CAAC;QAE1E,IAAI,sBAAO,CAAC,OAAO;YACjB,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAE9B,MAAM,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;IACjD,CAAC;;AAnHH,gCAoHC;AAjHwB,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;AAChC,mCAAwB,GAAG,IAAI,sBAAO,EAAiF,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 { AccessToken, BeEvent, BriefcaseStatus } from \"@itwin/core-bentley\";\r\nimport { IModelHostConfiguration, IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\r\nimport {\r\n IModelReadRpcInterface, IModelTileRpcInterface, RpcInterfaceDefinition,\r\n SnapshotIModelRpcInterface,\r\n} from \"@itwin/core-common\";\r\nimport { CancelRequest, DownloadFailed, UserCancelledError } from \"./MobileFileHandler\";\r\nimport { ProgressCallback } from \"./Request\";\r\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\r\nimport { mobileAppChannel, mobileAppNotify } from \"../common/MobileAppChannel\";\r\nimport { BatteryState, DeviceEvents, MobileAppFunctions, MobileNotifications, 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 case \"authAccessTokenChanged\":\r\n MobileHost.onAuthAccessTokenChanged.raiseEvent(args[0], args[1]); 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 authGetAccessToken(callback: (accessToken?: string, expirationDate?: string, err?: string) => void): 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 public async getAccessToken() {\r\n return MobileHost.authGetAccessToken();\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 };\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 public static readonly onAuthAccessTokenChanged = new BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>();\r\n\r\n /** Send a notification to the MobileApp connected to this MobileHost. */\r\n public static notifyMobileFrontend<T extends keyof MobileNotifications>(methodName: T, ...args: Parameters<MobileNotifications[T]>) {\r\n return IpcHost.send(mobileAppNotify, methodName, ...args);\r\n }\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 authGetAccessToken() {\r\n return new Promise<[AccessToken, string]>((resolve, reject) => {\r\n MobileHost.device.authGetAccessToken((tokenString?: AccessToken, expirationDate?: string, error?: string) => {\r\n if (error) {\r\n reject(error);\r\n }\r\n resolve([tokenString ?? \"\", expirationDate ?? \"\"]);\r\n });\r\n });\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 const authorizationClient = new MobileAuthorizationBackend();\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 this.onMemoryWarning.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyMemoryWarning\");\r\n });\r\n this.onOrientationChanged.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyOrientationChanged\");\r\n });\r\n this.onEnterForeground.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyEnterForeground\");\r\n });\r\n this.onEnterBackground.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyEnterBackground\");\r\n });\r\n this.onWillTerminate.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyWillTerminate\");\r\n });\r\n this.onAuthAccessTokenChanged.addListener((accessToken: string | undefined, expirationDate: string | undefined) => {\r\n authorizationClient.setAccessToken(accessToken, expirationDate);\r\n MobileHost.notifyMobileFrontend(\"notifyAuthAccessTokenChanged\", accessToken, expirationDate);\r\n });\r\n\r\n // following will provide impl for device specific api.\r\n setupMobileRpc();\r\n }\r\n const iModelHostConfiguration = opt?.iModelHost ?? new IModelHostConfiguration();\r\n iModelHostConfiguration.authorizationClient = authorizationClient;\r\n await NativeHost.startup({ ...opt, iModelHost: iModelHostConfiguration });\r\n\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}\r\n"]}
@@ -1,3 +1,4 @@
1
+ import { AccessToken } from "@itwin/core-bentley";
1
2
  /** @beta */
2
3
  export declare enum Orientation {
3
4
  Unknown = 0,
@@ -22,14 +23,16 @@ export interface MobileNotifications {
22
23
  notifyEnterForeground: () => void;
23
24
  notifyEnterBackground: () => void;
24
25
  notifyWillTerminate: () => void;
26
+ notifyAuthAccessTokenChanged: (accessToken: string | undefined, expirationDate: string | undefined) => void;
25
27
  }
26
28
  /** @beta */
27
- export declare type DeviceEvents = "memoryWarning" | "orientationChanged" | "enterForeground" | "enterBackground" | "willTerminate";
29
+ export declare type DeviceEvents = "memoryWarning" | "orientationChanged" | "enterForeground" | "enterBackground" | "willTerminate" | "authAccessTokenChanged";
28
30
  /**
29
31
  * The methods that may be invoked via Ipc from the frontend of a Mobile App that are implemented on its backend.
30
32
  * @beta
31
33
  */
32
34
  export interface MobileAppFunctions {
33
35
  reconnect: (connection: number) => Promise<void>;
36
+ getAccessToken: () => Promise<[AccessToken, string]>;
34
37
  }
35
38
  //# sourceMappingURL=MobileAppProps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MobileAppProps.d.ts","sourceRoot":"","sources":["../../../src/common/MobileAppProps.ts"],"names":[],"mappings":"AAKA,YAAY;AACZ,oBAAY,WAAW;IACrB,OAAO,IAAI;IACX,QAAQ,IAAM;IACd,kBAAkB,IAAM;IACxB,aAAa,IAAM;IACnB,cAAc,IAAM;IACpB,MAAM,KAAO;IACb,QAAQ,KAAO;CAChB;AAED,YAAY;AACZ,oBAAY,YAAY;IACtB,OAAO,IAAI;IACX,SAAS,IAAI;IACb,QAAQ,IAAI;IACZ,IAAI,IAAI;CACT;AAED,YAAY;AACZ,MAAM,WAAW,mBAAmB;IAClC,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,wBAAwB,EAAE,MAAM,IAAI,CAAC;IACrC,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,YAAY;AACZ,oBAAY,YAAY,GAAG,eAAe,GAAG,oBAAoB,GAAG,iBAAiB,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAE5H;;;EAGE;AACF,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD"}
1
+ {"version":3,"file":"MobileAppProps.d.ts","sourceRoot":"","sources":["../../../src/common/MobileAppProps.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,YAAY;AACZ,oBAAY,WAAW;IACrB,OAAO,IAAI;IACX,QAAQ,IAAM;IACd,kBAAkB,IAAM;IACxB,aAAa,IAAM;IACnB,cAAc,IAAM;IACpB,MAAM,KAAO;IACb,QAAQ,KAAO;CAChB;AAED,YAAY;AACZ,oBAAY,YAAY;IACtB,OAAO,IAAI;IACX,SAAS,IAAI;IACb,QAAQ,IAAI;IACZ,IAAI,IAAI;CACT;AAED,YAAY;AACZ,MAAM,WAAW,mBAAmB;IAClC,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,wBAAwB,EAAE,MAAM,IAAI,CAAC;IACrC,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,4BAA4B,EAAE,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,cAAc,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;CAC7G;AAED,YAAY;AACZ,oBAAY,YAAY,GAAG,eAAe,GAAG,oBAAoB,GAAG,iBAAiB,GAAG,iBAAiB,GAAG,eAAe,GAAG,wBAAwB,CAAC;AAEvJ;;;EAGE;AACF,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,cAAc,EAAE,MAAM,OAAO,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;CACtD"}
@@ -1 +1 @@
1
- {"version":3,"file":"MobileAppProps.js","sourceRoot":"","sources":["../../../src/common/MobileAppProps.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,YAAY;AACZ,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,mDAAW,CAAA;IACX,qDAAc,CAAA;IACd,yEAAwB,CAAA;IACxB,+DAAmB,CAAA;IACnB,iEAAoB,CAAA;IACpB,kDAAa,CAAA;IACb,sDAAe,CAAA;AACjB,CAAC,EARW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAQtB;AAED,YAAY;AACZ,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,qDAAW,CAAA;IACX,yDAAa,CAAA;IACb,uDAAY,CAAA;IACZ,+CAAQ,CAAA;AACV,CAAC,EALW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAKvB","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/** @beta */\r\nexport enum Orientation {\r\n Unknown = 0,\r\n Portrait = 0x1,\r\n PortraitUpsideDown = 0x2,\r\n LandscapeLeft = 0x4,\r\n LandscapeRight = 0x8,\r\n FaceUp = 0x10,\r\n FaceDown = 0x20,\r\n}\r\n\r\n/** @beta */\r\nexport enum BatteryState {\r\n Unknown = 0,\r\n Unplugged = 1,\r\n Charging = 2,\r\n Full = 3,\r\n}\r\n\r\n/** @beta */\r\nexport interface MobileNotifications {\r\n notifyMemoryWarning: () => void;\r\n notifyOrientationChanged: () => void;\r\n notifyEnterForeground: () => void;\r\n notifyEnterBackground: () => void;\r\n notifyWillTerminate: () => void;\r\n}\r\n\r\n/** @beta */\r\nexport type DeviceEvents = \"memoryWarning\" | \"orientationChanged\" | \"enterForeground\" | \"enterBackground\" | \"willTerminate\";\r\n\r\n/**\r\n* The methods that may be invoked via Ipc from the frontend of a Mobile App that are implemented on its backend.\r\n* @beta\r\n*/\r\nexport interface MobileAppFunctions {\r\n reconnect: (connection: number) => Promise<void>;\r\n}\r\n"]}
1
+ {"version":3,"file":"MobileAppProps.js","sourceRoot":"","sources":["../../../src/common/MobileAppProps.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAI/F,YAAY;AACZ,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,mDAAW,CAAA;IACX,qDAAc,CAAA;IACd,yEAAwB,CAAA;IACxB,+DAAmB,CAAA;IACnB,iEAAoB,CAAA;IACpB,kDAAa,CAAA;IACb,sDAAe,CAAA;AACjB,CAAC,EARW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAQtB;AAED,YAAY;AACZ,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,qDAAW,CAAA;IACX,yDAAa,CAAA;IACb,uDAAY,CAAA;IACZ,+CAAQ,CAAA;AACV,CAAC,EALW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAKvB","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 { AccessToken } from \"@itwin/core-bentley\";\r\n\r\n/** @beta */\r\nexport enum Orientation {\r\n Unknown = 0,\r\n Portrait = 0x1,\r\n PortraitUpsideDown = 0x2,\r\n LandscapeLeft = 0x4,\r\n LandscapeRight = 0x8,\r\n FaceUp = 0x10,\r\n FaceDown = 0x20,\r\n}\r\n\r\n/** @beta */\r\nexport enum BatteryState {\r\n Unknown = 0,\r\n Unplugged = 1,\r\n Charging = 2,\r\n Full = 3,\r\n}\r\n\r\n/** @beta */\r\nexport interface MobileNotifications {\r\n notifyMemoryWarning: () => void;\r\n notifyOrientationChanged: () => void;\r\n notifyEnterForeground: () => void;\r\n notifyEnterBackground: () => void;\r\n notifyWillTerminate: () => void;\r\n notifyAuthAccessTokenChanged: (accessToken: string | undefined, expirationDate: string | undefined) => void;\r\n}\r\n\r\n/** @beta */\r\nexport type DeviceEvents = \"memoryWarning\" | \"orientationChanged\" | \"enterForeground\" | \"enterBackground\" | \"willTerminate\" | \"authAccessTokenChanged\";\r\n\r\n/**\r\n* The methods that may be invoked via Ipc from the frontend of a Mobile App that are implemented on its backend.\r\n* @beta\r\n*/\r\nexport interface MobileAppFunctions {\r\n reconnect: (connection: number) => Promise<void>;\r\n getAccessToken: () => Promise<[AccessToken, string]>;\r\n}\r\n"]}
@@ -1,6 +1,10 @@
1
1
  import { NativeAppOpts } from "@itwin/core-frontend";
2
2
  /** @beta */
3
- export declare type IOSAppOpts = NativeAppOpts;
3
+ export declare type IOSAppOpts = NativeAppOpts & {
4
+ iModelApp: {
5
+ authorizationClient?: never;
6
+ };
7
+ };
4
8
  /** @beta */
5
9
  export declare class IOSApp {
6
10
  private static _isValid;
@@ -1 +1 @@
1
- {"version":3,"file":"IOSApp.d.ts","sourceRoot":"","sources":["../../../src/frontend/IOSApp.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,YAAY;AACZ,oBAAY,UAAU,GAAG,aAAa,CAAC;AAEvC,YAAY;AACZ,qBAAa,MAAM;IAEjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,WAAkB,OAAO,YAA4B;WACjC,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU;CAM9C"}
1
+ {"version":3,"file":"IOSApp.d.ts","sourceRoot":"","sources":["../../../src/frontend/IOSApp.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,YAAY;AACZ,oBAAY,UAAU,GAAG,aAAa,GAAG;IAAE,SAAS,EAAE;QAAE,mBAAmB,CAAC,EAAE,KAAK,CAAA;KAAE,CAAA;CAAE,CAAC;AAExF,YAAY;AACZ,qBAAa,MAAM;IAEjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,WAAkB,OAAO,YAA4B;WACjC,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU;CAM9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"IOSApp.js","sourceRoot":"","sources":["../../../src/frontend/IOSApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAG/F,2CAAwC;AAKxC,YAAY;AACZ,MAAa,MAAM;IAGV,MAAM,KAAK,OAAO,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAiB;QAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACtB;QACD,MAAM,qBAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;;AATH,wBAUC;AARgB,eAAQ,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 { NativeAppOpts } from \"@itwin/core-frontend\";\r\nimport { MobileApp } from \"./MobileApp\";\r\n\r\n/** @beta */\r\nexport type IOSAppOpts = NativeAppOpts;\r\n\r\n/** @beta */\r\nexport class IOSApp {\r\n\r\n private static _isValid = false;\r\n public static get isValid() { return this._isValid; }\r\n public static async startup(opts?: IOSAppOpts) {\r\n if (!this._isValid) {\r\n this._isValid = true;\r\n }\r\n await MobileApp.startup(opts);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"IOSApp.js","sourceRoot":"","sources":["../../../src/frontend/IOSApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAG/F,2CAAwC;AAKxC,YAAY;AACZ,MAAa,MAAM;IAGV,MAAM,KAAK,OAAO,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAiB;QAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACtB;QACD,MAAM,qBAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;;AATH,wBAUC;AARgB,eAAQ,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 { NativeAppOpts } from \"@itwin/core-frontend\";\r\nimport { MobileApp } from \"./MobileApp\";\r\n\r\n/** @beta */\r\nexport type IOSAppOpts = NativeAppOpts & { iModelApp: { authorizationClient?: never } };\r\n\r\n/** @beta */\r\nexport class IOSApp {\r\n\r\n private static _isValid = false;\r\n public static get isValid() { return this._isValid; }\r\n public static async startup(opts?: IOSAppOpts) {\r\n if (!this._isValid) {\r\n this._isValid = true;\r\n }\r\n await MobileApp.startup(opts);\r\n }\r\n}\r\n"]}
@@ -8,6 +8,7 @@ export declare class MobileApp {
8
8
  static onEnterForeground: BeEvent<() => void>;
9
9
  static onEnterBackground: BeEvent<() => void>;
10
10
  static onWillTerminate: BeEvent<() => void>;
11
+ static onAuthAccessTokenChanged: BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>;
11
12
  static callBackend<T extends AsyncMethodsOf<MobileAppFunctions>>(methodName: T, ...args: Parameters<MobileAppFunctions[T]>): Promise<PromiseReturnType<MobileAppFunctions[T]>>;
12
13
  private static _isValid;
13
14
  static get isValid(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"MobileApp.d.ts","sourceRoot":"","sources":["../../../src/frontend/MobileApp.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAU,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEzF,OAAO,EAAqB,aAAa,EAAuB,MAAM,sBAAsB,CAAC;AAE7F,OAAO,EAAE,kBAAkB,EAAuB,MAAM,0BAA0B,CAAC;AAoBnF,YAAY;AACZ,qBAAa,SAA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AC,CAAC;IAIvI,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,WAAkB,OAAO,YAA4B;IACrD;;;OAGG;WACiB,OAAO,CAAC,IAAI,CAAC,EAAE,aAAa;CAsBjD"}
@@ -10,6 +10,7 @@ const core_common_1 = require("@itwin/core-common");
10
10
  const core_frontend_1 = require("@itwin/core-frontend");
11
11
  const MobileAppChannel_1 = require("../common/MobileAppChannel");
12
12
  const MobileRpcManager_1 = require("../common/MobileRpcManager");
13
+ const MobileAuthorizationFrontend_1 = require("./MobileAuthorizationFrontend");
13
14
  /** receive notifications from backend */
14
15
  class MobileAppNotifyHandler extends core_frontend_1.NotificationHandler {
15
16
  get channelName() { return MobileAppChannel_1.mobileAppNotify; }
@@ -24,6 +25,9 @@ class MobileAppNotifyHandler extends core_frontend_1.NotificationHandler {
24
25
  notifyEnterForeground() { MobileApp.onEnterBackground.raiseEvent(); }
25
26
  notifyEnterBackground() { MobileApp.onEnterBackground.raiseEvent(); }
26
27
  notifyWillTerminate() { MobileApp.onWillTerminate.raiseEvent(); }
28
+ notifyAuthAccessTokenChanged(accessToken, expirationDate) {
29
+ MobileApp.onAuthAccessTokenChanged.raiseEvent(accessToken, expirationDate);
30
+ }
27
31
  }
28
32
  /** @beta */
29
33
  class MobileApp {
@@ -37,13 +41,21 @@ class MobileApp {
37
41
  */
38
42
  static async startup(opts) {
39
43
  var _a, _b;
44
+ const iModelAppOpts = {
45
+ ...opts === null || opts === void 0 ? void 0 : opts.iModelApp,
46
+ };
47
+ const authorizationClient = new MobileAuthorizationFrontend_1.MobileAuthorizationFrontend();
48
+ iModelAppOpts.authorizationClient = authorizationClient;
40
49
  if (!this._isValid) {
50
+ this.onAuthAccessTokenChanged.addListener((accessToken, expirationDate) => {
51
+ authorizationClient.setAccessToken(accessToken, expirationDate);
52
+ });
41
53
  const rpcInterfaces = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.iModelApp) === null || _a === void 0 ? void 0 : _a.rpcInterfaces) !== null && _b !== void 0 ? _b : [core_common_1.IModelReadRpcInterface, core_common_1.IModelTileRpcInterface];
42
54
  MobileRpcManager_1.MobileRpcManager.initializeClient(rpcInterfaces);
43
55
  this._isValid = true;
44
56
  }
45
57
  const socket = new core_common_1.IpcWebSocketFrontend(); // needs work
46
- await core_frontend_1.NativeApp.startup(socket, opts);
58
+ await core_frontend_1.NativeApp.startup(socket, { ...opts, iModelApp: iModelAppOpts });
47
59
  MobileAppNotifyHandler.register(); // receives notifications from backend
48
60
  }
49
61
  }
@@ -53,5 +65,6 @@ MobileApp.onOrientationChanged = new core_bentley_1.BeEvent();
53
65
  MobileApp.onEnterForeground = new core_bentley_1.BeEvent();
54
66
  MobileApp.onEnterBackground = new core_bentley_1.BeEvent();
55
67
  MobileApp.onWillTerminate = new core_bentley_1.BeEvent();
68
+ MobileApp.onAuthAccessTokenChanged = new core_bentley_1.BeEvent();
56
69
  MobileApp._isValid = false;
57
70
  //# sourceMappingURL=MobileApp.js.map
@@ -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,wDAA6F;AAC7F,iEAA+E;AAE/E,iEAA8D;AAE9D,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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AI,sBAAO,EAAc,CAAC;AAC9C,yBAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;AAK3C,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 { 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\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.onEnterBackground.raiseEvent(); }\r\n public notifyEnterBackground() { MobileApp.onEnterBackground.raiseEvent(); }\r\n public notifyWillTerminate() { MobileApp.onWillTerminate.raiseEvent(); }\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 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 /**\r\n * This is called by either AndroidApp.startup or IOSApp.startup - it should not be called directly\r\n * @internal\r\n */\r\n public static async startup(opts?: NativeAppOpts) {\r\n if (!this._isValid) {\r\n const rpcInterfaces = opts?.iModelApp?.rpcInterfaces ?? [IModelReadRpcInterface, IModelTileRpcInterface];\r\n MobileRpcManager.initializeClient(rpcInterfaces);\r\n this._isValid = true;\r\n }\r\n const socket = new IpcWebSocketFrontend(); // needs work\r\n await NativeApp.startup(socket, opts);\r\n\r\n MobileAppNotifyHandler.register(); // receives notifications from backend\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"MobileApp.js","sourceRoot":"","sources":["../../../src/frontend/MobileApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAAyF;AACzF,oDAA0G;AAC1G,wDAA6F;AAC7F,iEAA+E;AAE/E,iEAA8D;AAC9D,+EAA4E;AAE5E,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,iBAAiB,CAAC,UAAU,EAAE,CAAC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,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;;AAtCH,8BAuCC;AAtCe,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 { 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/** 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.onEnterBackground.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 /**\r\n * This is called by either AndroidApp.startup or IOSApp.startup - it should not be called directly\r\n * @internal\r\n */\r\n public static async startup(opts?: NativeAppOpts) {\r\n const iModelAppOpts = {\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"]}
@@ -0,0 +1,18 @@
1
+ /** @packageDocumentation
2
+ * @module OIDC
3
+ */
4
+ import { AccessToken } from "@itwin/core-bentley";
5
+ import { AuthorizationClient } from "@itwin/core-common";
6
+ /** Utility to provide and cache auth tokens from native mobile apps to IModelApp.
7
+ * @internal
8
+ */
9
+ export declare class MobileAuthorizationFrontend implements AuthorizationClient {
10
+ private _accessToken;
11
+ private _expirationDate;
12
+ private _expiryBuffer;
13
+ private _fetchingToken;
14
+ private get _hasExpired();
15
+ getAccessToken(): Promise<AccessToken>;
16
+ setAccessToken(accessToken?: string, expirationDate?: string): void;
17
+ }
18
+ //# sourceMappingURL=MobileAuthorizationFrontend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MobileAuthorizationFrontend.d.ts","sourceRoot":"","sources":["../../../src/frontend/MobileAuthorizationFrontend.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD;;GAEG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IACrE,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,aAAa,CAAW;IAChC,OAAO,CAAC,cAAc,CAAS;IAE/B,OAAO,KAAK,WAAW,GAEtB;IAEY,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAkB5C,cAAc,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM;CAIpE"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module OIDC
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.MobileAuthorizationFrontend = void 0;
11
+ const MobileApp_1 = require("./MobileApp");
12
+ /** Utility to provide and cache auth tokens from native mobile apps to IModelApp.
13
+ * @internal
14
+ */
15
+ class MobileAuthorizationFrontend {
16
+ constructor() {
17
+ this._accessToken = "";
18
+ this._expiryBuffer = 60 * 10; // ten minutes
19
+ this._fetchingToken = false;
20
+ }
21
+ get _hasExpired() {
22
+ return this._expirationDate !== undefined && this._expirationDate.getTime() - Date.now() <= this._expiryBuffer * 1000;
23
+ }
24
+ async getAccessToken() {
25
+ if (this._fetchingToken) {
26
+ return Promise.reject(); // short-circuits any recursive use of this function
27
+ }
28
+ if (this._accessToken && !this._hasExpired) {
29
+ return this._accessToken;
30
+ }
31
+ else {
32
+ this._fetchingToken = true;
33
+ const result = await MobileApp_1.MobileApp.callBackend("getAccessToken");
34
+ this._accessToken = result[0];
35
+ if (result[1])
36
+ this._expirationDate = new Date(result[1]);
37
+ this._fetchingToken = false;
38
+ return this._accessToken;
39
+ }
40
+ }
41
+ setAccessToken(accessToken, expirationDate) {
42
+ this._accessToken = accessToken !== null && accessToken !== void 0 ? accessToken : "";
43
+ this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;
44
+ }
45
+ }
46
+ exports.MobileAuthorizationFrontend = MobileAuthorizationFrontend;
47
+ //# sourceMappingURL=MobileAuthorizationFrontend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MobileAuthorizationFrontend.js","sourceRoot":"","sources":["../../../src/frontend/MobileAu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AC,CAAC,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;CACF;AAhCD,kEAgCC","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 } from \"@itwin/core-bentley\";\r\nimport { AuthorizationClient } from \"@itwin/core-common\";\r\nimport { MobileApp } from \"./MobileApp\";\r\n\r\n/** Utility to provide and cache auth tokens from native mobile apps to IModelApp.\r\n * @internal\r\n */\r\nexport class MobileAuthorizationFrontend implements AuthorizationClient {\r\n private _accessToken: AccessToken = \"\";\r\n private _expirationDate: Date | undefined;\r\n private _expiryBuffer = 60 * 10; // ten minutes\r\n private _fetchingToken = false;\r\n\r\n private get _hasExpired(): boolean {\r\n return this._expirationDate !== undefined && this._expirationDate.getTime() - Date.now() <= this._expiryBuffer * 1000;\r\n }\r\n\r\n public async getAccessToken(): Promise<AccessToken> {\r\n if (this._fetchingToken) {\r\n return Promise.reject(); // short-circuits any recursive use of this function\r\n }\r\n\r\n if (this._accessToken && !this._hasExpired) {\r\n return this._accessToken;\r\n } else {\r\n this._fetchingToken = true;\r\n const result = await MobileApp.callBackend(\"getAccessToken\");\r\n this._accessToken = result[0];\r\n if (result[1])\r\n this._expirationDate = new Date(result[1]);\r\n this._fetchingToken = false;\r\n return this._accessToken;\r\n }\r\n }\r\n\r\n public setAccessToken(accessToken?: string, expirationDate?: string) {\r\n this._accessToken = accessToken ?? \"\";\r\n this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;\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.2.0-dev.9",
3
+ "version": "3.3.0-dev.0",
4
4
  "description": "iTwin.js MobileHost and MobileApp",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -21,11 +21,11 @@
21
21
  "url": "http://www.bentley.com"
22
22
  },
23
23
  "peerDependencies": {
24
- "@itwin/core-backend": "^3.2.0-dev.9",
25
- "@itwin/core-bentley": "^3.2.0-dev.9",
26
- "@itwin/core-common": "^3.2.0-dev.9",
27
- "@itwin/core-frontend": "^3.2.0-dev.9",
28
- "@itwin/presentation-common": "^3.2.0-dev.9"
24
+ "@itwin/core-backend": "^3.3.0-dev.0",
25
+ "@itwin/core-bentley": "^3.3.0-dev.0",
26
+ "@itwin/core-common": "^3.3.0-dev.0",
27
+ "@itwin/core-frontend": "^3.3.0-dev.0",
28
+ "@itwin/presentation-common": "^3.3.0-dev.0"
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.2.0-dev.9",
40
- "@itwin/core-backend": "3.2.0-dev.9",
41
- "@itwin/core-bentley": "3.2.0-dev.9",
42
- "@itwin/core-common": "3.2.0-dev.9",
43
- "@itwin/core-frontend": "3.2.0-dev.9",
44
- "@itwin/eslint-plugin": "3.2.0-dev.9",
45
- "@itwin/presentation-common": "3.2.0-dev.9",
39
+ "@itwin/build-tools": "3.3.0-dev.0",
40
+ "@itwin/core-backend": "3.3.0-dev.0",
41
+ "@itwin/core-bentley": "3.3.0-dev.0",
42
+ "@itwin/core-common": "3.3.0-dev.0",
43
+ "@itwin/core-frontend": "3.3.0-dev.0",
44
+ "@itwin/eslint-plugin": "3.3.0-dev.0",
45
+ "@itwin/presentation-common": "3.3.0-dev.0",
46
46
  "@types/chai": "^4.1.4",
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": "14.14.31",
51
+ "@types/node": "16.11.7",
52
52
  "@types/qs": "^6.5.0",
53
53
  "@types/superagent": "^4.1.14",
54
54
  "@types/ws": "^7.0.0",