@itwin/core-frontend 3.3.0-dev.28 → 3.3.0-dev.29
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 +9 -1
- package/lib/cjs/extension/ExtensionAdmin.d.ts +5 -2
- package/lib/cjs/extension/ExtensionAdmin.d.ts.map +1 -1
- package/lib/cjs/extension/ExtensionAdmin.js +24 -6
- package/lib/cjs/extension/ExtensionAdmin.js.map +1 -1
- package/lib/cjs/extension/providers/ExtensionServiceClient.d.ts +8 -6
- package/lib/cjs/extension/providers/ExtensionServiceClient.d.ts.map +1 -1
- package/lib/cjs/extension/providers/ExtensionServiceClient.js +13 -6
- package/lib/cjs/extension/providers/ExtensionServiceClient.js.map +1 -1
- package/lib/cjs/extension/providers/RemoteExtensionProvider.d.ts +0 -2
- package/lib/cjs/extension/providers/RemoteExtensionProvider.d.ts.map +1 -1
- package/lib/cjs/extension/providers/RemoteExtensionProvider.js +9 -22
- package/lib/cjs/extension/providers/RemoteExtensionProvider.js.map +1 -1
- package/lib/cjs/extension/providers/ServiceExtensionProvider.d.ts +4 -6
- package/lib/cjs/extension/providers/ServiceExtensionProvider.d.ts.map +1 -1
- package/lib/cjs/extension/providers/ServiceExtensionProvider.js +11 -22
- package/lib/cjs/extension/providers/ServiceExtensionProvider.js.map +1 -1
- package/lib/esm/extension/ExtensionAdmin.d.ts +5 -2
- package/lib/esm/extension/ExtensionAdmin.d.ts.map +1 -1
- package/lib/esm/extension/ExtensionAdmin.js +24 -6
- package/lib/esm/extension/ExtensionAdmin.js.map +1 -1
- package/lib/esm/extension/providers/ExtensionServiceClient.d.ts +8 -6
- package/lib/esm/extension/providers/ExtensionServiceClient.d.ts.map +1 -1
- package/lib/esm/extension/providers/ExtensionServiceClient.js +13 -6
- package/lib/esm/extension/providers/ExtensionServiceClient.js.map +1 -1
- package/lib/esm/extension/providers/RemoteExtensionProvider.d.ts +0 -2
- package/lib/esm/extension/providers/RemoteExtensionProvider.d.ts.map +1 -1
- package/lib/esm/extension/providers/RemoteExtensionProvider.js +9 -22
- package/lib/esm/extension/providers/RemoteExtensionProvider.js.map +1 -1
- package/lib/esm/extension/providers/ServiceExtensionProvider.d.ts +4 -6
- package/lib/esm/extension/providers/ServiceExtensionProvider.d.ts.map +1 -1
- package/lib/esm/extension/providers/ServiceExtensionProvider.js +11 -22
- package/lib/esm/extension/providers/ServiceExtensionProvider.js.map +1 -1
- package/package.json +20 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Change Log - @itwin/core-frontend
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 10 Jun 2022 16:11:36 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 3.2.2
|
|
6
|
+
Fri, 10 Jun 2022 16:11:36 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- added errorOnMissingUniform render option
|
|
11
|
+
- Omit authorization in RPC communication between mobile frontend and backend.
|
|
4
12
|
|
|
5
13
|
## 3.2.1
|
|
6
14
|
Tue, 07 Jun 2022 15:02:56 GMT
|
|
@@ -29,10 +29,13 @@ export declare class ExtensionAdmin {
|
|
|
29
29
|
*/
|
|
30
30
|
addExtensions(providers: ExtensionProvider[]): Promise<void[]>;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* Registers a hostname for an extension.
|
|
33
|
+
* Once a hostname has been registered, only remote extensions from registered hosts are permitted to be added.
|
|
34
|
+
* @param hostUrl (string) Accepts both URLs and hostnames (e.g., http://localhost:3000, yourdomain.com, https://www.yourdomain.com, etc.).
|
|
34
35
|
*/
|
|
35
36
|
registerHost(hostUrl: string): void;
|
|
37
|
+
/** Returns the hostname of an input string. Throws an error if input is not a valid hostname (or URL). */
|
|
38
|
+
private getHostName;
|
|
36
39
|
/** Loops over all enabled Extensions and triggers each one if the provided event is defined. */
|
|
37
40
|
private activateExtensionEvents;
|
|
38
41
|
/** Executes the extension. Catches and logs any errors (so that an extension will not crash the main application). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionAdmin.d.ts","sourceRoot":"","sources":["../../../src/extension/ExtensionAdmin.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,KAAK,EAAqB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA4BxE;;;GAGG;AACH,qBAAa,cAAc;IACzB,2GAA2G;IAC3G,OAAO,CAAC,WAAW,CAA0E;IAC7F,OAAO,CAAC,MAAM,CAAW;IAEzB;;OAEG;IACI,SAAS,sBAEd;;IAMF;;;;;OAKG;IACU,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBrE;;;;OAIG;IACU,aAAa,CAAC,SAAS,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAM3E
|
|
1
|
+
{"version":3,"file":"ExtensionAdmin.d.ts","sourceRoot":"","sources":["../../../src/extension/ExtensionAdmin.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,KAAK,EAAqB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA4BxE;;;GAGG;AACH,qBAAa,cAAc;IACzB,2GAA2G;IAC3G,OAAO,CAAC,WAAW,CAA0E;IAC7F,OAAO,CAAC,MAAM,CAAW;IAEzB;;OAEG;IACI,SAAS,sBAEd;;IAMF;;;;;OAKG;IACU,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBrE;;;;OAIG;IACU,aAAa,CAAC,SAAS,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAM3E;;;;OAIG;IACI,YAAY,CAAC,OAAO,EAAE,MAAM;IAOnC,0GAA0G;IAC1G,OAAO,CAAC,WAAW;IAgBnB,gGAAgG;YAClF,uBAAuB;IAWrC,sHAAsH;YACxG,QAAQ;CAOvB"}
|
|
@@ -50,7 +50,7 @@ class ExtensionAdmin {
|
|
|
50
50
|
provider.execute(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
51
51
|
}
|
|
52
52
|
catch (e) {
|
|
53
|
-
throw new Error(`Failed to get manifest
|
|
53
|
+
throw new Error(`Failed to get extension manifest ${provider.hostname ? `at ${provider.hostname}` : ""}: ${e}`);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
@@ -62,13 +62,31 @@ class ExtensionAdmin {
|
|
|
62
62
|
return Promise.all(providers.map(async (provider) => this.addExtension(provider)));
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
65
|
+
* Registers a hostname for an extension.
|
|
66
|
+
* Once a hostname has been registered, only remote extensions from registered hosts are permitted to be added.
|
|
67
|
+
* @param hostUrl (string) Accepts both URLs and hostnames (e.g., http://localhost:3000, yourdomain.com, https://www.yourdomain.com, etc.).
|
|
67
68
|
*/
|
|
68
69
|
registerHost(hostUrl) {
|
|
69
|
-
const
|
|
70
|
-
if (this._hosts.indexOf(
|
|
71
|
-
this._hosts.push(
|
|
70
|
+
const hostname = this.getHostName(hostUrl);
|
|
71
|
+
if (this._hosts.indexOf(hostname) < 0) {
|
|
72
|
+
this._hosts.push(hostname);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Returns the hostname of an input string. Throws an error if input is not a valid hostname (or URL). */
|
|
76
|
+
getHostName(inputUrl) {
|
|
77
|
+
// inputs without a protocol (e.g., http://) will throw an error in URL constructor
|
|
78
|
+
const inputWithProtocol = /(http|https):\/\//.test(inputUrl) ?
|
|
79
|
+
inputUrl :
|
|
80
|
+
`https://${inputUrl}`;
|
|
81
|
+
try {
|
|
82
|
+
const hostname = new URL(inputWithProtocol).hostname.replace("www.", "");
|
|
83
|
+
return hostname;
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
if (e instanceof TypeError) {
|
|
87
|
+
throw new Error("Argument hostUrl should be a valid URL or hostname (i.e. http://localhost:3000, yourdomain.com, etc.).");
|
|
88
|
+
}
|
|
89
|
+
throw e;
|
|
72
90
|
}
|
|
73
91
|
}
|
|
74
92
|
/** Loops over all enabled Extensions and triggers each one if the provided event is defined. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionAdmin.js","sourceRoot":"","sources":["../../../src/extension/ExtensionAdmin.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAE7C,sEAAmE;AA6BnE;;;GAGG;AACH,MAAa,cAAc;IAYzB;QAXA,2GAA2G;QACnG,gBAAW,GAAoC,IAAI,GAAG,EAA8B,CAAC;QAG7F;;WAEG;QACI,cAAS,GAAG,KAAK,IAAI,EAAE;YAC5B,MAAM,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC,CAAC;QAGA,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CAAC,QAA2B;QACnD,IAAI,QAAQ,CAAC,QAAQ,EAAE;YACrB,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;YACnC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAC/D,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,sBAAsB,CAAC,CAAC;aAC7E;SACF;QACD,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC9C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE;gBAClC,QAAQ;gBACR,QAAQ;aACT,CAAC,CAAC;YACH,2DAA2D;YAC3D,IAAI,QAAQ,CAAC,gBAA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IACxF,KAAK,CAAC,uBAAuB,CAAC,KAAa;QACjD,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE;YACjD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB;gBAAE,SAAS;YACnD,KAAK,MAAM,eAAe,IAAI,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE;gBACjE,IAAI,eAAe,KAAK,KAAK,EAAE;oBAC7B,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,8DAA8D;iBACzF;aACF;SACF;IACH,CAAC;IAED,sHAAsH;IAC9G,KAAK,CAAC,QAAQ,CAAC,SAA6B;QAClD,IAAI;YACF,MAAM,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;SACpC;QAAC,OAAO,CAAC,EAAE;YACV,qBAAM,CAAC,QAAQ,CAAC,+CAAsB,CAAC,UAAU,EAAE,6BAA6B,SAAS,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;SAClH;IACH,CAAC;CACF;AAvGD,wCAuGC","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 Extensions\r\n */\r\n\r\nimport { Logger } from \"@itwin/core-bentley\";\r\n\r\nimport { FrontendLoggerCategory } from \"../FrontendLoggerCategory\";\r\nimport type { ExtensionManifest, ExtensionProvider } from \"./Extension\";\r\n\r\n/** The Extensions loading system has the following goals:\r\n * 1. Only fetch what is needed when it is required\r\n * 1. Load a manifest file\r\n * 2. Load the the main module when necessary (usually at an activation event)\r\n * 2. Download the extension's files\r\n *\r\n * 3 ways to load an Extension into the system:\r\n *\r\n * 1. Load both the Extension Manifest and import the main module of the extension from a local file/package.\r\n * 2. A minimum set of properties to get the manifest and javascript from a remote server.\r\n * 3. A minimum set of properties to get the manifest and javascript from Bentley's Extension Service.\r\n *\r\n * An Extension must be added to ExtensionAdmin before it can be executed during activation events.\r\n */\r\n\r\n/**\r\n * A \"ready to use\" Extension (contains a manifest object and an extension provider to help execute).\r\n * Will be used as the type for in-memory extensions in the ExtensionAdmin\r\n */\r\ninterface InstalledExtension {\r\n /** An extension provider that has been added to ExtensionAdmin */\r\n provider: ExtensionProvider;\r\n /** The manifest (package.json) of the extension */\r\n manifest: ExtensionManifest;\r\n}\r\n\r\n/** The Extension Admin controls the list of currently loaded Extensions.\r\n *\r\n * @alpha\r\n */\r\nexport class ExtensionAdmin {\r\n /** Defines the set of extensions that are currently known and can be invoked during activation events. */\r\n private _extensions: Map<string, InstalledExtension> = new Map<string, InstalledExtension>();\r\n private _hosts: string[];\r\n\r\n /** Fired when an Extension has been added or removed.\r\n * @internal\r\n */\r\n public onStartup = async () => {\r\n await this.activateExtensionEvents(\"onStartup\");\r\n };\r\n\r\n public constructor() {\r\n this._hosts = [];\r\n }\r\n\r\n /**\r\n * Adds an extension.\r\n * The manifest will be fetched and the extension will be activated on an activation event.\r\n * @param provider\r\n * @alpha\r\n */\r\n public async addExtension(provider: ExtensionProvider): Promise<void> {\r\n if (provider.hostname) {\r\n const hostName = provider.hostname;\r\n if (this._hosts.length > 0 && this._hosts.indexOf(hostName) < 0) {\r\n throw new Error(`Error loading extension: ${hostName} was not registered.`);\r\n }\r\n }\r\n try {\r\n const manifest = await provider.getManifest();\r\n this._extensions.set(manifest.name, {\r\n manifest,\r\n provider,\r\n });\r\n // TODO - temporary fix to execute the missed startup event\r\n if (manifest.activationEvents.includes(\"onStartup\"))\r\n provider.execute(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n } catch (e) {\r\n throw new Error(`Failed to get extension manifest ${provider.hostname ? `at ${provider.hostname}` : \"\"}: ${e}`);\r\n }\r\n }\r\n\r\n /**\r\n * Adds a list of extensions\r\n * @param providers\r\n * @alpha\r\n */\r\n public async addExtensions(providers: ExtensionProvider[]): Promise<void[]> {\r\n return Promise.all(\r\n providers.map(async (provider) => this.addExtension(provider))\r\n );\r\n }\r\n\r\n /**\r\n * Registers a hostname for an extension.\r\n * Once a hostname has been registered, only remote extensions from registered hosts are permitted to be added.\r\n * @param hostUrl (string) Accepts both URLs and hostnames (e.g., http://localhost:3000, yourdomain.com, https://www.yourdomain.com, etc.).\r\n */\r\n public registerHost(hostUrl: string) {\r\n const hostname = this.getHostName(hostUrl);\r\n if (this._hosts.indexOf(hostname) < 0) {\r\n this._hosts.push(hostname);\r\n }\r\n }\r\n\r\n /** Returns the hostname of an input string. Throws an error if input is not a valid hostname (or URL). */\r\n private getHostName(inputUrl: string): string {\r\n // inputs without a protocol (e.g., http://) will throw an error in URL constructor\r\n const inputWithProtocol = /(http|https):\\/\\//.test(inputUrl) ?\r\n inputUrl :\r\n `https://${inputUrl}`;\r\n try {\r\n const hostname = new URL(inputWithProtocol).hostname.replace(\"www.\", \"\");\r\n return hostname;\r\n } catch (e) {\r\n if (e instanceof TypeError) {\r\n throw new Error(\"Argument hostUrl should be a valid URL or hostname (i.e. http://localhost:3000, yourdomain.com, etc.).\");\r\n }\r\n throw e;\r\n }\r\n }\r\n\r\n /** Loops over all enabled Extensions and triggers each one if the provided event is defined. */\r\n private async activateExtensionEvents(event: string) {\r\n for (const extension of this._extensions.values()) {\r\n if (!extension.manifest.activationEvents) continue;\r\n for (const activationEvent of extension.manifest.activationEvents) {\r\n if (activationEvent === event) {\r\n this._execute(extension); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** Executes the extension. Catches and logs any errors (so that an extension will not crash the main application). */\r\n private async _execute(extension: InstalledExtension) {\r\n try {\r\n await extension.provider.execute();\r\n } catch (e) {\r\n Logger.logError(FrontendLoggerCategory.Extensions, `Error executing extension ${extension.manifest.name}: ${e}`);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -34,19 +34,21 @@ export declare class ExtensionClient {
|
|
|
34
34
|
private get _endpoint();
|
|
35
35
|
private parseExtensionMetadataArray;
|
|
36
36
|
/**
|
|
37
|
-
* Gets information on extensions. If extensionName is undefined, will return all extensions in the
|
|
38
|
-
* If
|
|
39
|
-
*
|
|
37
|
+
* Gets information on extensions. If extensionName is undefined, will return all extensions in the iTwin.
|
|
38
|
+
* If extensionName is defined, will return all versions of that extension.
|
|
39
|
+
* If iTwinId is undefined, will default to the public extensions.
|
|
40
40
|
* @param extensionName Extension name (optional)
|
|
41
|
+
* @param iTwinId iTwin Id (optional)
|
|
41
42
|
*/
|
|
42
|
-
getExtensions(accessToken: AccessToken,
|
|
43
|
+
getExtensions(accessToken: AccessToken, extensionName?: string, iTwinId?: string): Promise<ExtensionMetadata[]>;
|
|
43
44
|
/**
|
|
44
45
|
* Gets information about an extension's specific version
|
|
45
|
-
*
|
|
46
|
+
* If iTwinId is undefined, will assume the extension was published publicly.
|
|
46
47
|
* @param extensionName Extension name
|
|
47
48
|
* @param version Extension version
|
|
49
|
+
* @param iTwinId iTwin Id (optional)
|
|
48
50
|
*/
|
|
49
|
-
getExtensionMetadata(accessToken: AccessToken,
|
|
51
|
+
getExtensionMetadata(accessToken: AccessToken, extensionName: string, version: string, iTwinId?: string): Promise<ExtensionMetadata | undefined>;
|
|
50
52
|
}
|
|
51
53
|
export {};
|
|
52
54
|
//# sourceMappingURL=ExtensionServiceClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionServiceClient.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionServiceClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"ExtensionServiceClient.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionServiceClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAQ,MAAM,qBAAqB,CAAC;AAIxD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,qBAAqB;IAC7B,UAAU,EAAE,IAAI,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,QAAQ;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,IAAI,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;;IAKlC,OAAO,KAAK,SAAS,GAWpB;IAED,OAAO,CAAC,2BAA2B;IAcnC;;;;;;OAMG;IACU,aAAa,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,SAAa,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAahI;;;;;;OAMG;IACU,oBAAoB,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,SAAa,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;CAelK"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExtensionClient = void 0;
|
|
4
|
+
/*---------------------------------------------------------------------------------------------
|
|
5
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
4
9
|
const Request_1 = require("../../request/Request");
|
|
5
10
|
/**
|
|
6
11
|
* Client for querying, publishing and deleting iModel.js Extensions.
|
|
@@ -35,12 +40,13 @@ class ExtensionClient {
|
|
|
35
40
|
return ret;
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
|
-
* Gets information on extensions. If extensionName is undefined, will return all extensions in the
|
|
39
|
-
* If
|
|
40
|
-
*
|
|
43
|
+
* Gets information on extensions. If extensionName is undefined, will return all extensions in the iTwin.
|
|
44
|
+
* If extensionName is defined, will return all versions of that extension.
|
|
45
|
+
* If iTwinId is undefined, will default to the public extensions.
|
|
41
46
|
* @param extensionName Extension name (optional)
|
|
47
|
+
* @param iTwinId iTwin Id (optional)
|
|
42
48
|
*/
|
|
43
|
-
async getExtensions(accessToken,
|
|
49
|
+
async getExtensions(accessToken, extensionName, iTwinId = core_bentley_1.Guid.empty) {
|
|
44
50
|
const options = { method: "GET" };
|
|
45
51
|
options.headers = { authorization: accessToken };
|
|
46
52
|
const response = await (0, Request_1.request)(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName !== null && extensionName !== void 0 ? extensionName : ""}`, options);
|
|
@@ -52,11 +58,12 @@ class ExtensionClient {
|
|
|
52
58
|
}
|
|
53
59
|
/**
|
|
54
60
|
* Gets information about an extension's specific version
|
|
55
|
-
*
|
|
61
|
+
* If iTwinId is undefined, will assume the extension was published publicly.
|
|
56
62
|
* @param extensionName Extension name
|
|
57
63
|
* @param version Extension version
|
|
64
|
+
* @param iTwinId iTwin Id (optional)
|
|
58
65
|
*/
|
|
59
|
-
async getExtensionMetadata(accessToken,
|
|
66
|
+
async getExtensionMetadata(accessToken, extensionName, version, iTwinId = core_bentley_1.Guid.empty) {
|
|
60
67
|
const options = { method: "GET" };
|
|
61
68
|
options.headers = { authorization: accessToken };
|
|
62
69
|
const response = await (0, Request_1.request)(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName}/${version}`, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Extension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Q,KAAK,IAAI,CAAC,EAAE;QAEhH,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,GAAG,EAAE,UAAU,CAAC,GAAG;QACnB,OAAO,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QACvC,QAAQ,EAAE,UAAU,CAAC,QAAQ;KAC9B,CAAC;AACJ,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\nimport { AccessToken } from \"@itwin/core-bentley\";\r\n\r\nimport { request, RequestOptions } from \"../../request/Request\";\r\n\r\n/** Structure of extensions from the ExtensionService\r\n * @internal\r\n */\r\nexport interface ExtensionMetadata {\r\n contextId: string;\r\n extensionName: string;\r\n version: string;\r\n files: FileInfo[];\r\n uploadedBy: string;\r\n timestamp: Date;\r\n status: ExtensionUploadStatus;\r\n isPublic: boolean;\r\n}\r\n\r\ninterface ExtensionUploadStatus {\r\n updateTime: Date;\r\n status: string;\r\n}\r\n\r\ninterface FileInfo {\r\n url: string;\r\n expires: Date;\r\n checksum: string;\r\n}\r\n\r\n/**\r\n * Client for querying, publishing and deleting iModel.js Extensions.\r\n *\r\n * The `imodel-extension-service-api` OIDC scope is required for all operations and the `imodel-extension-service:modify` is\r\n * required for modification operations (modify, publish, and deleting).\r\n * @alpha\r\n */\r\nexport class ExtensionClient {\r\n private readonly _baseUrl: string;\r\n public constructor() {\r\n this._baseUrl = \"https://api.bentley.com/iModelExtensionService/\";\r\n }\r\n\r\n private get _endpoint(): string {\r\n const prefix = process.env.IMJS_URL_PREFIX;\r\n const baseUrl = new URL(this._baseUrl);\r\n if (prefix)\r\n baseUrl.hostname = prefix + new URL(baseUrl).hostname;\r\n\r\n if (!baseUrl.pathname.endsWith(\"/\"))\r\n baseUrl.pathname += \"/\";\r\n\r\n baseUrl.pathname += \"v1.0/\";\r\n return baseUrl.toString();\r\n }\r\n\r\n private parseExtensionMetadataArray(json: any): ExtensionMetadata[] {\r\n if (!(json instanceof Array))\r\n return [];\r\n\r\n const ret: ExtensionMetadata[] = [];\r\n json.forEach((extensionJson) => {\r\n const extension = extensionMetadataFromJSON(extensionJson);\r\n if (extension !== undefined)\r\n ret.push(extension);\r\n });\r\n\r\n return ret;\r\n }\r\n\r\n /**\r\n * Gets information on extensions. If extensionName is undefined, will return all extensions in the context.\r\n * If it's defined, will return all versions of that extension.\r\n * @param iTwinId Context Id\r\n * @param extensionName Extension name (optional)\r\n */\r\n public async getExtensions(accessToken: AccessToken, iTwinId: string, extensionName?: string): Promise<ExtensionMetadata[]> {\r\n const options: RequestOptions = { method: \"GET\" };\r\n options.headers = { authorization: accessToken };\r\n const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName ?? \"\"}`, options);\r\n if (response.status !== 200)\r\n throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);\r\n\r\n if (!(response.body instanceof Array) || response.body.length < 1)\r\n return [];\r\n\r\n return this.parseExtensionMetadataArray(response.body);\r\n }\r\n\r\n /**\r\n * Gets information about an extension's specific version\r\n * @param iTwinId iTwin Id\r\n * @param extensionName Extension name\r\n * @param version Extension version\r\n */\r\n public async getExtensionMetadata(accessToken: AccessToken, iTwinId: string, extensionName: string, version: string): Promise<ExtensionMetadata | undefined> {\r\n\r\n const options: RequestOptions = { method: \"GET\" };\r\n options.headers = { authorization: accessToken };\r\n const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName}/${version}`, options);\r\n if (response.status !== 200)\r\n throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);\r\n\r\n if (!(response.body instanceof Array) || response.body.length < 1)\r\n return undefined;\r\n if (response.body.length > 1)\r\n throw new Error(\"Server returned too many extensions\");\r\n\r\n return extensionMetadataFromJSON(response.body[0]);\r\n }\r\n}\r\n\r\n/**\r\n * Validates JSON and returns ExtensionMetadata\r\n */\r\nfunction extensionMetadataFromJSON(jsonObject: any): ExtensionMetadata | undefined {\r\n if (jsonObject.contextId === undefined || typeof jsonObject.contextId !== \"string\" ||\r\n jsonObject.extensionName === undefined || typeof jsonObject.extensionName !== \"string\" ||\r\n jsonObject.version === undefined || typeof jsonObject.version !== \"string\" ||\r\n jsonObject.files === undefined || !(jsonObject.files instanceof Array) ||\r\n jsonObject.uploadedBy === undefined || typeof jsonObject.uploadedBy !== \"string\" ||\r\n jsonObject.timestamp === undefined || typeof jsonObject.timestamp !== \"string\" ||\r\n jsonObject.isPublic === undefined || typeof jsonObject.isPublic !== \"boolean\" ||\r\n jsonObject.extensionStatus === undefined) {\r\n\r\n return undefined;\r\n }\r\n\r\n const status = statusFromJSON(jsonObject.extensionStatus);\r\n if (status === undefined)\r\n return undefined;\r\n\r\n const files = new Array(jsonObject.files.length);\r\n for (let i = 0; i < jsonObject.files.length; i++) {\r\n const parsed = fileInfoFromJSON(jsonObject.files[i]);\r\n if (parsed === undefined)\r\n return undefined;\r\n files[i] = parsed;\r\n }\r\n\r\n return {\r\n contextId: jsonObject.contextId,\r\n extensionName: jsonObject.extensionName,\r\n version: jsonObject.version,\r\n files,\r\n uploadedBy: jsonObject.uploadedBy,\r\n timestamp: new Date(jsonObject.timestamp),\r\n isPublic: jsonObject.isPublic,\r\n status,\r\n };\r\n}\r\n\r\nfunction statusFromJSON(jsonObject: any) {\r\n if (jsonObject.statusUpdateTime === undefined || typeof jsonObject.statusUpdateTime !== \"string\" ||\r\n jsonObject.status === undefined || (jsonObject.status !== null && typeof jsonObject.status !== \"string\")) {\r\n\r\n return undefined;\r\n }\r\n\r\n return {\r\n updateTime: new Date(jsonObject.statusUpdateTime),\r\n status: jsonObject.status ?? \"Valid\",\r\n };\r\n}\r\n\r\nfunction fileInfoFromJSON(jsonObject: any) {\r\n if (jsonObject.url === undefined || typeof jsonObject.url !== \"string\" ||\r\n jsonObject.expiresAt === undefined || typeof jsonObject.expiresAt !== \"string\" ||\r\n jsonObject.checksum === undefined || (typeof jsonObject.checksum !== \"string\" && jsonObject.checksum !== null)) {\r\n\r\n return undefined;\r\n }\r\n\r\n return {\r\n url: jsonObject.url,\r\n expires: new Date(jsonObject.expiresAt),\r\n checksum: jsonObject.checksum,\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ExtensionServiceClient.js","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionServiceClient.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAwD;AAExD,mDAAgE;AA2BhE;;;;;;GAMG;AACH,MAAa,eAAe;IAE1B;QACE,IAAI,CAAC,QAAQ,GAAG,iDAAiD,CAAC;IACpE,CAAC;IAED,IAAY,SAAS;QACnB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,MAAM;YACR,OAAO,CAAC,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;QAExD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YACjC,OAAO,CAAC,QAAQ,IAAI,GAAG,CAAC;QAE1B,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC;QAC5B,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC5B,CAAC;IAEO,2BAA2B,CAAC,IAAS;QAC3C,IAAI,CAAC,CAAC,IAAI,YAAY,KAAK,CAAC;YAC1B,OAAO,EAAE,CAAC;QAEZ,MAAM,GAAG,GAAwB,EAAE,CAAC;QACpC,IAAI,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;YAC7B,MAAM,SAAS,GAAG,yBAAyB,CAAC,aAAa,CAAC,CAAC;YAC3D,IAAI,SAAS,KAAK,SAAS;gBACzB,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC,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e;IACvC,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ;QACpE,UAAU,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,UAAU,CAAC,SAAS,KAAK,QAAQ;QAC9E,UAAU,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,OAAO,UAAU,CAAC,QAAQ,KAAK,QAAQ,IAAI,UAAU,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE;QAEhH,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,GAAG,EAAE,UAAU,CAAC,GAAG;QACnB,OAAO,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QACvC,QAAQ,EAAE,UAAU,CAAC,QAAQ;KAC9B,CAAC;AACJ,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\nimport { AccessToken, Guid } from \"@itwin/core-bentley\";\r\n\r\nimport { request, RequestOptions } from \"../../request/Request\";\r\n\r\n/** Structure of extensions from the ExtensionService\r\n * @internal\r\n */\r\nexport interface ExtensionMetadata {\r\n contextId: string;\r\n extensionName: string;\r\n version: string;\r\n files: FileInfo[];\r\n uploadedBy: string;\r\n timestamp: Date;\r\n status: ExtensionUploadStatus;\r\n isPublic: boolean;\r\n}\r\n\r\ninterface ExtensionUploadStatus {\r\n updateTime: Date;\r\n status: string;\r\n}\r\n\r\ninterface FileInfo {\r\n url: string;\r\n expires: Date;\r\n checksum: string;\r\n}\r\n\r\n/**\r\n * Client for querying, publishing and deleting iModel.js Extensions.\r\n *\r\n * The `imodel-extension-service-api` OIDC scope is required for all operations and the `imodel-extension-service:modify` is\r\n * required for modification operations (modify, publish, and deleting).\r\n * @alpha\r\n */\r\nexport class ExtensionClient {\r\n private readonly _baseUrl: string;\r\n public constructor() {\r\n this._baseUrl = \"https://api.bentley.com/iModelExtensionService/\";\r\n }\r\n\r\n private get _endpoint(): string {\r\n const prefix = process.env.IMJS_URL_PREFIX;\r\n const baseUrl = new URL(this._baseUrl);\r\n if (prefix)\r\n baseUrl.hostname = prefix + new URL(baseUrl).hostname;\r\n\r\n if (!baseUrl.pathname.endsWith(\"/\"))\r\n baseUrl.pathname += \"/\";\r\n\r\n baseUrl.pathname += \"v1.0/\";\r\n return baseUrl.toString();\r\n }\r\n\r\n private parseExtensionMetadataArray(json: any): ExtensionMetadata[] {\r\n if (!(json instanceof Array))\r\n return [];\r\n\r\n const ret: ExtensionMetadata[] = [];\r\n json.forEach((extensionJson) => {\r\n const extension = extensionMetadataFromJSON(extensionJson);\r\n if (extension !== undefined)\r\n ret.push(extension);\r\n });\r\n\r\n return ret;\r\n }\r\n\r\n /**\r\n * Gets information on extensions. If extensionName is undefined, will return all extensions in the iTwin.\r\n * If extensionName is defined, will return all versions of that extension.\r\n * If iTwinId is undefined, will default to the public extensions.\r\n * @param extensionName Extension name (optional)\r\n * @param iTwinId iTwin Id (optional)\r\n */\r\n public async getExtensions(accessToken: AccessToken, extensionName?: string, iTwinId = Guid.empty): Promise<ExtensionMetadata[]> {\r\n const options: RequestOptions = { method: \"GET\" };\r\n options.headers = { authorization: accessToken };\r\n const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName ?? \"\"}`, options);\r\n if (response.status !== 200)\r\n throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);\r\n\r\n if (!(response.body instanceof Array) || response.body.length < 1)\r\n return [];\r\n\r\n return this.parseExtensionMetadataArray(response.body);\r\n }\r\n\r\n /**\r\n * Gets information about an extension's specific version\r\n * If iTwinId is undefined, will assume the extension was published publicly.\r\n * @param extensionName Extension name\r\n * @param version Extension version\r\n * @param iTwinId iTwin Id (optional)\r\n */\r\n public async getExtensionMetadata(accessToken: AccessToken, extensionName: string, version: string, iTwinId = Guid.empty): Promise<ExtensionMetadata | undefined> {\r\n\r\n const options: RequestOptions = { method: \"GET\" };\r\n options.headers = { authorization: accessToken };\r\n const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName}/${version}`, options);\r\n if (response.status !== 200)\r\n throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);\r\n\r\n if (!(response.body instanceof Array) || response.body.length < 1)\r\n return undefined;\r\n if (response.body.length > 1)\r\n throw new Error(\"Server returned too many extensions\");\r\n\r\n return extensionMetadataFromJSON(response.body[0]);\r\n }\r\n}\r\n\r\n/**\r\n * Validates JSON and returns ExtensionMetadata\r\n */\r\nfunction extensionMetadataFromJSON(jsonObject: any): ExtensionMetadata | undefined {\r\n if (jsonObject.contextId === undefined || typeof jsonObject.contextId !== \"string\" ||\r\n jsonObject.extensionName === undefined || typeof jsonObject.extensionName !== \"string\" ||\r\n jsonObject.version === undefined || typeof jsonObject.version !== \"string\" ||\r\n jsonObject.files === undefined || !(jsonObject.files instanceof Array) ||\r\n jsonObject.uploadedBy === undefined || typeof jsonObject.uploadedBy !== \"string\" ||\r\n jsonObject.timestamp === undefined || typeof jsonObject.timestamp !== \"string\" ||\r\n jsonObject.isPublic === undefined || typeof jsonObject.isPublic !== \"boolean\" ||\r\n jsonObject.extensionStatus === undefined) {\r\n\r\n return undefined;\r\n }\r\n\r\n const status = statusFromJSON(jsonObject.extensionStatus);\r\n if (status === undefined)\r\n return undefined;\r\n\r\n const files = new Array(jsonObject.files.length);\r\n for (let i = 0; i < jsonObject.files.length; i++) {\r\n const parsed = fileInfoFromJSON(jsonObject.files[i]);\r\n if (parsed === undefined)\r\n return undefined;\r\n files[i] = parsed;\r\n }\r\n\r\n return {\r\n contextId: jsonObject.contextId,\r\n extensionName: jsonObject.extensionName,\r\n version: jsonObject.version,\r\n files,\r\n uploadedBy: jsonObject.uploadedBy,\r\n timestamp: new Date(jsonObject.timestamp),\r\n isPublic: jsonObject.isPublic,\r\n status,\r\n };\r\n}\r\n\r\nfunction statusFromJSON(jsonObject: any) {\r\n if (jsonObject.statusUpdateTime === undefined || typeof jsonObject.statusUpdateTime !== \"string\" ||\r\n jsonObject.status === undefined || (jsonObject.status !== null && typeof jsonObject.status !== \"string\")) {\r\n\r\n return undefined;\r\n }\r\n\r\n return {\r\n updateTime: new Date(jsonObject.statusUpdateTime),\r\n status: jsonObject.status ?? \"Valid\",\r\n };\r\n}\r\n\r\nfunction fileInfoFromJSON(jsonObject: any) {\r\n if (jsonObject.url === undefined || typeof jsonObject.url !== \"string\" ||\r\n jsonObject.expiresAt === undefined || typeof jsonObject.expiresAt !== \"string\" ||\r\n jsonObject.checksum === undefined || (typeof jsonObject.checksum !== \"string\" && jsonObject.checksum !== null)) {\r\n\r\n return undefined;\r\n }\r\n\r\n return {\r\n url: jsonObject.url,\r\n expires: new Date(jsonObject.expiresAt),\r\n checksum: jsonObject.checksum,\r\n };\r\n}\r\n"]}
|
|
@@ -30,7 +30,5 @@ export declare class RemoteExtensionProvider implements ExtensionProvider {
|
|
|
30
30
|
* Throws an error if the provided manifestUrl is not accessible.
|
|
31
31
|
*/
|
|
32
32
|
getManifest(): Promise<ExtensionManifest>;
|
|
33
|
-
/** Checks if url actually exists */
|
|
34
|
-
private _exists;
|
|
35
33
|
}
|
|
36
34
|
//# sourceMappingURL=RemoteExtensionProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"RemoteExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAItB;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,iBAAiB;IAInD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,4DAA4D;IAC5D,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAEJ,MAAM,EAAE,4BAA4B;IAIjE;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC;;;OAGG;IACU,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAWvD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RemoteExtensionProvider = void 0;
|
|
4
|
+
const Request_1 = require("../../request/Request");
|
|
4
5
|
const ExtensionLoadScript_1 = require("./ExtensionLoadScript");
|
|
5
6
|
/**
|
|
6
7
|
* Implements a "remote" extension.
|
|
@@ -18,10 +19,6 @@ class RemoteExtensionProvider {
|
|
|
18
19
|
* Throws an error if the provided jsUrl is not accessible.
|
|
19
20
|
*/
|
|
20
21
|
async execute() {
|
|
21
|
-
const doesUrlExist = await this._exists(this._props.jsUrl);
|
|
22
|
-
if (!doesUrlExist) {
|
|
23
|
-
throw new Error(`Extension at ${this._props.jsUrl} could not be found.`);
|
|
24
|
-
}
|
|
25
22
|
return (0, ExtensionLoadScript_1.loadScript)(this._props.jsUrl);
|
|
26
23
|
}
|
|
27
24
|
/**
|
|
@@ -29,24 +26,14 @@ class RemoteExtensionProvider {
|
|
|
29
26
|
* Throws an error if the provided manifestUrl is not accessible.
|
|
30
27
|
*/
|
|
31
28
|
async getManifest() {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let exists = false;
|
|
41
|
-
try {
|
|
42
|
-
const response = await fetch(url, { method: "HEAD" });
|
|
43
|
-
if (response.status === 200)
|
|
44
|
-
exists = true;
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
exists = false;
|
|
48
|
-
}
|
|
49
|
-
return exists;
|
|
29
|
+
const options = { method: "GET" };
|
|
30
|
+
const response = await (0, Request_1.request)(this._props.manifestUrl, options);
|
|
31
|
+
const data = response.body || (() => {
|
|
32
|
+
if (!response.text)
|
|
33
|
+
throw new Error("Manifest file was empty.");
|
|
34
|
+
return JSON.parse(response.text);
|
|
35
|
+
})();
|
|
36
|
+
return data;
|
|
50
37
|
}
|
|
51
38
|
}
|
|
52
39
|
exports.RemoteExtensionProvider = RemoteExtensionProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":";;;AAQA,+DAAmD;AAanD;;;;;GAKG;AACH,MAAa,uBAAuB;IAIlC,YAA6B,MAAoC;QAApC,WAAM,GAAN,MAAM,CAA8B;QAC/D,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO;QAClB,
|
|
1
|
+
{"version":3,"file":"RemoteExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":";;;AAQA,mDAAgE;AAChE,+DAAmD;AAanD;;;;;GAKG;AACH,MAAa,uBAAuB;IAIlC,YAA6B,MAAoC;QAApC,WAAM,GAAN,MAAM,CAA8B;QAC/D,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO;QAClB,OAAO,IAAA,gCAAU,EAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,WAAW;QACtB,MAAM,OAAO,GAAmB,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAClD,MAAM,QAAQ,GAAG,MAAM,IAAA,iBAAO,EAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACjE,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE;YAClC,IAAI,CAAC,QAAQ,CAAC,IAAI;gBAChB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC,CAAC,EAAE,CAAC;QACL,OAAO,IAAI,CAAC;IACd,CAAC;CAEF;AA/BD,0DA+BC","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\nimport type {\r\n ExtensionManifest,\r\n ExtensionProvider,\r\n} from \"../Extension\";\r\nimport { request, RequestOptions } from \"../../request/Request\";\r\nimport { loadScript } from \"./ExtensionLoadScript\";\r\n\r\n/**\r\n * Required props for a remote extension provider\r\n * @alpha\r\n */\r\nexport interface RemoteExtensionProviderProps {\r\n /** URL where the extension entry point can be loaded from */\r\n jsUrl: string;\r\n /** URL where the manifest (package.json) can be loaded from */\r\n manifestUrl: string;\r\n}\r\n\r\n/**\r\n * Implements a \"remote\" extension.\r\n * Remote extensions are hosted on an external server.\r\n * The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.\r\n * @alpha\r\n */\r\nexport class RemoteExtensionProvider implements ExtensionProvider {\r\n /** The name of the server where the extension is hosted. */\r\n public readonly hostname: string;\r\n\r\n constructor(private readonly _props: RemoteExtensionProviderProps) {\r\n this.hostname = new URL(this._props.jsUrl).hostname.replace(\"www\", \"\");\r\n }\r\n\r\n /**\r\n * Attempts to execute an extension.\r\n * Throws an error if the provided jsUrl is not accessible.\r\n */\r\n public async execute(): Promise<string> {\r\n return loadScript(this._props.jsUrl);\r\n }\r\n\r\n /**\r\n * Attempts to fetch an extension's manifest (package.json) file.\r\n * Throws an error if the provided manifestUrl is not accessible.\r\n */\r\n public async getManifest(): Promise<ExtensionManifest> {\r\n const options: RequestOptions = { method: \"GET\" };\r\n const response = await request(this._props.manifestUrl, options);\r\n const data = response.body || (() => {\r\n if (!response.text)\r\n throw new Error(\"Manifest file was empty.\");\r\n return JSON.parse(response.text);\r\n })();\r\n return data;\r\n }\r\n\r\n}\r\n"]}
|
|
@@ -7,10 +7,10 @@ import type { AccessToken } from "@itwin/core-bentley";
|
|
|
7
7
|
export interface ServiceExtensionProviderProps {
|
|
8
8
|
/** Name of the uploaded extension */
|
|
9
9
|
name: string;
|
|
10
|
-
/** Version number (
|
|
11
|
-
version
|
|
12
|
-
/** iTwin Id */
|
|
13
|
-
iTwinId
|
|
10
|
+
/** Version number (optional - if undefined, assumes the latest version) */
|
|
11
|
+
version?: string;
|
|
12
|
+
/** iTwin Id (optional - if undefined, assumes the extension is public) */
|
|
13
|
+
iTwinId?: string;
|
|
14
14
|
/** @internal */
|
|
15
15
|
getAccessToken?: () => Promise<AccessToken>;
|
|
16
16
|
}
|
|
@@ -31,8 +31,6 @@ export declare class ServiceExtensionProvider implements ExtensionProvider {
|
|
|
31
31
|
* Throws an error if the file cannot be found.
|
|
32
32
|
*/
|
|
33
33
|
execute(): Promise<any>;
|
|
34
|
-
/** Checks if url actually exists */
|
|
35
|
-
private _exists;
|
|
36
34
|
/** Fetches the extension from the ExtensionService.
|
|
37
35
|
*/
|
|
38
36
|
private _getExtensionFiles;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ServiceExtensionProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ServiceExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ServiceExtensionProvider.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,iBAAiB,EAAE,iBAAiB,EACrC,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB;IAChB,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;CAC7C;AAED;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,iBAAiB;IAEpD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,6BAA6B;IAElE;;OAEG;IACU,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAetD;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;IAQpC;OACG;YACW,kBAAkB;CAyBjC"}
|
|
@@ -7,6 +7,7 @@ exports.ServiceExtensionProvider = void 0;
|
|
|
7
7
|
*--------------------------------------------------------------------------------------------*/
|
|
8
8
|
const semver_1 = require("semver");
|
|
9
9
|
const IModelApp_1 = require("../../IModelApp");
|
|
10
|
+
const Request_1 = require("../../request/Request");
|
|
10
11
|
const ExtensionLoadScript_1 = require("./ExtensionLoadScript");
|
|
11
12
|
const ExtensionServiceClient_1 = require("./ExtensionServiceClient");
|
|
12
13
|
/**
|
|
@@ -26,10 +27,14 @@ class ServiceExtensionProvider {
|
|
|
26
27
|
const loadedExtensionProps = await this._getExtensionFiles(this._props);
|
|
27
28
|
if (!loadedExtensionProps)
|
|
28
29
|
throw new Error(`Error loading manifest for Extension ${this._props.name}.`);
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const options = { method: "GET" };
|
|
31
|
+
const response = await (0, Request_1.request)(loadedExtensionProps.manifest.url, options);
|
|
32
|
+
const data = response.body || (() => {
|
|
33
|
+
if (!response.text)
|
|
34
|
+
throw new Error("Manifest file was empty.");
|
|
35
|
+
return JSON.parse(response.text);
|
|
36
|
+
})();
|
|
37
|
+
return data;
|
|
33
38
|
}
|
|
34
39
|
/** Executes the javascript main file (the bundled index.js) of an extension from the Extension Service.
|
|
35
40
|
* Throws an error if the file cannot be found.
|
|
@@ -38,24 +43,8 @@ class ServiceExtensionProvider {
|
|
|
38
43
|
const loadedExtensionProps = await this._getExtensionFiles(this._props);
|
|
39
44
|
if (!loadedExtensionProps)
|
|
40
45
|
throw new Error(`Error executing Extension ${this._props.name}.`);
|
|
41
|
-
const doesUrlExist = await this._exists(loadedExtensionProps.main.url);
|
|
42
|
-
if (!doesUrlExist)
|
|
43
|
-
throw new Error(`Main javascript file at ${loadedExtensionProps.main.url} could not be found.`);
|
|
44
46
|
return (0, ExtensionLoadScript_1.loadScript)(loadedExtensionProps.main.url);
|
|
45
47
|
}
|
|
46
|
-
/** Checks if url actually exists */
|
|
47
|
-
async _exists(url) {
|
|
48
|
-
let exists = false;
|
|
49
|
-
try {
|
|
50
|
-
const response = await fetch(url, { method: "HEAD" });
|
|
51
|
-
if (response.status === 200)
|
|
52
|
-
exists = true;
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
exists = false;
|
|
56
|
-
}
|
|
57
|
-
return exists;
|
|
58
|
-
}
|
|
59
48
|
/** Fetches the extension from the ExtensionService.
|
|
60
49
|
*/
|
|
61
50
|
async _getExtensionFiles(props) {
|
|
@@ -66,9 +55,9 @@ class ServiceExtensionProvider {
|
|
|
66
55
|
return undefined;
|
|
67
56
|
let extensionProps;
|
|
68
57
|
if (props.version !== undefined)
|
|
69
|
-
extensionProps = await extensionClient.getExtensionMetadata(accessToken, props.
|
|
58
|
+
extensionProps = await extensionClient.getExtensionMetadata(accessToken, props.name, props.version, props.iTwinId);
|
|
70
59
|
else {
|
|
71
|
-
const propsArr = await extensionClient.getExtensions(accessToken, props.
|
|
60
|
+
const propsArr = await extensionClient.getExtensions(accessToken, props.name, props.iTwinId);
|
|
72
61
|
extensionProps = propsArr.sort((ext1, ext2) => (0, semver_1.rcompare)(ext1.version, ext2.version, true))[0];
|
|
73
62
|
}
|
|
74
63
|
if (extensionProps === undefined || extensionProps.files.length < 1)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/ServiceExtensionProvider.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,mCAAkC;AAElC,+CAA4C;AAC5C,+DAAmD;AACnD,qEAA8E;AAsB9E;;;;;GAKG;AACH,MAAa,wBAAwB;IAEnC,YAA6B,MAAqC;QAArC,WAAM,GAAN,MAAM,CAA+B;IAAI,CAAC;IAEvE;;OAEG;IACI,KAAK,CAAC,WAAW;QACtB,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxE,IAAI,CAAC,oBAAoB;YACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QAE/E,MAAM,
|
|
1
|
+
{"version":3,"file":"ServiceExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/ServiceExtensionProvider.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,mCAAkC;AAElC,+CAA4C;AAC5C,mDAAgE;AAChE,+DAAmD;AACnD,qEAA8E;AAsB9E;;;;;GAKG;AAC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,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF;AA5DD,4DA4DC","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\nimport { rcompare } from \"semver\";\r\n\r\nimport { IModelApp } from \"../../IModelApp\";\r\nimport { request, RequestOptions } from \"../../request/Request\";\r\nimport { loadScript } from \"./ExtensionLoadScript\";\r\nimport { ExtensionClient, ExtensionMetadata } from \"./ExtensionServiceClient\";\r\n\r\nimport type {\r\n ExtensionManifest, ExtensionProvider,\r\n} from \"../Extension\";\r\nimport type { AccessToken } from \"@itwin/core-bentley\";\r\n\r\n/**\r\n * Required props for an extension uploaded to Bentley's Extension Service\r\n * @alpha\r\n */\r\nexport interface ServiceExtensionProviderProps {\r\n /** Name of the uploaded extension */\r\n name: string;\r\n /** Version number (optional - if undefined, assumes the latest version) */\r\n version?: string;\r\n /** iTwin Id (optional - if undefined, assumes the extension is public) */\r\n iTwinId?: string;\r\n /** @internal */\r\n getAccessToken?: () => Promise<AccessToken>;\r\n}\r\n\r\n/**\r\n * Implements an Extension from the Extension Service via the ServiceExtensionProviderProps.\r\n * Service extensions are extensions hosted on Bentley's Extension Service.\r\n * The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.\r\n * @alpha\r\n */\r\nexport class ServiceExtensionProvider implements ExtensionProvider {\r\n\r\n constructor(private readonly _props: ServiceExtensionProviderProps) { }\r\n\r\n /** Returns the extension's manifest (package.json) from the ExtensionService.\r\n * Throws an error if the manifest cannot be found.\r\n */\r\n public async getManifest(): Promise<ExtensionManifest> {\r\n const loadedExtensionProps = await this._getExtensionFiles(this._props);\r\n if (!loadedExtensionProps)\r\n throw new Error(`Error loading manifest for Extension ${this._props.name}.`);\r\n\r\n const options: RequestOptions = { method: \"GET\" };\r\n const response = await request(loadedExtensionProps.manifest.url, options);\r\n const data = response.body || (() => {\r\n if (!response.text)\r\n throw new Error(\"Manifest file was empty.\");\r\n return JSON.parse(response.text);\r\n })();\r\n return data;\r\n }\r\n\r\n /** Executes the javascript main file (the bundled index.js) of an extension from the Extension Service.\r\n * Throws an error if the file cannot be found.\r\n */\r\n public async execute(): Promise<any> {\r\n const loadedExtensionProps = await this._getExtensionFiles(this._props);\r\n if (!loadedExtensionProps)\r\n throw new Error(`Error executing Extension ${this._props.name}.`);\r\n\r\n return loadScript(loadedExtensionProps.main.url);\r\n }\r\n\r\n /** Fetches the extension from the ExtensionService.\r\n */\r\n private async _getExtensionFiles(props: ServiceExtensionProviderProps) {\r\n const extensionClient = new ExtensionClient();\r\n\r\n const accessToken = await (props.getAccessToken?.() ?? IModelApp.authorizationClient?.getAccessToken());\r\n if (!accessToken)\r\n return undefined;\r\n\r\n let extensionProps: ExtensionMetadata | undefined;\r\n if (props.version !== undefined)\r\n extensionProps = await extensionClient.getExtensionMetadata(accessToken, props.name, props.version, props.iTwinId);\r\n else {\r\n const propsArr = await extensionClient.getExtensions(accessToken, props.name, props.iTwinId);\r\n extensionProps = propsArr.sort((ext1, ext2) => rcompare(ext1.version, ext2.version, true))[0];\r\n }\r\n\r\n if (extensionProps === undefined || extensionProps.files.length < 1)\r\n return undefined;\r\n\r\n const manifest = extensionProps.files.find((f) => f.url.indexOf(\"package.json?\") > -1);\r\n const main = extensionProps.files.find((f) => f.url.indexOf(\"index.js?\") > -1);\r\n if (!manifest || !main)\r\n return undefined;\r\n\r\n return { manifest, main };\r\n }\r\n}\r\n"]}
|
|
@@ -29,10 +29,13 @@ export declare class ExtensionAdmin {
|
|
|
29
29
|
*/
|
|
30
30
|
addExtensions(providers: ExtensionProvider[]): Promise<void[]>;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* Registers a hostname for an extension.
|
|
33
|
+
* Once a hostname has been registered, only remote extensions from registered hosts are permitted to be added.
|
|
34
|
+
* @param hostUrl (string) Accepts both URLs and hostnames (e.g., http://localhost:3000, yourdomain.com, https://www.yourdomain.com, etc.).
|
|
34
35
|
*/
|
|
35
36
|
registerHost(hostUrl: string): void;
|
|
37
|
+
/** Returns the hostname of an input string. Throws an error if input is not a valid hostname (or URL). */
|
|
38
|
+
private getHostName;
|
|
36
39
|
/** Loops over all enabled Extensions and triggers each one if the provided event is defined. */
|
|
37
40
|
private activateExtensionEvents;
|
|
38
41
|
/** Executes the extension. Catches and logs any errors (so that an extension will not crash the main application). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionAdmin.d.ts","sourceRoot":"","sources":["../../../src/extension/ExtensionAdmin.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,KAAK,EAAqB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA4BxE;;;GAGG;AACH,qBAAa,cAAc;IACzB,2GAA2G;IAC3G,OAAO,CAAC,WAAW,CAA0E;IAC7F,OAAO,CAAC,MAAM,CAAW;IAEzB;;OAEG;IACI,SAAS,sBAEd;;IAMF;;;;;OAKG;IACU,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBrE;;;;OAIG;IACU,aAAa,CAAC,SAAS,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAM3E
|
|
1
|
+
{"version":3,"file":"ExtensionAdmin.d.ts","sourceRoot":"","sources":["../../../src/extension/ExtensionAdmin.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,KAAK,EAAqB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA4BxE;;;GAGG;AACH,qBAAa,cAAc;IACzB,2GAA2G;IAC3G,OAAO,CAAC,WAAW,CAA0E;IAC7F,OAAO,CAAC,MAAM,CAAW;IAEzB;;OAEG;IACI,SAAS,sBAEd;;IAMF;;;;;OAKG;IACU,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBrE;;;;OAIG;IACU,aAAa,CAAC,SAAS,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAM3E;;;;OAIG;IACI,YAAY,CAAC,OAAO,EAAE,MAAM;IAOnC,0GAA0G;IAC1G,OAAO,CAAC,WAAW;IAgBnB,gGAAgG;YAClF,uBAAuB;IAWrC,sHAAsH;YACxG,QAAQ;CAOvB"}
|
|
@@ -47,7 +47,7 @@ export class ExtensionAdmin {
|
|
|
47
47
|
provider.execute(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
|
-
throw new Error(`Failed to get manifest
|
|
50
|
+
throw new Error(`Failed to get extension manifest ${provider.hostname ? `at ${provider.hostname}` : ""}: ${e}`);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -59,13 +59,31 @@ export class ExtensionAdmin {
|
|
|
59
59
|
return Promise.all(providers.map(async (provider) => this.addExtension(provider)));
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
62
|
+
* Registers a hostname for an extension.
|
|
63
|
+
* Once a hostname has been registered, only remote extensions from registered hosts are permitted to be added.
|
|
64
|
+
* @param hostUrl (string) Accepts both URLs and hostnames (e.g., http://localhost:3000, yourdomain.com, https://www.yourdomain.com, etc.).
|
|
64
65
|
*/
|
|
65
66
|
registerHost(hostUrl) {
|
|
66
|
-
const
|
|
67
|
-
if (this._hosts.indexOf(
|
|
68
|
-
this._hosts.push(
|
|
67
|
+
const hostname = this.getHostName(hostUrl);
|
|
68
|
+
if (this._hosts.indexOf(hostname) < 0) {
|
|
69
|
+
this._hosts.push(hostname);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Returns the hostname of an input string. Throws an error if input is not a valid hostname (or URL). */
|
|
73
|
+
getHostName(inputUrl) {
|
|
74
|
+
// inputs without a protocol (e.g., http://) will throw an error in URL constructor
|
|
75
|
+
const inputWithProtocol = /(http|https):\/\//.test(inputUrl) ?
|
|
76
|
+
inputUrl :
|
|
77
|
+
`https://${inputUrl}`;
|
|
78
|
+
try {
|
|
79
|
+
const hostname = new URL(inputWithProtocol).hostname.replace("www.", "");
|
|
80
|
+
return hostname;
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
if (e instanceof TypeError) {
|
|
84
|
+
throw new Error("Argument hostUrl should be a valid URL or hostname (i.e. http://localhost:3000, yourdomain.com, etc.).");
|
|
85
|
+
}
|
|
86
|
+
throw e;
|
|
69
87
|
}
|
|
70
88
|
}
|
|
71
89
|
/** Loops over all enabled Extensions and triggers each one if the provided event is defined. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionAdmin.js","sourceRoot":"","sources":["../../../src/extension/ExtensionAdmin.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AA6BnE;;;GAGG;AACH,MAAM,OAAO,cAAc;IAYzB;QAXA,2GAA2G;QACnG,gBAAW,GAAoC,IAAI,GAAG,EAA8B,CAAC;QAG7F;;WAEG;QACI,cAAS,GAAG,KAAK,IAAI,EAAE;YAC5B,MAAM,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC,CAAC;QAGA,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CAAC,QAA2B;QACnD,IAAI,QAAQ,CAAC,QAAQ,EAAE;YACrB,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;YACnC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,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CAAC,CAAC,CAAC;YAC5D,QAAQ,CAAC,CAAC;YACV,WAAW,QAAQ,EAAE,CAAC;QACxB,IAAI;YACF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACzE,OAAO,QAAQ,CAAC;SACjB;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,YAAY,SAAS,EAAE;gBAC1B,MAAM,IAAI,KAAK,CAAC,wGAAwG,CAAC,CAAC;aAC3H;YACD,MAAM,CAAC,CAAC;SACT;IACH,CAAC;IAED,gGAAgG;IACxF,KAAK,CAAC,uBAAuB,CAAC,KAAa;QACjD,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE;YACjD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB;gBAAE,SAAS;YACnD,KAAK,MAAM,eAAe,IAAI,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE;gBACjE,IAAI,eAAe,KAAK,KAAK,EAAE;oBAC7B,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,8DAA8D;iBACzF;aACF;SACF;IACH,CAAC;IAED,sHAAsH;IAC9G,KAAK,CAAC,QAAQ,CAAC,SAA6B;QAClD,IAAI;YACF,MAAM,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;SACpC;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,QAAQ,CAAC,sBAAsB,CAAC,UAAU,EAAE,6BAA6B,SAAS,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;SAClH;IACH,CAAC;CACF","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 Extensions\r\n */\r\n\r\nimport { Logger } from \"@itwin/core-bentley\";\r\n\r\nimport { FrontendLoggerCategory } from \"../FrontendLoggerCategory\";\r\nimport type { ExtensionManifest, ExtensionProvider } from \"./Extension\";\r\n\r\n/** The Extensions loading system has the following goals:\r\n * 1. Only fetch what is needed when it is required\r\n * 1. Load a manifest file\r\n * 2. Load the the main module when necessary (usually at an activation event)\r\n * 2. Download the extension's files\r\n *\r\n * 3 ways to load an Extension into the system:\r\n *\r\n * 1. Load both the Extension Manifest and import the main module of the extension from a local file/package.\r\n * 2. A minimum set of properties to get the manifest and javascript from a remote server.\r\n * 3. A minimum set of properties to get the manifest and javascript from Bentley's Extension Service.\r\n *\r\n * An Extension must be added to ExtensionAdmin before it can be executed during activation events.\r\n */\r\n\r\n/**\r\n * A \"ready to use\" Extension (contains a manifest object and an extension provider to help execute).\r\n * Will be used as the type for in-memory extensions in the ExtensionAdmin\r\n */\r\ninterface InstalledExtension {\r\n /** An extension provider that has been added to ExtensionAdmin */\r\n provider: ExtensionProvider;\r\n /** The manifest (package.json) of the extension */\r\n manifest: ExtensionManifest;\r\n}\r\n\r\n/** The Extension Admin controls the list of currently loaded Extensions.\r\n *\r\n * @alpha\r\n */\r\nexport class ExtensionAdmin {\r\n /** Defines the set of extensions that are currently known and can be invoked during activation events. */\r\n private _extensions: Map<string, InstalledExtension> = new Map<string, InstalledExtension>();\r\n private _hosts: string[];\r\n\r\n /** Fired when an Extension has been added or removed.\r\n * @internal\r\n */\r\n public onStartup = async () => {\r\n await this.activateExtensionEvents(\"onStartup\");\r\n };\r\n\r\n public constructor() {\r\n this._hosts = [];\r\n }\r\n\r\n /**\r\n * Adds an extension.\r\n * The manifest will be fetched and the extension will be activated on an activation event.\r\n * @param provider\r\n * @alpha\r\n */\r\n public async addExtension(provider: ExtensionProvider): Promise<void> {\r\n if (provider.hostname) {\r\n const hostName = provider.hostname;\r\n if (this._hosts.length > 0 && this._hosts.indexOf(hostName) < 0) {\r\n throw new Error(`Error loading extension: ${hostName} was not registered.`);\r\n }\r\n }\r\n try {\r\n const manifest = await provider.getManifest();\r\n this._extensions.set(manifest.name, {\r\n manifest,\r\n provider,\r\n });\r\n // TODO - temporary fix to execute the missed startup event\r\n if (manifest.activationEvents.includes(\"onStartup\"))\r\n provider.execute(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n } catch (e) {\r\n throw new Error(`Failed to get extension manifest ${provider.hostname ? `at ${provider.hostname}` : \"\"}: ${e}`);\r\n }\r\n }\r\n\r\n /**\r\n * Adds a list of extensions\r\n * @param providers\r\n * @alpha\r\n */\r\n public async addExtensions(providers: ExtensionProvider[]): Promise<void[]> {\r\n return Promise.all(\r\n providers.map(async (provider) => this.addExtension(provider))\r\n );\r\n }\r\n\r\n /**\r\n * Registers a hostname for an extension.\r\n * Once a hostname has been registered, only remote extensions from registered hosts are permitted to be added.\r\n * @param hostUrl (string) Accepts both URLs and hostnames (e.g., http://localhost:3000, yourdomain.com, https://www.yourdomain.com, etc.).\r\n */\r\n public registerHost(hostUrl: string) {\r\n const hostname = this.getHostName(hostUrl);\r\n if (this._hosts.indexOf(hostname) < 0) {\r\n this._hosts.push(hostname);\r\n }\r\n }\r\n\r\n /** Returns the hostname of an input string. Throws an error if input is not a valid hostname (or URL). */\r\n private getHostName(inputUrl: string): string {\r\n // inputs without a protocol (e.g., http://) will throw an error in URL constructor\r\n const inputWithProtocol = /(http|https):\\/\\//.test(inputUrl) ?\r\n inputUrl :\r\n `https://${inputUrl}`;\r\n try {\r\n const hostname = new URL(inputWithProtocol).hostname.replace(\"www.\", \"\");\r\n return hostname;\r\n } catch (e) {\r\n if (e instanceof TypeError) {\r\n throw new Error(\"Argument hostUrl should be a valid URL or hostname (i.e. http://localhost:3000, yourdomain.com, etc.).\");\r\n }\r\n throw e;\r\n }\r\n }\r\n\r\n /** Loops over all enabled Extensions and triggers each one if the provided event is defined. */\r\n private async activateExtensionEvents(event: string) {\r\n for (const extension of this._extensions.values()) {\r\n if (!extension.manifest.activationEvents) continue;\r\n for (const activationEvent of extension.manifest.activationEvents) {\r\n if (activationEvent === event) {\r\n this._execute(extension); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n }\r\n }\r\n\r\n /** Executes the extension. Catches and logs any errors (so that an extension will not crash the main application). */\r\n private async _execute(extension: InstalledExtension) {\r\n try {\r\n await extension.provider.execute();\r\n } catch (e) {\r\n Logger.logError(FrontendLoggerCategory.Extensions, `Error executing extension ${extension.manifest.name}: ${e}`);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -34,19 +34,21 @@ export declare class ExtensionClient {
|
|
|
34
34
|
private get _endpoint();
|
|
35
35
|
private parseExtensionMetadataArray;
|
|
36
36
|
/**
|
|
37
|
-
* Gets information on extensions. If extensionName is undefined, will return all extensions in the
|
|
38
|
-
* If
|
|
39
|
-
*
|
|
37
|
+
* Gets information on extensions. If extensionName is undefined, will return all extensions in the iTwin.
|
|
38
|
+
* If extensionName is defined, will return all versions of that extension.
|
|
39
|
+
* If iTwinId is undefined, will default to the public extensions.
|
|
40
40
|
* @param extensionName Extension name (optional)
|
|
41
|
+
* @param iTwinId iTwin Id (optional)
|
|
41
42
|
*/
|
|
42
|
-
getExtensions(accessToken: AccessToken,
|
|
43
|
+
getExtensions(accessToken: AccessToken, extensionName?: string, iTwinId?: string): Promise<ExtensionMetadata[]>;
|
|
43
44
|
/**
|
|
44
45
|
* Gets information about an extension's specific version
|
|
45
|
-
*
|
|
46
|
+
* If iTwinId is undefined, will assume the extension was published publicly.
|
|
46
47
|
* @param extensionName Extension name
|
|
47
48
|
* @param version Extension version
|
|
49
|
+
* @param iTwinId iTwin Id (optional)
|
|
48
50
|
*/
|
|
49
|
-
getExtensionMetadata(accessToken: AccessToken,
|
|
51
|
+
getExtensionMetadata(accessToken: AccessToken, extensionName: string, version: string, iTwinId?: string): Promise<ExtensionMetadata | undefined>;
|
|
50
52
|
}
|
|
51
53
|
export {};
|
|
52
54
|
//# sourceMappingURL=ExtensionServiceClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionServiceClient.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionServiceClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"ExtensionServiceClient.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionServiceClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAQ,MAAM,qBAAqB,CAAC;AAIxD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,qBAAqB;IAC7B,UAAU,EAAE,IAAI,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,QAAQ;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,IAAI,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;;IAKlC,OAAO,KAAK,SAAS,GAWpB;IAED,OAAO,CAAC,2BAA2B;IAcnC;;;;;;OAMG;IACU,aAAa,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,SAAa,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAahI;;;;;;OAMG;IACU,oBAAoB,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,SAAa,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;CAelK"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { Guid } from "@itwin/core-bentley";
|
|
1
6
|
import { request } from "../../request/Request";
|
|
2
7
|
/**
|
|
3
8
|
* Client for querying, publishing and deleting iModel.js Extensions.
|
|
@@ -32,12 +37,13 @@ export class ExtensionClient {
|
|
|
32
37
|
return ret;
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
|
-
* Gets information on extensions. If extensionName is undefined, will return all extensions in the
|
|
36
|
-
* If
|
|
37
|
-
*
|
|
40
|
+
* Gets information on extensions. If extensionName is undefined, will return all extensions in the iTwin.
|
|
41
|
+
* If extensionName is defined, will return all versions of that extension.
|
|
42
|
+
* If iTwinId is undefined, will default to the public extensions.
|
|
38
43
|
* @param extensionName Extension name (optional)
|
|
44
|
+
* @param iTwinId iTwin Id (optional)
|
|
39
45
|
*/
|
|
40
|
-
async getExtensions(accessToken,
|
|
46
|
+
async getExtensions(accessToken, extensionName, iTwinId = Guid.empty) {
|
|
41
47
|
const options = { method: "GET" };
|
|
42
48
|
options.headers = { authorization: accessToken };
|
|
43
49
|
const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName !== null && extensionName !== void 0 ? extensionName : ""}`, options);
|
|
@@ -49,11 +55,12 @@ export class ExtensionClient {
|
|
|
49
55
|
}
|
|
50
56
|
/**
|
|
51
57
|
* Gets information about an extension's specific version
|
|
52
|
-
*
|
|
58
|
+
* If iTwinId is undefined, will assume the extension was published publicly.
|
|
53
59
|
* @param extensionName Extension name
|
|
54
60
|
* @param version Extension version
|
|
61
|
+
* @param iTwinId iTwin Id (optional)
|
|
55
62
|
*/
|
|
56
|
-
async getExtensionMetadata(accessToken,
|
|
63
|
+
async getExtensionMetadata(accessToken, extensionName, version, iTwinId = Guid.empty) {
|
|
57
64
|
const options = { method: "GET" };
|
|
58
65
|
options.headers = { authorization: accessToken };
|
|
59
66
|
const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName}/${version}`, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionServiceClient.js","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionServiceClient.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAkB,MAAM,uBAAuB,CAAC;AA2BhE;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;IAE1B;QACE,IAAI,CAAC,QAAQ,GAAG,iDAAiD,CAAC;IACpE,CAAC;IAED,IAAY,SAAS;QACnB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,MAAM;YACR,OAAO,CAAC,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;QAExD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YACjC,OAAO,CAAC,QAAQ,IAAI,GAAG,CAAC;QAE1B,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC;QAC5B,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC5B,CAAC;IAEO,2BAA2B,CAAC,IAAS;QAC3C,IAAI,CAAC,CAAC,IAAI,YAAY,KAAK,CAAC;YAC1B,OAAO,EAAE,CAAC;QAEZ,MAAM,GAAG,GAAwB,EAAE,CAAC;QACpC,IAAI,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;YAC7B,MAAM,SAAS,GAAG,yBAAyB,CAAC,aAAa,CAAC,CAAC;YAC3D,IAAI,SAAS,KAAK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UAAU,CAAC,GAAG,KAAK,SAAS,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ;QACpE,UAAU,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,UAAU,CAAC,SAAS,KAAK,QAAQ;QAC9E,UAAU,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,OAAO,UAAU,CAAC,QAAQ,KAAK,QAAQ,IAAI,UAAU,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE;QAEhH,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,GAAG,EAAE,UAAU,CAAC,GAAG;QACnB,OAAO,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QACvC,QAAQ,EAAE,UAAU,CAAC,QAAQ;KAC9B,CAAC;AACJ,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\nimport { AccessToken } from \"@itwin/core-bentley\";\r\n\r\nimport { request, RequestOptions } from \"../../request/Request\";\r\n\r\n/** Structure of extensions from the ExtensionService\r\n * @internal\r\n */\r\nexport interface ExtensionMetadata {\r\n contextId: string;\r\n extensionName: string;\r\n version: string;\r\n files: FileInfo[];\r\n uploadedBy: string;\r\n timestamp: Date;\r\n status: ExtensionUploadStatus;\r\n isPublic: boolean;\r\n}\r\n\r\ninterface ExtensionUploadStatus {\r\n updateTime: Date;\r\n status: string;\r\n}\r\n\r\ninterface FileInfo {\r\n url: string;\r\n expires: Date;\r\n checksum: string;\r\n}\r\n\r\n/**\r\n * Client for querying, publishing and deleting iModel.js Extensions.\r\n *\r\n * The `imodel-extension-service-api` OIDC scope is required for all operations and the `imodel-extension-service:modify` is\r\n * required for modification operations (modify, publish, and deleting).\r\n * @alpha\r\n */\r\nexport class ExtensionClient {\r\n private readonly _baseUrl: string;\r\n public constructor() {\r\n this._baseUrl = \"https://api.bentley.com/iModelExtensionService/\";\r\n }\r\n\r\n private get _endpoint(): string {\r\n const prefix = process.env.IMJS_URL_PREFIX;\r\n const baseUrl = new URL(this._baseUrl);\r\n if (prefix)\r\n baseUrl.hostname = prefix + new URL(baseUrl).hostname;\r\n\r\n if (!baseUrl.pathname.endsWith(\"/\"))\r\n baseUrl.pathname += \"/\";\r\n\r\n baseUrl.pathname += \"v1.0/\";\r\n return baseUrl.toString();\r\n }\r\n\r\n private parseExtensionMetadataArray(json: any): ExtensionMetadata[] {\r\n if (!(json instanceof Array))\r\n return [];\r\n\r\n const ret: ExtensionMetadata[] = [];\r\n json.forEach((extensionJson) => {\r\n const extension = extensionMetadataFromJSON(extensionJson);\r\n if (extension !== undefined)\r\n ret.push(extension);\r\n });\r\n\r\n return ret;\r\n }\r\n\r\n /**\r\n * Gets information on extensions. If extensionName is undefined, will return all extensions in the context.\r\n * If it's defined, will return all versions of that extension.\r\n * @param iTwinId Context Id\r\n * @param extensionName Extension name (optional)\r\n */\r\n public async getExtensions(accessToken: AccessToken, iTwinId: string, extensionName?: string): Promise<ExtensionMetadata[]> {\r\n const options: RequestOptions = { method: \"GET\" };\r\n options.headers = { authorization: accessToken };\r\n const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName ?? \"\"}`, options);\r\n if (response.status !== 200)\r\n throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);\r\n\r\n if (!(response.body instanceof Array) || response.body.length < 1)\r\n return [];\r\n\r\n return this.parseExtensionMetadataArray(response.body);\r\n }\r\n\r\n /**\r\n * Gets information about an extension's specific version\r\n * @param iTwinId iTwin Id\r\n * @param extensionName Extension name\r\n * @param version Extension version\r\n */\r\n public async getExtensionMetadata(accessToken: AccessToken, iTwinId: string, extensionName: string, version: string): Promise<ExtensionMetadata | undefined> {\r\n\r\n const options: RequestOptions = { method: \"GET\" };\r\n options.headers = { authorization: accessToken };\r\n const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName}/${version}`, options);\r\n if (response.status !== 200)\r\n throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);\r\n\r\n if (!(response.body instanceof Array) || response.body.length < 1)\r\n return undefined;\r\n if (response.body.length > 1)\r\n throw new Error(\"Server returned too many extensions\");\r\n\r\n return extensionMetadataFromJSON(response.body[0]);\r\n }\r\n}\r\n\r\n/**\r\n * Validates JSON and returns ExtensionMetadata\r\n */\r\nfunction extensionMetadataFromJSON(jsonObject: any): ExtensionMetadata | undefined {\r\n if (jsonObject.contextId === undefined || typeof jsonObject.contextId !== \"string\" ||\r\n jsonObject.extensionName === undefined || typeof jsonObject.extensionName !== \"string\" ||\r\n jsonObject.version === undefined || typeof jsonObject.version !== \"string\" ||\r\n jsonObject.files === undefined || !(jsonObject.files instanceof Array) ||\r\n jsonObject.uploadedBy === undefined || typeof jsonObject.uploadedBy !== \"string\" ||\r\n jsonObject.timestamp === undefined || typeof jsonObject.timestamp !== \"string\" ||\r\n jsonObject.isPublic === undefined || typeof jsonObject.isPublic !== \"boolean\" ||\r\n jsonObject.extensionStatus === undefined) {\r\n\r\n return undefined;\r\n }\r\n\r\n const status = statusFromJSON(jsonObject.extensionStatus);\r\n if (status === undefined)\r\n return undefined;\r\n\r\n const files = new Array(jsonObject.files.length);\r\n for (let i = 0; i < jsonObject.files.length; i++) {\r\n const parsed = fileInfoFromJSON(jsonObject.files[i]);\r\n if (parsed === undefined)\r\n return undefined;\r\n files[i] = parsed;\r\n }\r\n\r\n return {\r\n contextId: jsonObject.contextId,\r\n extensionName: jsonObject.extensionName,\r\n version: jsonObject.version,\r\n files,\r\n uploadedBy: jsonObject.uploadedBy,\r\n timestamp: new Date(jsonObject.timestamp),\r\n isPublic: jsonObject.isPublic,\r\n status,\r\n };\r\n}\r\n\r\nfunction statusFromJSON(jsonObject: any) {\r\n if (jsonObject.statusUpdateTime === undefined || typeof jsonObject.statusUpdateTime !== \"string\" ||\r\n jsonObject.status === undefined || (jsonObject.status !== null && typeof jsonObject.status !== \"string\")) {\r\n\r\n return undefined;\r\n }\r\n\r\n return {\r\n updateTime: new Date(jsonObject.statusUpdateTime),\r\n status: jsonObject.status ?? \"Valid\",\r\n };\r\n}\r\n\r\nfunction fileInfoFromJSON(jsonObject: any) {\r\n if (jsonObject.url === undefined || typeof jsonObject.url !== \"string\" ||\r\n jsonObject.expiresAt === undefined || typeof jsonObject.expiresAt !== \"string\" ||\r\n jsonObject.checksum === undefined || (typeof jsonObject.checksum !== \"string\" && jsonObject.checksum !== null)) {\r\n\r\n return undefined;\r\n }\r\n\r\n return {\r\n url: jsonObject.url,\r\n expires: new Date(jsonObject.expiresAt),\r\n checksum: jsonObject.checksum,\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ExtensionServiceClient.js","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionServiceClient.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAe,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,OAAO,EAAkB,MAAM,uBAAuB,CAAC;AA2BhE;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;IAE1B;QACE,IAAI,CAAC,QAAQ,GAAG,iDAAiD,CAAC;IACpE,CAAC;IAED,IAAY,SAAS;QACnB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,MAAM;YACR,OAAO,CAAC,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;QAExD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YACjC,OAAO,CAAC,QAAQ,IAAI,GAAG,CAAC;QAE1B,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC;QAC5B,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC5B,CAAC;IAE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AAI,CAAC,UAAU,CAAC,MAAM,KAAK,IAAI,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ,CAAC,EAAE;QAE1G,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,UAAU,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC;QACjD,MAAM,EAAE,MAAA,UAAU,CAAC,MAAM,mCAAI,OAAO;KACrC,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,UAAe;IACvC,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ;QACpE,UAAU,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,UAAU,CAAC,SAAS,KAAK,QAAQ;QAC9E,UAAU,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,OAAO,UAAU,CAAC,QAAQ,KAAK,QAAQ,IAAI,UAAU,CAAC,QAAQ,KAAK,IAAI,CAAC,EAAE;QAEhH,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,GAAG,EAAE,UAAU,CAAC,GAAG;QACnB,OAAO,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QACvC,QAAQ,EAAE,UAAU,CAAC,QAAQ;KAC9B,CAAC;AACJ,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\nimport { AccessToken, Guid } from \"@itwin/core-bentley\";\r\n\r\nimport { request, RequestOptions } from \"../../request/Request\";\r\n\r\n/** Structure of extensions from the ExtensionService\r\n * @internal\r\n */\r\nexport interface ExtensionMetadata {\r\n contextId: string;\r\n extensionName: string;\r\n version: string;\r\n files: FileInfo[];\r\n uploadedBy: string;\r\n timestamp: Date;\r\n status: ExtensionUploadStatus;\r\n isPublic: boolean;\r\n}\r\n\r\ninterface ExtensionUploadStatus {\r\n updateTime: Date;\r\n status: string;\r\n}\r\n\r\ninterface FileInfo {\r\n url: string;\r\n expires: Date;\r\n checksum: string;\r\n}\r\n\r\n/**\r\n * Client for querying, publishing and deleting iModel.js Extensions.\r\n *\r\n * The `imodel-extension-service-api` OIDC scope is required for all operations and the `imodel-extension-service:modify` is\r\n * required for modification operations (modify, publish, and deleting).\r\n * @alpha\r\n */\r\nexport class ExtensionClient {\r\n private readonly _baseUrl: string;\r\n public constructor() {\r\n this._baseUrl = \"https://api.bentley.com/iModelExtensionService/\";\r\n }\r\n\r\n private get _endpoint(): string {\r\n const prefix = process.env.IMJS_URL_PREFIX;\r\n const baseUrl = new URL(this._baseUrl);\r\n if (prefix)\r\n baseUrl.hostname = prefix + new URL(baseUrl).hostname;\r\n\r\n if (!baseUrl.pathname.endsWith(\"/\"))\r\n baseUrl.pathname += \"/\";\r\n\r\n baseUrl.pathname += \"v1.0/\";\r\n return baseUrl.toString();\r\n }\r\n\r\n private parseExtensionMetadataArray(json: any): ExtensionMetadata[] {\r\n if (!(json instanceof Array))\r\n return [];\r\n\r\n const ret: ExtensionMetadata[] = [];\r\n json.forEach((extensionJson) => {\r\n const extension = extensionMetadataFromJSON(extensionJson);\r\n if (extension !== undefined)\r\n ret.push(extension);\r\n });\r\n\r\n return ret;\r\n }\r\n\r\n /**\r\n * Gets information on extensions. If extensionName is undefined, will return all extensions in the iTwin.\r\n * If extensionName is defined, will return all versions of that extension.\r\n * If iTwinId is undefined, will default to the public extensions.\r\n * @param extensionName Extension name (optional)\r\n * @param iTwinId iTwin Id (optional)\r\n */\r\n public async getExtensions(accessToken: AccessToken, extensionName?: string, iTwinId = Guid.empty): Promise<ExtensionMetadata[]> {\r\n const options: RequestOptions = { method: \"GET\" };\r\n options.headers = { authorization: accessToken };\r\n const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName ?? \"\"}`, options);\r\n if (response.status !== 200)\r\n throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);\r\n\r\n if (!(response.body instanceof Array) || response.body.length < 1)\r\n return [];\r\n\r\n return this.parseExtensionMetadataArray(response.body);\r\n }\r\n\r\n /**\r\n * Gets information about an extension's specific version\r\n * If iTwinId is undefined, will assume the extension was published publicly.\r\n * @param extensionName Extension name\r\n * @param version Extension version\r\n * @param iTwinId iTwin Id (optional)\r\n */\r\n public async getExtensionMetadata(accessToken: AccessToken, extensionName: string, version: string, iTwinId = Guid.empty): Promise<ExtensionMetadata | undefined> {\r\n\r\n const options: RequestOptions = { method: \"GET\" };\r\n options.headers = { authorization: accessToken };\r\n const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName}/${version}`, options);\r\n if (response.status !== 200)\r\n throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);\r\n\r\n if (!(response.body instanceof Array) || response.body.length < 1)\r\n return undefined;\r\n if (response.body.length > 1)\r\n throw new Error(\"Server returned too many extensions\");\r\n\r\n return extensionMetadataFromJSON(response.body[0]);\r\n }\r\n}\r\n\r\n/**\r\n * Validates JSON and returns ExtensionMetadata\r\n */\r\nfunction extensionMetadataFromJSON(jsonObject: any): ExtensionMetadata | undefined {\r\n if (jsonObject.contextId === undefined || typeof jsonObject.contextId !== \"string\" ||\r\n jsonObject.extensionName === undefined || typeof jsonObject.extensionName !== \"string\" ||\r\n jsonObject.version === undefined || typeof jsonObject.version !== \"string\" ||\r\n jsonObject.files === undefined || !(jsonObject.files instanceof Array) ||\r\n jsonObject.uploadedBy === undefined || typeof jsonObject.uploadedBy !== \"string\" ||\r\n jsonObject.timestamp === undefined || typeof jsonObject.timestamp !== \"string\" ||\r\n jsonObject.isPublic === undefined || typeof jsonObject.isPublic !== \"boolean\" ||\r\n jsonObject.extensionStatus === undefined) {\r\n\r\n return undefined;\r\n }\r\n\r\n const status = statusFromJSON(jsonObject.extensionStatus);\r\n if (status === undefined)\r\n return undefined;\r\n\r\n const files = new Array(jsonObject.files.length);\r\n for (let i = 0; i < jsonObject.files.length; i++) {\r\n const parsed = fileInfoFromJSON(jsonObject.files[i]);\r\n if (parsed === undefined)\r\n return undefined;\r\n files[i] = parsed;\r\n }\r\n\r\n return {\r\n contextId: jsonObject.contextId,\r\n extensionName: jsonObject.extensionName,\r\n version: jsonObject.version,\r\n files,\r\n uploadedBy: jsonObject.uploadedBy,\r\n timestamp: new Date(jsonObject.timestamp),\r\n isPublic: jsonObject.isPublic,\r\n status,\r\n };\r\n}\r\n\r\nfunction statusFromJSON(jsonObject: any) {\r\n if (jsonObject.statusUpdateTime === undefined || typeof jsonObject.statusUpdateTime !== \"string\" ||\r\n jsonObject.status === undefined || (jsonObject.status !== null && typeof jsonObject.status !== \"string\")) {\r\n\r\n return undefined;\r\n }\r\n\r\n return {\r\n updateTime: new Date(jsonObject.statusUpdateTime),\r\n status: jsonObject.status ?? \"Valid\",\r\n };\r\n}\r\n\r\nfunction fileInfoFromJSON(jsonObject: any) {\r\n if (jsonObject.url === undefined || typeof jsonObject.url !== \"string\" ||\r\n jsonObject.expiresAt === undefined || typeof jsonObject.expiresAt !== \"string\" ||\r\n jsonObject.checksum === undefined || (typeof jsonObject.checksum !== \"string\" && jsonObject.checksum !== null)) {\r\n\r\n return undefined;\r\n }\r\n\r\n return {\r\n url: jsonObject.url,\r\n expires: new Date(jsonObject.expiresAt),\r\n checksum: jsonObject.checksum,\r\n };\r\n}\r\n"]}
|
|
@@ -30,7 +30,5 @@ export declare class RemoteExtensionProvider implements ExtensionProvider {
|
|
|
30
30
|
* Throws an error if the provided manifestUrl is not accessible.
|
|
31
31
|
*/
|
|
32
32
|
getManifest(): Promise<ExtensionManifest>;
|
|
33
|
-
/** Checks if url actually exists */
|
|
34
|
-
private _exists;
|
|
35
33
|
}
|
|
36
34
|
//# sourceMappingURL=RemoteExtensionProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"RemoteExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AAItB;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,iBAAiB;IAInD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,4DAA4D;IAC5D,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAEJ,MAAM,EAAE,4BAA4B;IAIjE;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC;;;OAGG;IACU,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAWvD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { request } from "../../request/Request";
|
|
1
2
|
import { loadScript } from "./ExtensionLoadScript";
|
|
2
3
|
/**
|
|
3
4
|
* Implements a "remote" extension.
|
|
@@ -15,10 +16,6 @@ export class RemoteExtensionProvider {
|
|
|
15
16
|
* Throws an error if the provided jsUrl is not accessible.
|
|
16
17
|
*/
|
|
17
18
|
async execute() {
|
|
18
|
-
const doesUrlExist = await this._exists(this._props.jsUrl);
|
|
19
|
-
if (!doesUrlExist) {
|
|
20
|
-
throw new Error(`Extension at ${this._props.jsUrl} could not be found.`);
|
|
21
|
-
}
|
|
22
19
|
return loadScript(this._props.jsUrl);
|
|
23
20
|
}
|
|
24
21
|
/**
|
|
@@ -26,24 +23,14 @@ export class RemoteExtensionProvider {
|
|
|
26
23
|
* Throws an error if the provided manifestUrl is not accessible.
|
|
27
24
|
*/
|
|
28
25
|
async getManifest() {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
let exists = false;
|
|
38
|
-
try {
|
|
39
|
-
const response = await fetch(url, { method: "HEAD" });
|
|
40
|
-
if (response.status === 200)
|
|
41
|
-
exists = true;
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
exists = false;
|
|
45
|
-
}
|
|
46
|
-
return exists;
|
|
26
|
+
const options = { method: "GET" };
|
|
27
|
+
const response = await request(this._props.manifestUrl, options);
|
|
28
|
+
const data = response.body || (() => {
|
|
29
|
+
if (!response.text)
|
|
30
|
+
throw new Error("Manifest file was empty.");
|
|
31
|
+
return JSON.parse(response.text);
|
|
32
|
+
})();
|
|
33
|
+
return data;
|
|
47
34
|
}
|
|
48
35
|
}
|
|
49
36
|
//# sourceMappingURL=RemoteExtensionProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAanD;;;;;GAKG;AACH,MAAM,OAAO,uBAAuB;IAIlC,YAA6B,MAAoC;QAApC,WAAM,GAAN,MAAM,CAA8B;QAC/D,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO;QAClB,
|
|
1
|
+
{"version":3,"file":"RemoteExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/RemoteExtensionProvider.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAkB,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAanD;;;;;GAKG;AACH,MAAM,OAAO,uBAAuB;IAIlC,YAA6B,MAAoC;QAApC,WAAM,GAAN,MAAM,CAA8B;QAC/D,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO;QAClB,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,WAAW;QACtB,MAAM,OAAO,GAAmB,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAClD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACjE,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE;YAClC,IAAI,CAAC,QAAQ,CAAC,IAAI;gBAChB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAC9C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC,CAAC,EAAE,CAAC;QACL,OAAO,IAAI,CAAC;IACd,CAAC;CAEF","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\nimport type {\r\n ExtensionManifest,\r\n ExtensionProvider,\r\n} from \"../Extension\";\r\nimport { request, RequestOptions } from \"../../request/Request\";\r\nimport { loadScript } from \"./ExtensionLoadScript\";\r\n\r\n/**\r\n * Required props for a remote extension provider\r\n * @alpha\r\n */\r\nexport interface RemoteExtensionProviderProps {\r\n /** URL where the extension entry point can be loaded from */\r\n jsUrl: string;\r\n /** URL where the manifest (package.json) can be loaded from */\r\n manifestUrl: string;\r\n}\r\n\r\n/**\r\n * Implements a \"remote\" extension.\r\n * Remote extensions are hosted on an external server.\r\n * The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.\r\n * @alpha\r\n */\r\nexport class RemoteExtensionProvider implements ExtensionProvider {\r\n /** The name of the server where the extension is hosted. */\r\n public readonly hostname: string;\r\n\r\n constructor(private readonly _props: RemoteExtensionProviderProps) {\r\n this.hostname = new URL(this._props.jsUrl).hostname.replace(\"www\", \"\");\r\n }\r\n\r\n /**\r\n * Attempts to execute an extension.\r\n * Throws an error if the provided jsUrl is not accessible.\r\n */\r\n public async execute(): Promise<string> {\r\n return loadScript(this._props.jsUrl);\r\n }\r\n\r\n /**\r\n * Attempts to fetch an extension's manifest (package.json) file.\r\n * Throws an error if the provided manifestUrl is not accessible.\r\n */\r\n public async getManifest(): Promise<ExtensionManifest> {\r\n const options: RequestOptions = { method: \"GET\" };\r\n const response = await request(this._props.manifestUrl, options);\r\n const data = response.body || (() => {\r\n if (!response.text)\r\n throw new Error(\"Manifest file was empty.\");\r\n return JSON.parse(response.text);\r\n })();\r\n return data;\r\n }\r\n\r\n}\r\n"]}
|
|
@@ -7,10 +7,10 @@ import type { AccessToken } from "@itwin/core-bentley";
|
|
|
7
7
|
export interface ServiceExtensionProviderProps {
|
|
8
8
|
/** Name of the uploaded extension */
|
|
9
9
|
name: string;
|
|
10
|
-
/** Version number (
|
|
11
|
-
version
|
|
12
|
-
/** iTwin Id */
|
|
13
|
-
iTwinId
|
|
10
|
+
/** Version number (optional - if undefined, assumes the latest version) */
|
|
11
|
+
version?: string;
|
|
12
|
+
/** iTwin Id (optional - if undefined, assumes the extension is public) */
|
|
13
|
+
iTwinId?: string;
|
|
14
14
|
/** @internal */
|
|
15
15
|
getAccessToken?: () => Promise<AccessToken>;
|
|
16
16
|
}
|
|
@@ -31,8 +31,6 @@ export declare class ServiceExtensionProvider implements ExtensionProvider {
|
|
|
31
31
|
* Throws an error if the file cannot be found.
|
|
32
32
|
*/
|
|
33
33
|
execute(): Promise<any>;
|
|
34
|
-
/** Checks if url actually exists */
|
|
35
|
-
private _exists;
|
|
36
34
|
/** Fetches the extension from the ExtensionService.
|
|
37
35
|
*/
|
|
38
36
|
private _getExtensionFiles;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ServiceExtensionProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ServiceExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ServiceExtensionProvider.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,iBAAiB,EAAE,iBAAiB,EACrC,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB;IAChB,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;CAC7C;AAED;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,iBAAiB;IAEpD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,6BAA6B;IAElE;;OAEG;IACU,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAetD;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;IAQpC;OACG;YACW,kBAAkB;CAyBjC"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { rcompare } from "semver";
|
|
6
6
|
import { IModelApp } from "../../IModelApp";
|
|
7
|
+
import { request } from "../../request/Request";
|
|
7
8
|
import { loadScript } from "./ExtensionLoadScript";
|
|
8
9
|
import { ExtensionClient } from "./ExtensionServiceClient";
|
|
9
10
|
/**
|
|
@@ -23,10 +24,14 @@ export class ServiceExtensionProvider {
|
|
|
23
24
|
const loadedExtensionProps = await this._getExtensionFiles(this._props);
|
|
24
25
|
if (!loadedExtensionProps)
|
|
25
26
|
throw new Error(`Error loading manifest for Extension ${this._props.name}.`);
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const options = { method: "GET" };
|
|
28
|
+
const response = await request(loadedExtensionProps.manifest.url, options);
|
|
29
|
+
const data = response.body || (() => {
|
|
30
|
+
if (!response.text)
|
|
31
|
+
throw new Error("Manifest file was empty.");
|
|
32
|
+
return JSON.parse(response.text);
|
|
33
|
+
})();
|
|
34
|
+
return data;
|
|
30
35
|
}
|
|
31
36
|
/** Executes the javascript main file (the bundled index.js) of an extension from the Extension Service.
|
|
32
37
|
* Throws an error if the file cannot be found.
|
|
@@ -35,24 +40,8 @@ export class ServiceExtensionProvider {
|
|
|
35
40
|
const loadedExtensionProps = await this._getExtensionFiles(this._props);
|
|
36
41
|
if (!loadedExtensionProps)
|
|
37
42
|
throw new Error(`Error executing Extension ${this._props.name}.`);
|
|
38
|
-
const doesUrlExist = await this._exists(loadedExtensionProps.main.url);
|
|
39
|
-
if (!doesUrlExist)
|
|
40
|
-
throw new Error(`Main javascript file at ${loadedExtensionProps.main.url} could not be found.`);
|
|
41
43
|
return loadScript(loadedExtensionProps.main.url);
|
|
42
44
|
}
|
|
43
|
-
/** Checks if url actually exists */
|
|
44
|
-
async _exists(url) {
|
|
45
|
-
let exists = false;
|
|
46
|
-
try {
|
|
47
|
-
const response = await fetch(url, { method: "HEAD" });
|
|
48
|
-
if (response.status === 200)
|
|
49
|
-
exists = true;
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
exists = false;
|
|
53
|
-
}
|
|
54
|
-
return exists;
|
|
55
|
-
}
|
|
56
45
|
/** Fetches the extension from the ExtensionService.
|
|
57
46
|
*/
|
|
58
47
|
async _getExtensionFiles(props) {
|
|
@@ -63,9 +52,9 @@ export class ServiceExtensionProvider {
|
|
|
63
52
|
return undefined;
|
|
64
53
|
let extensionProps;
|
|
65
54
|
if (props.version !== undefined)
|
|
66
|
-
extensionProps = await extensionClient.getExtensionMetadata(accessToken, props.
|
|
55
|
+
extensionProps = await extensionClient.getExtensionMetadata(accessToken, props.name, props.version, props.iTwinId);
|
|
67
56
|
else {
|
|
68
|
-
const propsArr = await extensionClient.getExtensions(accessToken, props.
|
|
57
|
+
const propsArr = await extensionClient.getExtensions(accessToken, props.name, props.iTwinId);
|
|
69
58
|
extensionProps = propsArr.sort((ext1, ext2) => rcompare(ext1.version, ext2.version, true))[0];
|
|
70
59
|
}
|
|
71
60
|
if (extensionProps === undefined || extensionProps.files.length < 1)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/ServiceExtensionProvider.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAqB,MAAM,0BAA0B,CAAC;AAsB9E;;;;;GAKG;AACH,MAAM,OAAO,wBAAwB;IAEnC,YAA6B,MAAqC;QAArC,WAAM,GAAN,MAAM,CAA+B;IAAI,CAAC;IAEvE;;OAEG;IACI,KAAK,CAAC,WAAW;QACtB,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxE,IAAI,CAAC,oBAAoB;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I,cAAc,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;YACjE,OAAO,SAAS,CAAC;QAEnB,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACvF,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI;YACpB,OAAO,SAAS,CAAC;QAEnB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF","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\nimport { rcompare } from \"semver\";\r\n\r\nimport { IModelApp } from \"../../IModelApp\";\r\nimport { request, RequestOptions } from \"../../request/Request\";\r\nimport { loadScript } from \"./ExtensionLoadScript\";\r\nimport { ExtensionClient, ExtensionMetadata } from \"./ExtensionServiceClient\";\r\n\r\nimport type {\r\n ExtensionManifest, ExtensionProvider,\r\n} from \"../Extension\";\r\nimport type { AccessToken } from \"@itwin/core-bentley\";\r\n\r\n/**\r\n * Required props for an extension uploaded to Bentley's Extension Service\r\n * @alpha\r\n */\r\nexport interface ServiceExtensionProviderProps {\r\n /** Name of the uploaded extension */\r\n name: string;\r\n /** Version number (optional - if undefined, assumes the latest version) */\r\n version?: string;\r\n /** iTwin Id (optional - if undefined, assumes the extension is public) */\r\n iTwinId?: string;\r\n /** @internal */\r\n getAccessToken?: () => Promise<AccessToken>;\r\n}\r\n\r\n/**\r\n * Implements an Extension from the Extension Service via the ServiceExtensionProviderProps.\r\n * Service extensions are extensions hosted on Bentley's Extension Service.\r\n * The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.\r\n * @alpha\r\n */\r\nexport class ServiceExtensionProvider implements ExtensionProvider {\r\n\r\n constructor(private readonly _props: ServiceExtensionProviderProps) { }\r\n\r\n /** Returns the extension's manifest (package.json) from the ExtensionService.\r\n * Throws an error if the manifest cannot be found.\r\n */\r\n public async getManifest(): Promise<ExtensionManifest> {\r\n const loadedExtensionProps = await this._getExtensionFiles(this._props);\r\n if (!loadedExtensionProps)\r\n throw new Error(`Error loading manifest for Extension ${this._props.name}.`);\r\n\r\n const options: RequestOptions = { method: \"GET\" };\r\n const response = await request(loadedExtensionProps.manifest.url, options);\r\n const data = response.body || (() => {\r\n if (!response.text)\r\n throw new Error(\"Manifest file was empty.\");\r\n return JSON.parse(response.text);\r\n })();\r\n return data;\r\n }\r\n\r\n /** Executes the javascript main file (the bundled index.js) of an extension from the Extension Service.\r\n * Throws an error if the file cannot be found.\r\n */\r\n public async execute(): Promise<any> {\r\n const loadedExtensionProps = await this._getExtensionFiles(this._props);\r\n if (!loadedExtensionProps)\r\n throw new Error(`Error executing Extension ${this._props.name}.`);\r\n\r\n return loadScript(loadedExtensionProps.main.url);\r\n }\r\n\r\n /** Fetches the extension from the ExtensionService.\r\n */\r\n private async _getExtensionFiles(props: ServiceExtensionProviderProps) {\r\n const extensionClient = new ExtensionClient();\r\n\r\n const accessToken = await (props.getAccessToken?.() ?? IModelApp.authorizationClient?.getAccessToken());\r\n if (!accessToken)\r\n return undefined;\r\n\r\n let extensionProps: ExtensionMetadata | undefined;\r\n if (props.version !== undefined)\r\n extensionProps = await extensionClient.getExtensionMetadata(accessToken, props.name, props.version, props.iTwinId);\r\n else {\r\n const propsArr = await extensionClient.getExtensions(accessToken, props.name, props.iTwinId);\r\n extensionProps = propsArr.sort((ext1, ext2) => rcompare(ext1.version, ext2.version, true))[0];\r\n }\r\n\r\n if (extensionProps === undefined || extensionProps.files.length < 1)\r\n return undefined;\r\n\r\n const manifest = extensionProps.files.find((f) => f.url.indexOf(\"package.json?\") > -1);\r\n const main = extensionProps.files.find((f) => f.url.indexOf(\"index.js?\") > -1);\r\n if (!manifest || !main)\r\n return undefined;\r\n\r\n return { manifest, main };\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-frontend",
|
|
3
|
-
"version": "3.3.0-dev.
|
|
3
|
+
"version": "3.3.0-dev.29",
|
|
4
4
|
"description": "iTwin.js frontend components",
|
|
5
5
|
"main": "lib/cjs/core-frontend.js",
|
|
6
6
|
"module": "lib/esm/core-frontend.js",
|
|
@@ -22,29 +22,29 @@
|
|
|
22
22
|
"url": "http://www.bentley.com"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@itwin/appui-abstract": "^3.3.0-dev.
|
|
26
|
-
"@itwin/core-bentley": "^3.3.0-dev.
|
|
27
|
-
"@itwin/core-common": "^3.3.0-dev.
|
|
28
|
-
"@itwin/core-geometry": "^3.3.0-dev.
|
|
29
|
-
"@itwin/core-orbitgt": "^3.3.0-dev.
|
|
30
|
-
"@itwin/core-quantity": "^3.3.0-dev.
|
|
31
|
-
"@itwin/webgl-compatibility": "^3.3.0-dev.
|
|
25
|
+
"@itwin/appui-abstract": "^3.3.0-dev.29",
|
|
26
|
+
"@itwin/core-bentley": "^3.3.0-dev.29",
|
|
27
|
+
"@itwin/core-common": "^3.3.0-dev.29",
|
|
28
|
+
"@itwin/core-geometry": "^3.3.0-dev.29",
|
|
29
|
+
"@itwin/core-orbitgt": "^3.3.0-dev.29",
|
|
30
|
+
"@itwin/core-quantity": "^3.3.0-dev.29",
|
|
31
|
+
"@itwin/webgl-compatibility": "^3.3.0-dev.29"
|
|
32
32
|
},
|
|
33
33
|
"//devDependencies": [
|
|
34
34
|
"NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
|
|
35
35
|
"NOTE: All tools used by scripts in this package must be listed as devDependencies"
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@itwin/appui-abstract": "3.3.0-dev.
|
|
39
|
-
"@itwin/build-tools": "3.3.0-dev.
|
|
40
|
-
"@itwin/core-bentley": "3.3.0-dev.
|
|
41
|
-
"@itwin/core-common": "3.3.0-dev.
|
|
42
|
-
"@itwin/core-geometry": "3.3.0-dev.
|
|
43
|
-
"@itwin/core-orbitgt": "3.3.0-dev.
|
|
44
|
-
"@itwin/core-quantity": "3.3.0-dev.
|
|
45
|
-
"@itwin/certa": "3.3.0-dev.
|
|
46
|
-
"@itwin/eslint-plugin": "3.3.0-dev.
|
|
47
|
-
"@itwin/webgl-compatibility": "3.3.0-dev.
|
|
38
|
+
"@itwin/appui-abstract": "3.3.0-dev.29",
|
|
39
|
+
"@itwin/build-tools": "3.3.0-dev.29",
|
|
40
|
+
"@itwin/core-bentley": "3.3.0-dev.29",
|
|
41
|
+
"@itwin/core-common": "3.3.0-dev.29",
|
|
42
|
+
"@itwin/core-geometry": "3.3.0-dev.29",
|
|
43
|
+
"@itwin/core-orbitgt": "3.3.0-dev.29",
|
|
44
|
+
"@itwin/core-quantity": "3.3.0-dev.29",
|
|
45
|
+
"@itwin/certa": "3.3.0-dev.29",
|
|
46
|
+
"@itwin/eslint-plugin": "3.3.0-dev.29",
|
|
47
|
+
"@itwin/webgl-compatibility": "3.3.0-dev.29",
|
|
48
48
|
"@types/chai": "^4.1.4",
|
|
49
49
|
"@types/chai-as-promised": "^7",
|
|
50
50
|
"@types/deep-assign": "^0.1.0",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"NOTE: core-frontend should remain UI technology agnostic, so no react/angular dependencies are allowed"
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@itwin/core-i18n": "3.3.0-dev.
|
|
77
|
-
"@itwin/core-telemetry": "3.3.0-dev.
|
|
76
|
+
"@itwin/core-i18n": "3.3.0-dev.29",
|
|
77
|
+
"@itwin/core-telemetry": "3.3.0-dev.29",
|
|
78
78
|
"@loaders.gl/core": "^3.1.6",
|
|
79
79
|
"@loaders.gl/draco": "^3.1.6",
|
|
80
80
|
"deep-assign": "^2.0.0",
|