@itwin/core-frontend 3.3.0-dev.49 → 3.3.0-dev.51

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.
Files changed (161) hide show
  1. package/lib/cjs/DisplayStyleState.d.ts +12 -14
  2. package/lib/cjs/DisplayStyleState.d.ts.map +1 -1
  3. package/lib/cjs/DisplayStyleState.js +84 -69
  4. package/lib/cjs/DisplayStyleState.js.map +1 -1
  5. package/lib/cjs/DrawingViewState.js +1 -1
  6. package/lib/cjs/DrawingViewState.js.map +1 -1
  7. package/lib/cjs/IModelConnection.js +1 -1
  8. package/lib/cjs/IModelConnection.js.map +1 -1
  9. package/lib/cjs/RealityDataSource.d.ts.map +1 -1
  10. package/lib/cjs/RealityDataSource.js +6 -2
  11. package/lib/cjs/RealityDataSource.js.map +1 -1
  12. package/lib/cjs/SheetViewState.js +1 -1
  13. package/lib/cjs/SheetViewState.js.map +1 -1
  14. package/lib/cjs/ViewState.d.ts +1 -2
  15. package/lib/cjs/ViewState.d.ts.map +1 -1
  16. package/lib/cjs/ViewState.js +2 -2
  17. package/lib/cjs/ViewState.js.map +1 -1
  18. package/lib/cjs/Viewport.d.ts.map +1 -1
  19. package/lib/cjs/Viewport.js +9 -4
  20. package/lib/cjs/Viewport.js.map +1 -1
  21. package/lib/cjs/core-frontend.d.ts +0 -2
  22. package/lib/cjs/core-frontend.d.ts.map +1 -1
  23. package/lib/cjs/core-frontend.js +0 -2
  24. package/lib/cjs/core-frontend.js.map +1 -1
  25. package/lib/cjs/render/FeatureSymbology.js +2 -2
  26. package/lib/cjs/render/FeatureSymbology.js.map +1 -1
  27. package/lib/cjs/render/GraphicBranch.d.ts +15 -9
  28. package/lib/cjs/render/GraphicBranch.d.ts.map +1 -1
  29. package/lib/cjs/render/GraphicBranch.js +38 -1
  30. package/lib/cjs/render/GraphicBranch.js.map +1 -1
  31. package/lib/cjs/render/primitives/EdgeParams.d.ts +11 -0
  32. package/lib/cjs/render/primitives/EdgeParams.d.ts.map +1 -1
  33. package/lib/cjs/render/primitives/EdgeParams.js +36 -29
  34. package/lib/cjs/render/primitives/EdgeParams.js.map +1 -1
  35. package/lib/cjs/render/primitives/VertexTable.d.ts +11 -4
  36. package/lib/cjs/render/primitives/VertexTable.d.ts.map +1 -1
  37. package/lib/cjs/render/primitives/VertexTable.js +13 -6
  38. package/lib/cjs/render/primitives/VertexTable.js.map +1 -1
  39. package/lib/cjs/render/primitives/VertexTableSplitter.d.ts +41 -0
  40. package/lib/cjs/render/primitives/VertexTableSplitter.d.ts.map +1 -0
  41. package/lib/cjs/render/primitives/VertexTableSplitter.js +662 -0
  42. package/lib/cjs/render/primitives/VertexTableSplitter.js.map +1 -0
  43. package/lib/cjs/render-primitives.d.ts +1 -0
  44. package/lib/cjs/render-primitives.d.ts.map +1 -1
  45. package/lib/cjs/render-primitives.js +1 -0
  46. package/lib/cjs/render-primitives.js.map +1 -1
  47. package/lib/cjs/tile/ClassifierTileTree.d.ts.map +1 -1
  48. package/lib/cjs/tile/ClassifierTileTree.js +8 -8
  49. package/lib/cjs/tile/ClassifierTileTree.js.map +1 -1
  50. package/lib/cjs/tile/IModelTile.d.ts.map +1 -1
  51. package/lib/cjs/tile/IModelTile.js +1 -0
  52. package/lib/cjs/tile/IModelTile.js.map +1 -1
  53. package/lib/cjs/tile/IModelTileTree.d.ts +3 -1
  54. package/lib/cjs/tile/IModelTileTree.d.ts.map +1 -1
  55. package/lib/cjs/tile/IModelTileTree.js +1 -0
  56. package/lib/cjs/tile/IModelTileTree.js.map +1 -1
  57. package/lib/cjs/tile/ImdlReader.d.ts +9 -4
  58. package/lib/cjs/tile/ImdlReader.d.ts.map +1 -1
  59. package/lib/cjs/tile/ImdlReader.js +174 -60
  60. package/lib/cjs/tile/ImdlReader.js.map +1 -1
  61. package/lib/cjs/tile/PrimaryTileTree.d.ts +7 -6
  62. package/lib/cjs/tile/PrimaryTileTree.d.ts.map +1 -1
  63. package/lib/cjs/tile/PrimaryTileTree.js +30 -25
  64. package/lib/cjs/tile/PrimaryTileTree.js.map +1 -1
  65. package/lib/cjs/tile/TileAdmin.d.ts +21 -2
  66. package/lib/cjs/tile/TileAdmin.d.ts.map +1 -1
  67. package/lib/cjs/tile/TileAdmin.js +30 -12
  68. package/lib/cjs/tile/TileAdmin.js.map +1 -1
  69. package/lib/esm/DisplayStyleState.d.ts +12 -14
  70. package/lib/esm/DisplayStyleState.d.ts.map +1 -1
  71. package/lib/esm/DisplayStyleState.js +84 -69
  72. package/lib/esm/DisplayStyleState.js.map +1 -1
  73. package/lib/esm/DrawingViewState.js +1 -1
  74. package/lib/esm/DrawingViewState.js.map +1 -1
  75. package/lib/esm/IModelConnection.js +1 -1
  76. package/lib/esm/IModelConnection.js.map +1 -1
  77. package/lib/esm/RealityDataSource.d.ts.map +1 -1
  78. package/lib/esm/RealityDataSource.js +6 -2
  79. package/lib/esm/RealityDataSource.js.map +1 -1
  80. package/lib/esm/SheetViewState.js +1 -1
  81. package/lib/esm/SheetViewState.js.map +1 -1
  82. package/lib/esm/ViewState.d.ts +1 -2
  83. package/lib/esm/ViewState.d.ts.map +1 -1
  84. package/lib/esm/ViewState.js +2 -2
  85. package/lib/esm/ViewState.js.map +1 -1
  86. package/lib/esm/Viewport.d.ts.map +1 -1
  87. package/lib/esm/Viewport.js +9 -4
  88. package/lib/esm/Viewport.js.map +1 -1
  89. package/lib/esm/core-frontend.d.ts +0 -2
  90. package/lib/esm/core-frontend.d.ts.map +1 -1
  91. package/lib/esm/core-frontend.js +0 -2
  92. package/lib/esm/core-frontend.js.map +1 -1
  93. package/lib/esm/render/FeatureSymbology.js +2 -2
  94. package/lib/esm/render/FeatureSymbology.js.map +1 -1
  95. package/lib/esm/render/GraphicBranch.d.ts +15 -9
  96. package/lib/esm/render/GraphicBranch.d.ts.map +1 -1
  97. package/lib/esm/render/GraphicBranch.js +36 -0
  98. package/lib/esm/render/GraphicBranch.js.map +1 -1
  99. package/lib/esm/render/primitives/EdgeParams.d.ts +11 -0
  100. package/lib/esm/render/primitives/EdgeParams.d.ts.map +1 -1
  101. package/lib/esm/render/primitives/EdgeParams.js +34 -28
  102. package/lib/esm/render/primitives/EdgeParams.js.map +1 -1
  103. package/lib/esm/render/primitives/VertexTable.d.ts +11 -4
  104. package/lib/esm/render/primitives/VertexTable.d.ts.map +1 -1
  105. package/lib/esm/render/primitives/VertexTable.js +14 -7
  106. package/lib/esm/render/primitives/VertexTable.js.map +1 -1
  107. package/lib/esm/render/primitives/VertexTableSplitter.d.ts +41 -0
  108. package/lib/esm/render/primitives/VertexTableSplitter.d.ts.map +1 -0
  109. package/lib/esm/render/primitives/VertexTableSplitter.js +655 -0
  110. package/lib/esm/render/primitives/VertexTableSplitter.js.map +1 -0
  111. package/lib/esm/render-primitives.d.ts +1 -0
  112. package/lib/esm/render-primitives.d.ts.map +1 -1
  113. package/lib/esm/render-primitives.js +1 -0
  114. package/lib/esm/render-primitives.js.map +1 -1
  115. package/lib/esm/tile/ClassifierTileTree.d.ts.map +1 -1
  116. package/lib/esm/tile/ClassifierTileTree.js +10 -10
  117. package/lib/esm/tile/ClassifierTileTree.js.map +1 -1
  118. package/lib/esm/tile/IModelTile.d.ts.map +1 -1
  119. package/lib/esm/tile/IModelTile.js +1 -0
  120. package/lib/esm/tile/IModelTile.js.map +1 -1
  121. package/lib/esm/tile/IModelTileTree.d.ts +3 -1
  122. package/lib/esm/tile/IModelTileTree.d.ts.map +1 -1
  123. package/lib/esm/tile/IModelTileTree.js +1 -0
  124. package/lib/esm/tile/IModelTileTree.js.map +1 -1
  125. package/lib/esm/tile/ImdlReader.d.ts +9 -4
  126. package/lib/esm/tile/ImdlReader.d.ts.map +1 -1
  127. package/lib/esm/tile/ImdlReader.js +174 -60
  128. package/lib/esm/tile/ImdlReader.js.map +1 -1
  129. package/lib/esm/tile/PrimaryTileTree.d.ts +7 -6
  130. package/lib/esm/tile/PrimaryTileTree.d.ts.map +1 -1
  131. package/lib/esm/tile/PrimaryTileTree.js +31 -26
  132. package/lib/esm/tile/PrimaryTileTree.js.map +1 -1
  133. package/lib/esm/tile/TileAdmin.d.ts +21 -2
  134. package/lib/esm/tile/TileAdmin.d.ts.map +1 -1
  135. package/lib/esm/tile/TileAdmin.js +31 -13
  136. package/lib/esm/tile/TileAdmin.js.map +1 -1
  137. package/package.json +20 -20
  138. package/lib/cjs/RenderScheduleState.d.ts +0 -24
  139. package/lib/cjs/RenderScheduleState.d.ts.map +0 -1
  140. package/lib/cjs/RenderScheduleState.js +0 -76
  141. package/lib/cjs/RenderScheduleState.js.map +0 -1
  142. package/lib/cjs/extension/providers/ExtensionServiceClient.d.ts +0 -54
  143. package/lib/cjs/extension/providers/ExtensionServiceClient.d.ts.map +0 -1
  144. package/lib/cjs/extension/providers/ExtensionServiceClient.js +0 -138
  145. package/lib/cjs/extension/providers/ExtensionServiceClient.js.map +0 -1
  146. package/lib/cjs/extension/providers/ServiceExtensionProvider.d.ts +0 -38
  147. package/lib/cjs/extension/providers/ServiceExtensionProvider.d.ts.map +0 -1
  148. package/lib/cjs/extension/providers/ServiceExtensionProvider.js +0 -73
  149. package/lib/cjs/extension/providers/ServiceExtensionProvider.js.map +0 -1
  150. package/lib/esm/RenderScheduleState.d.ts +0 -24
  151. package/lib/esm/RenderScheduleState.d.ts.map +0 -1
  152. package/lib/esm/RenderScheduleState.js +0 -71
  153. package/lib/esm/RenderScheduleState.js.map +0 -1
  154. package/lib/esm/extension/providers/ExtensionServiceClient.d.ts +0 -54
  155. package/lib/esm/extension/providers/ExtensionServiceClient.d.ts.map +0 -1
  156. package/lib/esm/extension/providers/ExtensionServiceClient.js +0 -134
  157. package/lib/esm/extension/providers/ExtensionServiceClient.js.map +0 -1
  158. package/lib/esm/extension/providers/ServiceExtensionProvider.d.ts +0 -38
  159. package/lib/esm/extension/providers/ServiceExtensionProvider.d.ts.map +0 -1
  160. package/lib/esm/extension/providers/ServiceExtensionProvider.js +0 -69
  161. package/lib/esm/extension/providers/ServiceExtensionProvider.js.map +0 -1
