@itwin/core-frontend 3.2.0-dev.71 → 3.2.0-dev.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/FrontendLoggerCategory.d.ts +5 -1
- package/lib/cjs/FrontendLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/FrontendLoggerCategory.js +4 -0
- package/lib/cjs/FrontendLoggerCategory.js.map +1 -1
- package/lib/cjs/core-frontend.d.ts +3 -0
- package/lib/cjs/core-frontend.d.ts.map +1 -1
- package/lib/cjs/core-frontend.js +3 -0
- package/lib/cjs/core-frontend.js.map +1 -1
- package/lib/cjs/extension/Extension.d.ts +22 -32
- package/lib/cjs/extension/Extension.d.ts.map +1 -1
- package/lib/cjs/extension/Extension.js.map +1 -1
- package/lib/cjs/extension/ExtensionAdmin.d.ts +22 -43
- package/lib/cjs/extension/ExtensionAdmin.d.ts.map +1 -1
- package/lib/cjs/extension/ExtensionAdmin.js +54 -60
- package/lib/cjs/extension/ExtensionAdmin.js.map +1 -1
- package/lib/cjs/extension/providers/ExtensionLoadScript.d.ts +10 -0
- package/lib/cjs/extension/providers/ExtensionLoadScript.d.ts.map +1 -0
- package/lib/cjs/extension/providers/ExtensionLoadScript.js +55 -0
- package/lib/cjs/extension/providers/ExtensionLoadScript.js.map +1 -0
- package/lib/cjs/extension/providers/ExtensionServiceClient.d.ts +52 -0
- package/lib/cjs/extension/providers/ExtensionServiceClient.d.ts.map +1 -0
- package/lib/cjs/extension/providers/ExtensionServiceClient.js +131 -0
- package/lib/cjs/extension/providers/ExtensionServiceClient.js.map +1 -0
- package/lib/cjs/extension/providers/LocalExtensionProvider.d.ts +26 -0
- package/lib/cjs/extension/providers/LocalExtensionProvider.d.ts.map +1 -0
- package/lib/cjs/extension/providers/LocalExtensionProvider.js +24 -0
- package/lib/cjs/extension/providers/LocalExtensionProvider.js.map +1 -0
- package/lib/cjs/extension/providers/RemoteExtensionProvider.d.ts +36 -0
- package/lib/cjs/extension/providers/RemoteExtensionProvider.d.ts.map +1 -0
- package/lib/cjs/extension/providers/RemoteExtensionProvider.js +53 -0
- package/lib/cjs/extension/providers/RemoteExtensionProvider.js.map +1 -0
- package/lib/cjs/extension/providers/ServiceExtensionProvider.d.ts +37 -0
- package/lib/cjs/extension/providers/ServiceExtensionProvider.d.ts.map +1 -0
- package/lib/cjs/extension/providers/ServiceExtensionProvider.js +84 -0
- package/lib/cjs/extension/providers/ServiceExtensionProvider.js.map +1 -0
- package/lib/esm/FrontendLoggerCategory.d.ts +5 -1
- package/lib/esm/FrontendLoggerCategory.d.ts.map +1 -1
- package/lib/esm/FrontendLoggerCategory.js +4 -0
- package/lib/esm/FrontendLoggerCategory.js.map +1 -1
- package/lib/esm/core-frontend.d.ts +3 -0
- package/lib/esm/core-frontend.d.ts.map +1 -1
- package/lib/esm/core-frontend.js +3 -0
- package/lib/esm/core-frontend.js.map +1 -1
- package/lib/esm/extension/Extension.d.ts +22 -32
- package/lib/esm/extension/Extension.d.ts.map +1 -1
- package/lib/esm/extension/Extension.js.map +1 -1
- package/lib/esm/extension/ExtensionAdmin.d.ts +22 -43
- package/lib/esm/extension/ExtensionAdmin.d.ts.map +1 -1
- package/lib/esm/extension/ExtensionAdmin.js +54 -60
- package/lib/esm/extension/ExtensionAdmin.js.map +1 -1
- package/lib/esm/extension/providers/ExtensionLoadScript.d.ts +10 -0
- package/lib/esm/extension/providers/ExtensionLoadScript.d.ts.map +1 -0
- package/lib/esm/extension/providers/ExtensionLoadScript.js +51 -0
- package/lib/esm/extension/providers/ExtensionLoadScript.js.map +1 -0
- package/lib/esm/extension/providers/ExtensionServiceClient.d.ts +52 -0
- package/lib/esm/extension/providers/ExtensionServiceClient.d.ts.map +1 -0
- package/lib/esm/extension/providers/ExtensionServiceClient.js +127 -0
- package/lib/esm/extension/providers/ExtensionServiceClient.js.map +1 -0
- package/lib/esm/extension/providers/LocalExtensionProvider.d.ts +26 -0
- package/lib/esm/extension/providers/LocalExtensionProvider.d.ts.map +1 -0
- package/lib/esm/extension/providers/LocalExtensionProvider.js +20 -0
- package/lib/esm/extension/providers/LocalExtensionProvider.js.map +1 -0
- package/lib/esm/extension/providers/RemoteExtensionProvider.d.ts +36 -0
- package/lib/esm/extension/providers/RemoteExtensionProvider.d.ts.map +1 -0
- package/lib/esm/extension/providers/RemoteExtensionProvider.js +49 -0
- package/lib/esm/extension/providers/RemoteExtensionProvider.js.map +1 -0
- package/lib/esm/extension/providers/ServiceExtensionProvider.d.ts +37 -0
- package/lib/esm/extension/providers/ServiceExtensionProvider.d.ts.map +1 -0
- package/lib/esm/extension/providers/ServiceExtensionProvider.js +80 -0
- package/lib/esm/extension/providers/ServiceExtensionProvider.js.map +1 -0
- package/package.json +21 -22
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadScript = 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
|
+
/**
|
|
9
|
+
* Executes an extension's bundled javascript module.
|
|
10
|
+
* First attempts an ES6 dynamic import,
|
|
11
|
+
* second attempts a dynamic import via a script element as a fallback.
|
|
12
|
+
* Used by remote and service Extensions.
|
|
13
|
+
* Throws an error if the module does not have a default or main function to execute.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
async function loadScript(jsUrl) {
|
|
17
|
+
// Warning "Critical dependency: the request of a dependency is an expression"
|
|
18
|
+
// until that is resolved, leave code commented:
|
|
19
|
+
// const module = await import(/* webpackIgnore: true */jsUrl);
|
|
20
|
+
// return execute(module);
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const head = document.getElementsByTagName("head")[0];
|
|
23
|
+
if (!head)
|
|
24
|
+
reject(new Error("No head element found"));
|
|
25
|
+
const scriptElement = document.createElement("script");
|
|
26
|
+
const tempGlobal = `__tempModuleLoadingVariable${Math.random().toString(32).substring(2)}`;
|
|
27
|
+
function cleanup() {
|
|
28
|
+
delete window[tempGlobal];
|
|
29
|
+
scriptElement.remove();
|
|
30
|
+
}
|
|
31
|
+
window[tempGlobal] = async function (module) {
|
|
32
|
+
await execute(module);
|
|
33
|
+
cleanup();
|
|
34
|
+
resolve(module);
|
|
35
|
+
};
|
|
36
|
+
scriptElement.type = "module";
|
|
37
|
+
scriptElement.textContent = `import * as m from "${jsUrl}";window.${tempGlobal}(m);`;
|
|
38
|
+
scriptElement.onerror = () => {
|
|
39
|
+
reject(new Error(`Failed to load extension with URL ${jsUrl}`));
|
|
40
|
+
cleanup();
|
|
41
|
+
};
|
|
42
|
+
head.insertBefore(scriptElement, head.lastChild);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.loadScript = loadScript;
|
|
46
|
+
function execute(m) {
|
|
47
|
+
if (typeof m === "function")
|
|
48
|
+
return m();
|
|
49
|
+
if (m.main && typeof m.main === "function")
|
|
50
|
+
return m.main();
|
|
51
|
+
if (m.default && typeof m.default === "function")
|
|
52
|
+
return m.default();
|
|
53
|
+
throw new Error(`Failed to load extension. No default function was found to execute.`);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=ExtensionLoadScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionLoadScript.js","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionLoadScript.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;;;;;;GAOG;AACI,KAAK,UAAU,UAAU,CAAC,KAAa;IAC5C,8EAA8E;IAC9E,gDAAgD;IAChD,+DAA+D;IAC/D,0BAA0B;IAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,oB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AAC,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,UAAU;QAC9C,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;IACrB,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;AACzF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/**\r\n * Executes an extension's bundled javascript module.\r\n * First attempts an ES6 dynamic import,\r\n * second attempts a dynamic import via a script element as a fallback.\r\n * Used by remote and service Extensions.\r\n * Throws an error if the module does not have a default or main function to execute.\r\n * @internal\r\n */\r\nexport async function loadScript(jsUrl: string): Promise<any> {\r\n // Warning \"Critical dependency: the request of a dependency is an expression\"\r\n // until that is resolved, leave code commented:\r\n // const module = await import(/* webpackIgnore: true */jsUrl);\r\n // return execute(module);\r\n return new Promise((resolve, reject) => {\r\n const head = document.getElementsByTagName(\"head\")[0];\r\n if (!head)\r\n reject(new Error(\"No head element found\"));\r\n\r\n const scriptElement = document.createElement(\"script\");\r\n const tempGlobal: string = `__tempModuleLoadingVariable${Math.random().toString(32).substring(2)}`;\r\n\r\n function cleanup() {\r\n delete (window as any)[tempGlobal];\r\n scriptElement.remove();\r\n }\r\n\r\n (window as any)[tempGlobal] = async function (module: any) {\r\n await execute(module);\r\n cleanup();\r\n resolve(module);\r\n };\r\n scriptElement.type = \"module\";\r\n scriptElement.textContent = `import * as m from \"${jsUrl}\";window.${tempGlobal}(m);`;\r\n\r\n scriptElement.onerror = () => {\r\n reject(new Error(`Failed to load extension with URL ${jsUrl}`));\r\n cleanup();\r\n };\r\n\r\n head.insertBefore(scriptElement, head.lastChild);\r\n });\r\n}\r\n\r\nfunction execute(m: any) {\r\n if (typeof m === \"function\")\r\n return m();\r\n if (m.main && typeof m.main === \"function\")\r\n return m.main();\r\n if (m.default && typeof m.default === \"function\")\r\n return m.default();\r\n throw new Error(`Failed to load extension. No default function was found to execute.`);\r\n}\r\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AccessToken } from "@itwin/core-bentley";
|
|
2
|
+
/** Structure of extensions from the ExtensionService
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export interface ExtensionMetadata {
|
|
6
|
+
contextId: string;
|
|
7
|
+
extensionName: string;
|
|
8
|
+
version: string;
|
|
9
|
+
files: FileInfo[];
|
|
10
|
+
uploadedBy: string;
|
|
11
|
+
timestamp: Date;
|
|
12
|
+
status: ExtensionUploadStatus;
|
|
13
|
+
isPublic: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface ExtensionUploadStatus {
|
|
16
|
+
updateTime: Date;
|
|
17
|
+
status: string;
|
|
18
|
+
}
|
|
19
|
+
interface FileInfo {
|
|
20
|
+
url: string;
|
|
21
|
+
expires: Date;
|
|
22
|
+
checksum: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Client for querying, publishing and deleting iModel.js Extensions.
|
|
26
|
+
*
|
|
27
|
+
* The `imodel-extension-service-api` OIDC scope is required for all operations and the `imodel-extension-service:modify` is
|
|
28
|
+
* required for modification operations (modify, publish, and deleting).
|
|
29
|
+
* @alpha
|
|
30
|
+
*/
|
|
31
|
+
export declare class ExtensionClient {
|
|
32
|
+
private readonly _baseUrl;
|
|
33
|
+
constructor();
|
|
34
|
+
private get _endpoint();
|
|
35
|
+
private parseExtensionMetadataArray;
|
|
36
|
+
/**
|
|
37
|
+
* Gets information on extensions. If extensionName is undefined, will return all extensions in the context.
|
|
38
|
+
* If it's defined, will return all versions of that extension.
|
|
39
|
+
* @param iTwinId Context Id
|
|
40
|
+
* @param extensionName Extension name (optional)
|
|
41
|
+
*/
|
|
42
|
+
getExtensions(accessToken: AccessToken, iTwinId: string, extensionName?: string): Promise<ExtensionMetadata[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets information about an extension's specific version
|
|
45
|
+
* @param iTwinId iTwin Id
|
|
46
|
+
* @param extensionName Extension name
|
|
47
|
+
* @param version Extension version
|
|
48
|
+
*/
|
|
49
|
+
getExtensionMetadata(accessToken: AccessToken, iTwinId: string, extensionName: string, version: string): Promise<ExtensionMetadata | undefined>;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=ExtensionServiceClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionServiceClient.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionServiceClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIlD;;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;;;;;OAKG;IACU,aAAa,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAa3H;;;;;OAKG;IACU,oBAAoB,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;CAe7J"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtensionClient = void 0;
|
|
4
|
+
const Request_1 = require("../../request/Request");
|
|
5
|
+
/**
|
|
6
|
+
* Client for querying, publishing and deleting iModel.js Extensions.
|
|
7
|
+
*
|
|
8
|
+
* The `imodel-extension-service-api` OIDC scope is required for all operations and the `imodel-extension-service:modify` is
|
|
9
|
+
* required for modification operations (modify, publish, and deleting).
|
|
10
|
+
* @alpha
|
|
11
|
+
*/
|
|
12
|
+
class ExtensionClient {
|
|
13
|
+
constructor() {
|
|
14
|
+
this._baseUrl = "https://api.bentley.com/iModelExtensionService/";
|
|
15
|
+
}
|
|
16
|
+
get _endpoint() {
|
|
17
|
+
const prefix = process.env.IMJS_URL_PREFIX;
|
|
18
|
+
const baseUrl = new URL(this._baseUrl);
|
|
19
|
+
if (prefix)
|
|
20
|
+
baseUrl.hostname = prefix + new URL(baseUrl).hostname;
|
|
21
|
+
if (!baseUrl.pathname.endsWith("/"))
|
|
22
|
+
baseUrl.pathname += "/";
|
|
23
|
+
baseUrl.pathname += "v1.0/";
|
|
24
|
+
return baseUrl.toString();
|
|
25
|
+
}
|
|
26
|
+
parseExtensionMetadataArray(json) {
|
|
27
|
+
if (!(json instanceof Array))
|
|
28
|
+
return [];
|
|
29
|
+
const ret = [];
|
|
30
|
+
json.forEach((extensionJson) => {
|
|
31
|
+
const extension = extensionMetadataFromJSON(extensionJson);
|
|
32
|
+
if (extension !== undefined)
|
|
33
|
+
ret.push(extension);
|
|
34
|
+
});
|
|
35
|
+
return ret;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets information on extensions. If extensionName is undefined, will return all extensions in the context.
|
|
39
|
+
* If it's defined, will return all versions of that extension.
|
|
40
|
+
* @param iTwinId Context Id
|
|
41
|
+
* @param extensionName Extension name (optional)
|
|
42
|
+
*/
|
|
43
|
+
async getExtensions(accessToken, iTwinId, extensionName) {
|
|
44
|
+
const options = { method: "GET" };
|
|
45
|
+
options.headers = { authorization: accessToken };
|
|
46
|
+
const response = await (0, Request_1.request)(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName !== null && extensionName !== void 0 ? extensionName : ""}`, options);
|
|
47
|
+
if (response.status !== 200)
|
|
48
|
+
throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);
|
|
49
|
+
if (!(response.body instanceof Array) || response.body.length < 1)
|
|
50
|
+
return [];
|
|
51
|
+
return this.parseExtensionMetadataArray(response.body);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets information about an extension's specific version
|
|
55
|
+
* @param iTwinId iTwin Id
|
|
56
|
+
* @param extensionName Extension name
|
|
57
|
+
* @param version Extension version
|
|
58
|
+
*/
|
|
59
|
+
async getExtensionMetadata(accessToken, iTwinId, extensionName, version) {
|
|
60
|
+
const options = { method: "GET" };
|
|
61
|
+
options.headers = { authorization: accessToken };
|
|
62
|
+
const response = await (0, Request_1.request)(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName}/${version}`, options);
|
|
63
|
+
if (response.status !== 200)
|
|
64
|
+
throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);
|
|
65
|
+
if (!(response.body instanceof Array) || response.body.length < 1)
|
|
66
|
+
return undefined;
|
|
67
|
+
if (response.body.length > 1)
|
|
68
|
+
throw new Error("Server returned too many extensions");
|
|
69
|
+
return extensionMetadataFromJSON(response.body[0]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.ExtensionClient = ExtensionClient;
|
|
73
|
+
/**
|
|
74
|
+
* Validates JSON and returns ExtensionMetadata
|
|
75
|
+
*/
|
|
76
|
+
function extensionMetadataFromJSON(jsonObject) {
|
|
77
|
+
if (jsonObject.contextId === undefined || typeof jsonObject.contextId !== "string" ||
|
|
78
|
+
jsonObject.extensionName === undefined || typeof jsonObject.extensionName !== "string" ||
|
|
79
|
+
jsonObject.version === undefined || typeof jsonObject.version !== "string" ||
|
|
80
|
+
jsonObject.files === undefined || !(jsonObject.files instanceof Array) ||
|
|
81
|
+
jsonObject.uploadedBy === undefined || typeof jsonObject.uploadedBy !== "string" ||
|
|
82
|
+
jsonObject.timestamp === undefined || typeof jsonObject.timestamp !== "string" ||
|
|
83
|
+
jsonObject.isPublic === undefined || typeof jsonObject.isPublic !== "boolean" ||
|
|
84
|
+
jsonObject.extensionStatus === undefined) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
const status = statusFromJSON(jsonObject.extensionStatus);
|
|
88
|
+
if (status === undefined)
|
|
89
|
+
return undefined;
|
|
90
|
+
const files = new Array(jsonObject.files.length);
|
|
91
|
+
for (let i = 0; i < jsonObject.files.length; i++) {
|
|
92
|
+
const parsed = fileInfoFromJSON(jsonObject.files[i]);
|
|
93
|
+
if (parsed === undefined)
|
|
94
|
+
return undefined;
|
|
95
|
+
files[i] = parsed;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
contextId: jsonObject.contextId,
|
|
99
|
+
extensionName: jsonObject.extensionName,
|
|
100
|
+
version: jsonObject.version,
|
|
101
|
+
files,
|
|
102
|
+
uploadedBy: jsonObject.uploadedBy,
|
|
103
|
+
timestamp: new Date(jsonObject.timestamp),
|
|
104
|
+
isPublic: jsonObject.isPublic,
|
|
105
|
+
status,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function statusFromJSON(jsonObject) {
|
|
109
|
+
var _a;
|
|
110
|
+
if (jsonObject.statusUpdateTime === undefined || typeof jsonObject.statusUpdateTime !== "string" ||
|
|
111
|
+
jsonObject.status === undefined || (jsonObject.status !== null && typeof jsonObject.status !== "string")) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
updateTime: new Date(jsonObject.statusUpdateTime),
|
|
116
|
+
status: (_a = jsonObject.status) !== null && _a !== void 0 ? _a : "Valid",
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function fileInfoFromJSON(jsonObject) {
|
|
120
|
+
if (jsonObject.url === undefined || typeof jsonObject.url !== "string" ||
|
|
121
|
+
jsonObject.expiresAt === undefined || typeof jsonObject.expiresAt !== "string" ||
|
|
122
|
+
jsonObject.checksum === undefined || (typeof jsonObject.checksum !== "string" && jsonObject.checksum !== null)) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
url: jsonObject.url,
|
|
127
|
+
expires: new Date(jsonObject.expiresAt),
|
|
128
|
+
checksum: jsonObject.checksum,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=ExtensionServiceClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionServiceClient.js","sourceRoot":"","sources":["../../../../src/extension/providers/ExtensionServiceClient.ts"],"names":[],"mappings":";;;AAMA,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,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KAAK,QAAQ;QAC9F,UAAU,CAAC,MAAM,KAAK,SAAS,IAAI,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 } 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"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ExtensionManifest, ExtensionProvider, ResolveFunc } from "../Extension";
|
|
2
|
+
/**
|
|
3
|
+
* Required props for a local extension provider
|
|
4
|
+
* @alpha
|
|
5
|
+
*/
|
|
6
|
+
export interface LocalExtensionProviderProps {
|
|
7
|
+
/** A promise that returns the manifest (package.json) of a local extension */
|
|
8
|
+
manifestPromise: Promise<any>;
|
|
9
|
+
/** A function that runs the main entry point of the local extension */
|
|
10
|
+
main: ResolveFunc;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Implements a "local" extension via LocalExtensionProps.
|
|
14
|
+
* An extension is not loaded until it is added to the ExtensionAdmin.
|
|
15
|
+
* The execute() and getManifest() methods are used by the ExtensionAdmin.
|
|
16
|
+
* @alpha
|
|
17
|
+
*/
|
|
18
|
+
export declare class LocalExtensionProvider implements ExtensionProvider {
|
|
19
|
+
private readonly _props;
|
|
20
|
+
constructor(_props: LocalExtensionProviderProps);
|
|
21
|
+
/** returns the manifest (package.json) of a local extension */
|
|
22
|
+
getManifest(): Promise<ExtensionManifest>;
|
|
23
|
+
/** executes the javascript main file / bundle (index.js) of a local extension */
|
|
24
|
+
execute(): Promise<any>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=LocalExtensionProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/LocalExtensionProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACZ,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,8EAA8E;IAC9E,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9B,uEAAuE;IACvE,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,iBAAiB;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,2BAA2B;IAEhE,+DAA+D;IAClD,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAItD,iFAAiF;IACpE,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGrC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalExtensionProvider = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Implements a "local" extension via LocalExtensionProps.
|
|
6
|
+
* An extension is not loaded until it is added to the ExtensionAdmin.
|
|
7
|
+
* The execute() and getManifest() methods are used by the ExtensionAdmin.
|
|
8
|
+
* @alpha
|
|
9
|
+
*/
|
|
10
|
+
class LocalExtensionProvider {
|
|
11
|
+
constructor(_props) {
|
|
12
|
+
this._props = _props;
|
|
13
|
+
}
|
|
14
|
+
/** returns the manifest (package.json) of a local extension */
|
|
15
|
+
async getManifest() {
|
|
16
|
+
return this._props.manifestPromise;
|
|
17
|
+
}
|
|
18
|
+
/** executes the javascript main file / bundle (index.js) of a local extension */
|
|
19
|
+
async execute() {
|
|
20
|
+
return this._props.main();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.LocalExtensionProvider = LocalExtensionProvider;
|
|
24
|
+
//# sourceMappingURL=LocalExtensionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalExtensionProvider.js","sourceRoot":"","sources":["../../../../src/extension/providers/LocalExtensionProvider.ts"],"names":[],"mappings":";;;AAqBA;;;;;GAKG;AACH,MAAa,sBAAsB;IACjC,YAA6B,MAAmC;QAAnC,WAAM,GAAN,MAAM,CAA6B;IAAI,CAAC;IAErE,+DAA+D;IACxD,KAAK,CAAC,WAAW;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;IACrC,CAAC;IAED,iFAAiF;IAC1E,KAAK,CAAC,OAAO;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF;AAZD,wDAYC","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 ResolveFunc,\r\n} from \"../Extension\";\r\n\r\n/**\r\n * Required props for a local extension provider\r\n * @alpha\r\n */\r\nexport interface LocalExtensionProviderProps {\r\n /** A promise that returns the manifest (package.json) of a local extension */\r\n manifestPromise: Promise<any>;\r\n /** A function that runs the main entry point of the local extension */\r\n main: ResolveFunc;\r\n}\r\n\r\n/**\r\n * Implements a \"local\" extension via LocalExtensionProps.\r\n * An extension is not loaded until it is added to the ExtensionAdmin.\r\n * The execute() and getManifest() methods are used by the ExtensionAdmin.\r\n * @alpha\r\n */\r\nexport class LocalExtensionProvider implements ExtensionProvider {\r\n constructor(private readonly _props: LocalExtensionProviderProps) { }\r\n\r\n /** returns the manifest (package.json) of a local extension */\r\n public async getManifest(): Promise<ExtensionManifest> {\r\n return this._props.manifestPromise;\r\n }\r\n\r\n /** executes the javascript main file / bundle (index.js) of a local extension */\r\n public async execute(): Promise<any> {\r\n return this._props.main();\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ExtensionManifest, ExtensionProvider } from "../Extension";
|
|
2
|
+
/**
|
|
3
|
+
* Required props for a remote extension provider
|
|
4
|
+
* @alpha
|
|
5
|
+
*/
|
|
6
|
+
export interface RemoteExtensionProviderProps {
|
|
7
|
+
/** URL where the extension entry point can be loaded from */
|
|
8
|
+
jsUrl: string;
|
|
9
|
+
/** URL where the manifest (package.json) can be loaded from */
|
|
10
|
+
manifestUrl: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Implements a "remote" extension.
|
|
14
|
+
* Remote extensions are hosted on an external server.
|
|
15
|
+
* The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.
|
|
16
|
+
* @alpha
|
|
17
|
+
*/
|
|
18
|
+
export declare class RemoteExtensionProvider implements ExtensionProvider {
|
|
19
|
+
private readonly _props;
|
|
20
|
+
/** The name of the server where the extension is hosted. */
|
|
21
|
+
readonly hostname: string;
|
|
22
|
+
constructor(_props: RemoteExtensionProviderProps);
|
|
23
|
+
/**
|
|
24
|
+
* Attempts to execute an extension.
|
|
25
|
+
* Throws an error if the provided jsUrl is not accessible.
|
|
26
|
+
*/
|
|
27
|
+
execute(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Attempts to fetch an extension's manifest (package.json) file.
|
|
30
|
+
* Throws an error if the provided manifestUrl is not accessible.
|
|
31
|
+
*/
|
|
32
|
+
getManifest(): Promise<ExtensionManifest>;
|
|
33
|
+
/** Checks if url actually exists */
|
|
34
|
+
private _exists;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=RemoteExtensionProvider.d.ts.map
|
|
@@ -0,0 +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;AAGtB;;;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;IAQvC;;;OAGG;IACU,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAQtD,oCAAoC;YACtB,OAAO;CAWtB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteExtensionProvider = void 0;
|
|
4
|
+
const ExtensionLoadScript_1 = require("./ExtensionLoadScript");
|
|
5
|
+
/**
|
|
6
|
+
* Implements a "remote" extension.
|
|
7
|
+
* Remote extensions are hosted on an external server.
|
|
8
|
+
* The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
class RemoteExtensionProvider {
|
|
12
|
+
constructor(_props) {
|
|
13
|
+
this._props = _props;
|
|
14
|
+
this.hostname = new URL(this._props.jsUrl).hostname.replace("www", "");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Attempts to execute an extension.
|
|
18
|
+
* Throws an error if the provided jsUrl is not accessible.
|
|
19
|
+
*/
|
|
20
|
+
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
|
+
return (0, ExtensionLoadScript_1.loadScript)(this._props.jsUrl);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Attempts to fetch an extension's manifest (package.json) file.
|
|
29
|
+
* Throws an error if the provided manifestUrl is not accessible.
|
|
30
|
+
*/
|
|
31
|
+
async getManifest() {
|
|
32
|
+
const doesUrlExist = await this._exists(this._props.manifestUrl);
|
|
33
|
+
if (!doesUrlExist) {
|
|
34
|
+
throw new Error(`Manifest at ${this._props.manifestUrl} could not be found.`);
|
|
35
|
+
}
|
|
36
|
+
return (await fetch(this._props.manifestUrl)).json();
|
|
37
|
+
}
|
|
38
|
+
/** Checks if url actually exists */
|
|
39
|
+
async _exists(url) {
|
|
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;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.RemoteExtensionProvider = RemoteExtensionProvider;
|
|
53
|
+
//# sourceMappingURL=RemoteExtensionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteExtensionProvider.js","s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AAC;YACtD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;gBACzB,MAAM,GAAG,IAAI,CAAC;SACjB;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,GAAG,KAAK,CAAC;SAChB;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA5CD,0DA4CC","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 { 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 const doesUrlExist = await this._exists(this._props.jsUrl);\r\n if (!doesUrlExist) {\r\n throw new Error(`Extension at ${this._props.jsUrl} could not be found.`);\r\n }\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 doesUrlExist = await this._exists(this._props.manifestUrl);\r\n if (!doesUrlExist) {\r\n throw new Error(`Manifest at ${this._props.manifestUrl} could not be found.`);\r\n }\r\n return (await fetch(this._props.manifestUrl)).json();\r\n }\r\n\r\n /** Checks if url actually exists */\r\n private async _exists(url: string): Promise<boolean> {\r\n let exists = false;\r\n try {\r\n const response = await fetch(url, { method: \"HEAD\" });\r\n if (response.status === 200)\r\n exists = true;\r\n } catch (error) {\r\n exists = false;\r\n }\r\n return exists;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ExtensionManifest, ExtensionProvider } from "../Extension";
|
|
2
|
+
/**
|
|
3
|
+
* Required props for an extension uploaded to Bentley's Extension Service
|
|
4
|
+
* @alpha
|
|
5
|
+
*/
|
|
6
|
+
export interface ServiceExtensionProviderProps {
|
|
7
|
+
/** Name of the uploaded extension */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Version number (Semantic Versioning) */
|
|
10
|
+
version: string;
|
|
11
|
+
/** iTwin Id */
|
|
12
|
+
iTwinId: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Implements an Extension from the Extension Service via the ServiceExtensionProviderProps.
|
|
16
|
+
* Service extensions are extensions hosted on Bentley's Extension Service.
|
|
17
|
+
* The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.
|
|
18
|
+
* @alpha
|
|
19
|
+
*/
|
|
20
|
+
export declare class ServiceExtensionProvider implements ExtensionProvider {
|
|
21
|
+
private readonly _props;
|
|
22
|
+
constructor(_props: ServiceExtensionProviderProps);
|
|
23
|
+
/** Returns the extension's manifest (package.json) from the ExtensionService.
|
|
24
|
+
* Throws an error if the manifest cannot be found.
|
|
25
|
+
*/
|
|
26
|
+
getManifest(): Promise<ExtensionManifest>;
|
|
27
|
+
/** Executes the javascript main file (the bundled index.js) of an extension from the Extension Service.
|
|
28
|
+
* Throws an error if the file cannot be found.
|
|
29
|
+
*/
|
|
30
|
+
execute(): Promise<any>;
|
|
31
|
+
/** Checks if url actually exists */
|
|
32
|
+
private _exists;
|
|
33
|
+
/** Fetches the extension from the ExtensionService.
|
|
34
|
+
*/
|
|
35
|
+
private _getExtensionFiles;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=ServiceExtensionProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceExtensionProvider.d.ts","sourceRoot":"","sources":["../../../../src/extension/providers/ServiceExtensionProvider.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,iBAAiB,EAAE,iBAAiB,EACrC,MAAM,cAAc,CAAC;AAEtB;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;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;IAYtD;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;IAYpC,oCAAoC;YACtB,OAAO;IAYrB;OACG;YACW,kBAAkB;CAyBjC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceExtensionProvider = 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 semver_1 = require("semver");
|
|
9
|
+
const IModelApp_1 = require("../../IModelApp");
|
|
10
|
+
const ExtensionLoadScript_1 = require("./ExtensionLoadScript");
|
|
11
|
+
const ExtensionServiceClient_1 = require("./ExtensionServiceClient");
|
|
12
|
+
/**
|
|
13
|
+
* Implements an Extension from the Extension Service via the ServiceExtensionProviderProps.
|
|
14
|
+
* Service extensions are extensions hosted on Bentley's Extension Service.
|
|
15
|
+
* The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.
|
|
16
|
+
* @alpha
|
|
17
|
+
*/
|
|
18
|
+
class ServiceExtensionProvider {
|
|
19
|
+
constructor(_props) {
|
|
20
|
+
this._props = _props;
|
|
21
|
+
}
|
|
22
|
+
/** Returns the extension's manifest (package.json) from the ExtensionService.
|
|
23
|
+
* Throws an error if the manifest cannot be found.
|
|
24
|
+
*/
|
|
25
|
+
async getManifest() {
|
|
26
|
+
const loadedExtensionProps = await this._getExtensionFiles(this._props);
|
|
27
|
+
if (!loadedExtensionProps)
|
|
28
|
+
throw new Error(`Error loading manifest for Extension ${this._props.name}.`);
|
|
29
|
+
const doesUrlExist = await this._exists(loadedExtensionProps.manifest.url);
|
|
30
|
+
if (!doesUrlExist)
|
|
31
|
+
throw new Error(`Manifest at ${loadedExtensionProps.manifest.url} could not be found.`);
|
|
32
|
+
return (await fetch(loadedExtensionProps.manifest.url)).json();
|
|
33
|
+
}
|
|
34
|
+
/** Executes the javascript main file (the bundled index.js) of an extension from the Extension Service.
|
|
35
|
+
* Throws an error if the file cannot be found.
|
|
36
|
+
*/
|
|
37
|
+
async execute() {
|
|
38
|
+
const loadedExtensionProps = await this._getExtensionFiles(this._props);
|
|
39
|
+
if (!loadedExtensionProps)
|
|
40
|
+
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
|
+
return (0, ExtensionLoadScript_1.loadScript)(loadedExtensionProps.main.url);
|
|
45
|
+
}
|
|
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
|
+
/** Fetches the extension from the ExtensionService.
|
|
60
|
+
*/
|
|
61
|
+
async _getExtensionFiles(props) {
|
|
62
|
+
var _a;
|
|
63
|
+
const extensionClient = new ExtensionServiceClient_1.ExtensionClient();
|
|
64
|
+
const accessToken = await ((_a = IModelApp_1.IModelApp.authorizationClient) === null || _a === void 0 ? void 0 : _a.getAccessToken());
|
|
65
|
+
if (!accessToken)
|
|
66
|
+
return undefined;
|
|
67
|
+
let extensionProps;
|
|
68
|
+
if (props.version !== undefined)
|
|
69
|
+
extensionProps = await extensionClient.getExtensionMetadata(accessToken, props.iTwinId, props.name, props.version);
|
|
70
|
+
else {
|
|
71
|
+
const propsArr = await extensionClient.getExtensions(accessToken, props.iTwinId, props.name);
|
|
72
|
+
extensionProps = propsArr.sort((ext1, ext2) => (0, semver_1.rcompare)(ext1.version, ext2.version, true))[0];
|
|
73
|
+
}
|
|
74
|
+
if (extensionProps === undefined || extensionProps.files.length < 1)
|
|
75
|
+
return undefined;
|
|
76
|
+
const manifest = extensionProps.files.find((f) => f.url.indexOf("package.json?") > -1);
|
|
77
|
+
const main = extensionProps.files.find((f) => f.url.indexOf("index.js?") > -1);
|
|
78
|
+
if (!manifest || !main)
|
|
79
|
+
return undefined;
|
|
80
|
+
return { manifest, main };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.ServiceExtensionProvider = ServiceExtensionProvider;
|
|
84
|
+
//# sourceMappingURL=ServiceExtensionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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AAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/F;QAED,IAAI,cAAc,KAAK,SAAS,IAAI,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;AA1ED,4DA0EC","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 { loadScript } from \"./ExtensionLoadScript\";\r\nimport { ExtensionClient, ExtensionMetadata } from \"./ExtensionServiceClient\";\r\n\r\nimport type {\r\n ExtensionManifest, ExtensionProvider,\r\n} from \"../Extension\";\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 (Semantic Versioning) */\r\n version: string;\r\n /** iTwin Id */\r\n iTwinId: string;\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 doesUrlExist = await this._exists(loadedExtensionProps.manifest.url);\r\n if (!doesUrlExist)\r\n throw new Error(`Manifest at ${loadedExtensionProps.manifest.url} could not be found.`);\r\n\r\n return (await fetch(loadedExtensionProps.manifest.url)).json();\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 const doesUrlExist = await this._exists(loadedExtensionProps.main.url);\r\n if (!doesUrlExist)\r\n throw new Error(`Main javascript file at ${loadedExtensionProps.main.url} could not be found.`);\r\n\r\n return loadScript(loadedExtensionProps.main.url);\r\n }\r\n\r\n /** Checks if url actually exists */\r\n private async _exists(url: string): Promise<boolean> {\r\n let exists = false;\r\n try {\r\n const response = await fetch(url, { method: \"HEAD\" });\r\n if (response.status === 200)\r\n exists = true;\r\n } catch (error) {\r\n exists = false;\r\n }\r\n return exists;\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 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.iTwinId, props.name, props.version);\r\n else {\r\n const propsArr = await extensionClient.getExtensions(accessToken, props.iTwinId, props.name);\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"]}
|
|
@@ -26,6 +26,10 @@ export declare enum FrontendLoggerCategory {
|
|
|
26
26
|
*/
|
|
27
27
|
RealityData = "core-frontend.RealityData",
|
|
28
28
|
/** The logger category used for creating and displaying graphics. */
|
|
29
|
-
Render = "core-frontend.Render"
|
|
29
|
+
Render = "core-frontend.Render",
|
|
30
|
+
/** The logger category used for loading and executing Extensions
|
|
31
|
+
* @alpha
|
|
32
|
+
*/
|
|
33
|
+
Extensions = "core-frontend.Extensions"
|
|
30
34
|
}
|
|
31
35
|
//# sourceMappingURL=FrontendLoggerCategory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendLoggerCategory.d.ts","sourceRoot":"","sources":["../../src/FrontendLoggerCategory.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;GAKG;AACH,oBAAY,sBAAsB;IAChC,OAAO,kBAAkB;IAEzB,4FAA4F;IAC5F,gBAAgB,mCAAmC;IAEnD,6CAA6C;IAC7C,SAAS,4BAA4B;IAErC,4DAA4D;IAC5D,OAAO,0BAA0B;IAEjC;;;OAGG;IACH,eAAe,kCAAkC;IACjD;;;OAGG;IACH,WAAW,8BAA8B;IAEzC,qEAAqE;IACrE,MAAM,yBAAyB;
|
|
1
|
+
{"version":3,"file":"FrontendLoggerCategory.d.ts","sourceRoot":"","sources":["../../src/FrontendLoggerCategory.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;GAKG;AACH,oBAAY,sBAAsB;IAChC,OAAO,kBAAkB;IAEzB,4FAA4F;IAC5F,gBAAgB,mCAAmC;IAEnD,6CAA6C;IAC7C,SAAS,4BAA4B;IAErC,4DAA4D;IAC5D,OAAO,0BAA0B;IAEjC;;;OAGG;IACH,eAAe,kCAAkC;IACjD;;;OAGG;IACH,WAAW,8BAA8B;IAEzC,qEAAqE;IACrE,MAAM,yBAAyB;IAE/B;;OAEG;IACH,UAAU,6BAA6B;CACxC"}
|
|
@@ -32,5 +32,9 @@ export var FrontendLoggerCategory;
|
|
|
32
32
|
FrontendLoggerCategory["RealityData"] = "core-frontend.RealityData";
|
|
33
33
|
/** The logger category used for creating and displaying graphics. */
|
|
34
34
|
FrontendLoggerCategory["Render"] = "core-frontend.Render";
|
|
35
|
+
/** The logger category used for loading and executing Extensions
|
|
36
|
+
* @alpha
|
|
37
|
+
*/
|
|
38
|
+
FrontendLoggerCategory["Extensions"] = "core-frontend.Extensions";
|
|
35
39
|
})(FrontendLoggerCategory || (FrontendLoggerCategory = {}));
|
|
36
40
|
//# sourceMappingURL=FrontendLoggerCategory.js.map
|