@@ -1,134 +0,0 @@
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";
6
- import { request } from "../../request/Request";
7
- /**
8
- * Client for querying, publishing and deleting iModel.js Extensions.
9
- *
10
- * The `imodel-extension-service-api` OIDC scope is required for all operations and the `imodel-extension-service:modify` is
11
- * required for modification operations (modify, publish, and deleting).
12
- * @alpha
13
- */
14
- export class ExtensionClient {
15
- constructor() {
16
- this._baseUrl = "https://api.bentley.com/iModelExtensionService/";
17
- }
18
- get _endpoint() {
19
- const prefix = process.env.IMJS_URL_PREFIX;
20
- const baseUrl = new URL(this._baseUrl);
21
- if (prefix)
22
- baseUrl.hostname = prefix + new URL(baseUrl).hostname;
23
- if (!baseUrl.pathname.endsWith("/"))
24
- baseUrl.pathname += "/";
25
- baseUrl.pathname += "v1.0/";
26
- return baseUrl.toString();
27
- }
28
- parseExtensionMetadataArray(json) {
29
- if (!(json instanceof Array))
30
- return [];
31
- const ret = [];
32
- json.forEach((extensionJson) => {
33
- const extension = extensionMetadataFromJSON(extensionJson);
34
- if (extension !== undefined)
35
- ret.push(extension);
36
- });
37
- return ret;
38
- }
39
- /**
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.
43
- * @param extensionName Extension name (optional)
44
- * @param iTwinId iTwin Id (optional)
45
- */
46
- async getExtensions(accessToken, extensionName, iTwinId = Guid.empty) {
47
- const options = { method: "GET" };
48
- options.headers = { authorization: accessToken };
49
- const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName !== null && extensionName !== void 0 ? extensionName : ""}`, options);
50
- if (response.status !== 200)
51
- throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);
52
- if (!(response.body instanceof Array) || response.body.length < 1)
53
- return [];
54
- return this.parseExtensionMetadataArray(response.body);
55
- }
56
- /**
57
- * Gets information about an extension's specific version
58
- * If iTwinId is undefined, will assume the extension was published publicly.
59
- * @param extensionName Extension name
60
- * @param version Extension version
61
- * @param iTwinId iTwin Id (optional)
62
- */
63
- async getExtensionMetadata(accessToken, extensionName, version, iTwinId = Guid.empty) {
64
- const options = { method: "GET" };
65
- options.headers = { authorization: accessToken };
66
- const response = await request(`${this._endpoint}${iTwinId}/IModelExtension/${extensionName}/${version}`, options);
67
- if (response.status !== 200)
68
- throw new Error(`Server returned status: ${response.status}, message: ${response.body.message}`);
69
- if (!(response.body instanceof Array) || response.body.length < 1)
70
- return undefined;
71
- if (response.body.length > 1)
72
- throw new Error("Server returned too many extensions");
73
- return extensionMetadataFromJSON(response.body[0]);
74
- }
75
- }
76
- /**
77
- * Validates JSON and returns ExtensionMetadata
78
- */
79
- function extensionMetadataFromJSON(jsonObject) {
80
- if (jsonObject.contextId === undefined || typeof jsonObject.contextId !== "string" ||
81
- jsonObject.extensionName === undefined || typeof jsonObject.extensionName !== "string" ||
82
- jsonObject.version === undefined || typeof jsonObject.version !== "string" ||
83
- jsonObject.files === undefined || !(jsonObject.files instanceof Array) ||
84
- jsonObject.uploadedBy === undefined || typeof jsonObject.uploadedBy !== "string" ||
85
- jsonObject.timestamp === undefined || typeof jsonObject.timestamp !== "string" ||
86
- jsonObject.isPublic === undefined || typeof jsonObject.isPublic !== "boolean" ||
87
- jsonObject.extensionStatus === undefined) {
88
- return undefined;
89
- }
90
- const status = statusFromJSON(jsonObject.extensionStatus);
91
- if (status === undefined)
92
- return undefined;
93
- const files = new Array(jsonObject.files.length);
94
- for (let i = 0; i < jsonObject.files.length; i++) {
95
- const parsed = fileInfoFromJSON(jsonObject.files[i]);
96
- if (parsed === undefined)
97
- return undefined;
98
- files[i] = parsed;
99
- }
100
- return {
101
- contextId: jsonObject.contextId,
102
- extensionName: jsonObject.extensionName,
103
- version: jsonObject.version,
104
- files,
105
- uploadedBy: jsonObject.uploadedBy,
106
- timestamp: new Date(jsonObject.timestamp),
107
- isPublic: jsonObject.isPublic,
108
- status,
109
- };
110
- }
111
- function statusFromJSON(jsonObject) {
112
- var _a;
113
- if (jsonObject.statusUpdateTime === undefined || typeof jsonObject.statusUpdateTime !== "string" ||
114
- jsonObject.status === undefined || (jsonObject.status !== null && typeof jsonObject.status !== "string")) {
115
- return undefined;
116
- }
117
- return {
118
- updateTime: new Date(jsonObject.statusUpdateTime),
119
- status: (_a = jsonObject.status) !== null && _a !== void 0 ? _a : "Valid",
120
- };
121
- }
122
- function fileInfoFromJSON(jsonObject) {
123
- if (jsonObject.url === undefined || typeof jsonObject.url !== "string" ||
124
- jsonObject.expiresAt === undefined || typeof jsonObject.expiresAt !== "string" ||
125
- jsonObject.checksum === undefined || (typeof jsonObject.checksum !== "string" && jsonObject.checksum !== null)) {
126
- return undefined;
127
- }
128
- return {
129
- url: jsonObject.url,
130
- expires: new Date(jsonObject.expiresAt),
131
- checksum: jsonObject.checksum,
132
- };
133
- }
134
- //# sourceMappingURL=ExtensionServiceClient.js.map
@@ -1 +0,0 @@
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,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AI,CAAC,UAAU,CAAC,SAAS,CAAC;QACzC,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,MAAM;KACP,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,UAAe;;IACrC,IAAI,UAAU,CAAC,gBAAgB,KAAK,SAAS,IAAI,OAAO,UAAU,CAAC,gBAAgB,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, 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"]}
@@ -1,38 +0,0 @@
1
- import type { ExtensionManifest, ExtensionProvider } from "../Extension";
2
- import type { AccessToken } from "@itwin/core-bentley";
3
- /**
4
- * Required props for an extension uploaded to Bentley's Extension Service
5
- * @alpha
6
- */
7
- export interface ServiceExtensionProviderProps {
8
- /** Name of the uploaded extension */
9
- name: string;
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
- /** @internal */
15
- getAccessToken?: () => Promise<AccessToken>;
16
- }
17
- /**
18
- * Implements an Extension from the Extension Service via the ServiceExtensionProviderProps.
19
- * Service extensions are extensions hosted on Bentley's Extension Service.
20
- * The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.
21
- * @alpha
22
- */
23
- export declare class ServiceExtensionProvider implements ExtensionProvider {
24
- private readonly _props;
25
- constructor(_props: ServiceExtensionProviderProps);
26
- /** Returns the extension's manifest (package.json) from the ExtensionService.
27
- * Throws an error if the manifest cannot be found.
28
- */
29
- getManifest(): Promise<ExtensionManifest>;
30
- /** Executes the javascript main file (the bundled index.js) of an extension from the Extension Service.
31
- * Throws an error if the file cannot be found.
32
- */
33
- execute(): Promise<any>;
34
- /** Fetches the extension from the ExtensionService.
35
- */
36
- private _getExtensionFiles;
37
- }
38
- //# sourceMappingURL=ServiceExtensionProvider.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,69 +0,0 @@
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 { rcompare } from "semver";
6
- import { IModelApp } from "../../IModelApp";
7
- import { request } from "../../request/Request";
8
- import { loadScript } from "./ExtensionLoadScript";
9
- import { ExtensionClient } from "./ExtensionServiceClient";
10
- /**
11
- * Implements an Extension from the Extension Service via the ServiceExtensionProviderProps.
12
- * Service extensions are extensions hosted on Bentley's Extension Service.
13
- * The execute() and getManifest() methods are used by the ExtensionAdmin to load and execute the extension.
14
- * @alpha
15
- */
16
- export class ServiceExtensionProvider {
17
- constructor(_props) {
18
- this._props = _props;
19
- }
20
- /** Returns the extension's manifest (package.json) from the ExtensionService.
21
- * Throws an error if the manifest cannot be found.
22
- */
23
- async getManifest() {
24
- const loadedExtensionProps = await this._getExtensionFiles(this._props);
25
- if (!loadedExtensionProps)
26
- throw new Error(`Error loading manifest for Extension ${this._props.name}.`);
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;
35
- }
36
- /** Executes the javascript main file (the bundled index.js) of an extension from the Extension Service.
37
- * Throws an error if the file cannot be found.
38
- */
39
- async execute() {
40
- const loadedExtensionProps = await this._getExtensionFiles(this._props);
41
- if (!loadedExtensionProps)
42
- throw new Error(`Error executing Extension ${this._props.name}.`);
43
- return loadScript(loadedExtensionProps.main.url);
44
- }
45
- /** Fetches the extension from the ExtensionService.
46
- */
47
- async _getExtensionFiles(props) {
48
- var _a, _b, _c;
49
- const extensionClient = new ExtensionClient();
50
- const accessToken = await ((_b = (_a = props.getAccessToken) === null || _a === void 0 ? void 0 : _a.call(props)) !== null && _b !== void 0 ? _b : (_c = IModelApp.authorizationClient) === null || _c === void 0 ? void 0 : _c.getAccessToken());
51
- if (!accessToken)
52
- return undefined;
53
- let extensionProps;
54
- if (props.version !== undefined)
55
- extensionProps = await extensionClient.getExtensionMetadata(accessToken, props.name, props.version, props.iTwinId);
56
- else {
57
- const propsArr = await extensionClient.getExtensions(accessToken, props.name, props.iTwinId);
58
- extensionProps = propsArr.sort((ext1, ext2) => rcompare(ext1.version, ext2.version, true))[0];
59
- }
60
- if (extensionProps === undefined || extensionProps.files.length < 1)
61
- return undefined;
62
- const manifest = extensionProps.files.find((f) => f.url.indexOf("package.json?") > -1);
63
- const main = extensionProps.files.find((f) => f.url.indexOf("index.js?") > -1);
64
- if (!manifest || !main)
65
- return undefined;
66
- return { manifest, main };
67
- }
68
- }
69
- //# sourceMappingURL=ServiceExtensionProvider.js.map
@@ -1 +0,0 @@
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,OAAO,EAAkB,MAAM,uBAAuB,CAAC;AAChE,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,GA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------------------------------------------------------------------------------------\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"]}