@itwin/core-common 4.1.0-dev.6 → 4.1.0-dev.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"BentleyCloudRpcProtocol.js","sourceRoot":"","sources":["../../../../src/rpc/web/BentleyCloudRpcProtocol.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,4CAA4C;AAE5C,IAAK,OAEJ;AAFD,WAAK,OAAO;IACV,gCAAqB,CAAA;AACvB,CAAC,EAFI,OAAO,KAAP,OAAO,QAEX;AAED;;GAEG;AACH,MAAM,OAAgB,uBAAwB,SAAQ,iBAAiB;IAAvE;;QACkB,eAAU,GAAG,IAAI,CAAC;QAElC,iFAAiF;QACjE,8CAAyC,GAA0B;YACjF,8CAA8C;YAC9C,EAAE,EAAE,kBAAkB;YAEtB,kDAAkD;YAClD,aAAa,EAAE,kBAAkB;YAEjC,uDAAuD;YACvD,kBAAkB,EAAE,uBAAuB;YAE3C,8CAA8C;YAC9C,SAAS,EAAE,cAAc;YAEzB,iDAAiD;YACjD,aAAa,EAAE,eAAe;SAC/B,CAAC;QAEF,mDAAmD;QACnC,8BAAyB,GAAG,oBAAoB,CAAC;IA6GnE,CAAC;IA3GC,yEAAyE;IACzD,oBAAoB,CAAC,IAAY;QAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;QAChD,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,KA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,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YAC1E,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YAC3E,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YAC5E,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;SACjF,CAAC;IACJ,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 RpcInterface\r\n */\r\n\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { IModelError } from \"../../IModelError\";\r\nimport { RpcConfiguration } from \"../core/RpcConfiguration\";\r\nimport { RpcOperation } from \"../core/RpcOperation\";\r\nimport { SerializedRpcOperation, SerializedRpcRequest } from \"../core/RpcProtocol\";\r\nimport { RpcRequest } from \"../core/RpcRequest\";\r\nimport { OpenAPIParameter } from \"./OpenAPI\";\r\nimport { WebAppRpcProtocol } from \"./WebAppRpcProtocol\";\r\nimport { SerializedRpcActivity } from \"../core/RpcInvocation\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nenum AppMode {\r\n MilestoneReview = \"1\",\r\n}\r\n\r\n/** An http protocol for Bentley cloud RPC interface deployments.\r\n * @internal\r\n */\r\nexport abstract class BentleyCloudRpcProtocol extends WebAppRpcProtocol {\r\n public override checkToken = true;\r\n\r\n /** The name of various HTTP request headers based on client's request context */\r\n public override serializedClientRequestContextHeaderNames: SerializedRpcActivity = {\r\n /** The name of the HTTP request id header. */\r\n id: \"X-Correlation-Id\",\r\n\r\n /** The name of the HTTP application id header. */\r\n applicationId: \"X-Application-Id\",\r\n\r\n /** The name of the HTTP application version header. */\r\n applicationVersion: \"X-Application-Version\",\r\n\r\n /** The name of the HTTP session id header. */\r\n sessionId: \"X-Session-Id\",\r\n\r\n /** The name of the HTTP authorization header. */\r\n authorization: \"Authorization\",\r\n };\r\n\r\n /** The name of the RPC protocol version header. */\r\n public override protocolVersionHeaderName = \"X-Protocol-Version\";\r\n\r\n /** Returns the operation specified by an OpenAPI-compatible URI path. */\r\n public override getOperationFromPath(path: string): SerializedRpcOperation {\r\n const url = new URL(path, \"https://localhost/\");\r\n const components = url.pathname.split(\"/\").filter((x) => x); // filter out empty segments\r\n\r\n const operationComponent = components.slice(-1)[0];\r\n const encodedRequest = url.searchParams.get(\"parameters\") || \"\";\r\n\r\n // The encodedRequest should be base64 - fail now if any other characters detected.\r\n if (/[^A-z0-9=+\\/]/.test(encodedRequest))\r\n throw new IModelError(BentleyStatus.ERROR, `Invalid request: Malformed URL parameters detected.`);\r\n\r\n const firstHyphen = operationComponent.indexOf(\"-\");\r\n const lastHyphen = operationComponent.lastIndexOf(\"-\");\r\n const interfaceDefinition = operationComponent.slice(0, firstHyphen);\r\n const interfaceVersion = operationComponent.slice(firstHyphen + 1, lastHyphen);\r\n const operationName = operationComponent.slice(lastHyphen + 1);\r\n\r\n return { interfaceDefinition, operationName, interfaceVersion, encodedRequest };\r\n }\r\n\r\n /** Supplies the OpenAPI-compatible URI path for an RPC operation. */\r\n public override supplyPathForOperation(operation: RpcOperation, request: RpcRequest | undefined) {\r\n const prefix = this.pathPrefix;\r\n const appTitle = this.info.title;\r\n const appVersion = this.info.version;\r\n const operationId = `${operation.interfaceDefinition.interfaceName}-${operation.interfaceVersion}-${operation.operationName}`;\r\n\r\n let appMode: string = \"\";\r\n let iTwinId: string = \"\";\r\n let iModelId: string = \"\";\r\n let routeChangesetId: string | undefined;\r\n /* Note: The changesetId field is omitted in the route in the case of ReadWrite connections since the connection is generally expected to be at the\r\n * latest version and not some specific changeset. Also, for the first version (before any changesets), the changesetId in the route is arbitrarily\r\n * set to \"0\" instead of an empty string, since the latter is more un-intuitive for a route. However, in all other use cases, including the changesetId\r\n * held by the IModelRpcProps itself, the changesetId of \"\" (i.e., empty string) signifies the first version - this is more intuitive and retains\r\n * compatibility with the majority of use cases. */\r\n\r\n if (request === undefined) {\r\n appMode = \"{modeId}\";\r\n iTwinId = \"{iTwinId}\";\r\n iModelId = \"{iModelId}\";\r\n routeChangesetId = \"{changeSetId}\";\r\n } else {\r\n let token = operation.policy.token(request) || RpcOperation.fallbackToken;\r\n\r\n if (!token || !token.iModelId) {\r\n if (RpcConfiguration.disableRoutingValidation) {\r\n token = { key: \"\" };\r\n } else {\r\n throw new IModelError(BentleyStatus.ERROR, \"Invalid iModelToken for RPC operation request\");\r\n }\r\n }\r\n\r\n iTwinId = encodeURIComponent(token.iTwinId || \"\");\r\n iModelId = encodeURIComponent(token.iModelId!);\r\n\r\n routeChangesetId = token.changeset?.id || \"0\";\r\n appMode = AppMode.MilestoneReview;\r\n }\r\n\r\n return `${prefix}/${appTitle}/${appVersion}/mode/${appMode}/context/${iTwinId}/imodel/${iModelId}${!!routeChangesetId ? `/changeset/${routeChangesetId}` : \"\"}/${operationId}`;\r\n }\r\n\r\n /**\r\n * Inflates the IModelRpcProps from the URL path for each request on the backend.\r\n * @note This function updates the IModelRpcProps value supplied in the request body.\r\n */\r\n public override inflateToken(tokenFromBody: IModelRpcProps, request: SerializedRpcRequest): IModelRpcProps {\r\n const urlPathComponents = request.path.split(\"/\");\r\n\r\n const iModelKey = tokenFromBody.key;\r\n let iModelId = tokenFromBody.iModelId;\r\n let iTwinId = tokenFromBody.iTwinId;\r\n const changeset = { id: tokenFromBody.changeset?.id ?? \"0\", index: tokenFromBody.changeset?.index };\r\n\r\n for (let i = 0; i <= urlPathComponents.length; ++i) {\r\n const key = urlPathComponents[i];\r\n const value = urlPathComponents[i + 1];\r\n if (key === \"mode\") {\r\n ++i;\r\n } else if (key === \"context\") {\r\n iTwinId = value;\r\n ++i;\r\n } else if (key === \"imodel\") {\r\n iModelId = value;\r\n ++i;\r\n } else if (key === \"changeset\") {\r\n changeset.id = (value === \"0\") ? \"\" : value;\r\n ++i;\r\n }\r\n }\r\n\r\n return { key: iModelKey, iTwinId, iModelId, changeset };\r\n }\r\n\r\n /** Returns the OpenAPI-compatible URI path parameters for an RPC operation.\r\n * @internal\r\n */\r\n public supplyPathParametersForOperation(_operation: RpcOperation): OpenAPIParameter[] {\r\n return [\r\n { name: \"modeId\", in: \"path\", required: true, schema: { type: \"string\" } },\r\n { name: \"iTwinId\", in: \"path\", required: true, schema: { type: \"string\" } },\r\n { name: \"iModelId\", in: \"path\", required: true, schema: { type: \"string\" } },\r\n { name: \"changeSetId\", in: \"path\", required: false, schema: { type: \"string\" } },\r\n ];\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"BentleyCloudRpcProtocol.js","sourceRoot":"","sources":["../../../../src/rpc/web/BentleyCloudRpcProtocol.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,4CAA4C;AAE5C,IAAK,OAEJ;AAFD,WAAK,OAAO;IACV,gCAAqB,CAAA;AACvB,CAAC,EAFI,OAAO,KAAP,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,MAAM,EAAE;gBAClB,EAAE,CAAC,CAAC;aACL;iBAAM,IAAI,GAAG,KAAK,SAAS,EAAE;gBAC5B,OAAO,GAAG,KAAK,CAAC;gBAChB,EAAE,CAAC,CAAC;aACL;iBAAM,IAAI,GAAG,KAAK,QAAQ,EAAE;gBAC3B,QAAQ,GAAG,KAAK,CAAC;gBACjB,EAAE,CAAC,CAAC;aACL;iBAAM,IAAI,GAAG,KAAK,WAAW,EAAE;gBAC9B,SAAS,CAAC,EAAE,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;gBAC5C,EAAE,CAAC,CAAC;aACL;SACF;QAED,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IAC1D,CAAC;IAED;;OAEG;IACI,gCAAgC,CAAC,UAAwB;QAC9D,OAAO;YACL,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YAC1E,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YAC3E,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YAC5E,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;SACjF,CAAC;IACJ,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 RpcInterface\r\n */\r\n\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { IModelRpcProps } from \"../../IModel\";\r\nimport { IModelError } from \"../../IModelError\";\r\nimport { RpcConfiguration } from \"../core/RpcConfiguration\";\r\nimport { RpcOperation } from \"../core/RpcOperation\";\r\nimport { SerializedRpcOperation, SerializedRpcRequest } from \"../core/RpcProtocol\";\r\nimport { RpcRequest } from \"../core/RpcRequest\";\r\nimport { OpenAPIParameter } from \"./OpenAPI\";\r\nimport { WebAppRpcProtocol } from \"./WebAppRpcProtocol\";\r\nimport { SerializedRpcActivity } from \"../core/RpcInvocation\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nenum AppMode {\r\n MilestoneReview = \"1\",\r\n}\r\n\r\n/** An http protocol for Bentley cloud RPC interface deployments.\r\n * @internal\r\n */\r\nexport abstract class BentleyCloudRpcProtocol extends WebAppRpcProtocol {\r\n public override checkToken = true;\r\n\r\n /** The name of various HTTP request headers based on client's request context */\r\n public override serializedClientRequestContextHeaderNames: SerializedRpcActivity = {\r\n /** The name of the HTTP request id header. */\r\n id: \"X-Correlation-Id\",\r\n\r\n /** The name of the HTTP application id header. */\r\n applicationId: \"X-Application-Id\",\r\n\r\n /** The name of the HTTP application version header. */\r\n applicationVersion: \"X-Application-Version\",\r\n\r\n /** The name of the HTTP session id header. */\r\n sessionId: \"X-Session-Id\",\r\n\r\n /** The name of the HTTP authorization header. */\r\n authorization: \"Authorization\",\r\n };\r\n\r\n /** The name of the RPC protocol version header. */\r\n public override protocolVersionHeaderName = \"X-Protocol-Version\";\r\n\r\n /** Returns the operation specified by an OpenAPI-compatible URI path. */\r\n public override getOperationFromPath(path: string): SerializedRpcOperation {\r\n const url = new URL(path, \"https://localhost/\");\r\n const components = url.pathname.split(\"/\").filter((x) => x); // filter out empty segments\r\n\r\n const operationComponent = components.slice(-1)[0];\r\n const encodedRequest = url.searchParams.get(\"parameters\") || \"\";\r\n\r\n // The encodedRequest should be base64 - fail now if any other characters detected.\r\n if (/[^a-zA-Z0-9=+\\/$]/.test(encodedRequest))\r\n throw new IModelError(BentleyStatus.ERROR, `Invalid request: Malformed URL parameters detected.`);\r\n\r\n const firstHyphen = operationComponent.indexOf(\"-\");\r\n const lastHyphen = operationComponent.lastIndexOf(\"-\");\r\n const interfaceDefinition = operationComponent.slice(0, firstHyphen);\r\n const interfaceVersion = operationComponent.slice(firstHyphen + 1, lastHyphen);\r\n const operationName = operationComponent.slice(lastHyphen + 1);\r\n\r\n return { interfaceDefinition, operationName, interfaceVersion, encodedRequest };\r\n }\r\n\r\n /** Supplies the OpenAPI-compatible URI path for an RPC operation. */\r\n public override supplyPathForOperation(operation: RpcOperation, request: RpcRequest | undefined) {\r\n const prefix = this.pathPrefix;\r\n const appTitle = this.info.title;\r\n const appVersion = this.info.version;\r\n const operationId = `${operation.interfaceDefinition.interfaceName}-${operation.interfaceVersion}-${operation.operationName}`;\r\n\r\n let appMode: string = \"\";\r\n let iTwinId: string = \"\";\r\n let iModelId: string = \"\";\r\n let routeChangesetId: string | undefined;\r\n /* Note: The changesetId field is omitted in the route in the case of ReadWrite connections since the connection is generally expected to be at the\r\n * latest version and not some specific changeset. Also, for the first version (before any changesets), the changesetId in the route is arbitrarily\r\n * set to \"0\" instead of an empty string, since the latter is more un-intuitive for a route. However, in all other use cases, including the changesetId\r\n * held by the IModelRpcProps itself, the changesetId of \"\" (i.e., empty string) signifies the first version - this is more intuitive and retains\r\n * compatibility with the majority of use cases. */\r\n\r\n if (request === undefined) {\r\n appMode = \"{modeId}\";\r\n iTwinId = \"{iTwinId}\";\r\n iModelId = \"{iModelId}\";\r\n routeChangesetId = \"{changeSetId}\";\r\n } else {\r\n let token = operation.policy.token(request) || RpcOperation.fallbackToken;\r\n\r\n if (!token || !token.iModelId) {\r\n if (RpcConfiguration.disableRoutingValidation) {\r\n token = { key: \"\" };\r\n } else {\r\n throw new IModelError(BentleyStatus.ERROR, \"Invalid iModelToken for RPC operation request\");\r\n }\r\n }\r\n\r\n iTwinId = encodeURIComponent(token.iTwinId || \"\");\r\n iModelId = encodeURIComponent(token.iModelId!);\r\n\r\n routeChangesetId = token.changeset?.id || \"0\";\r\n appMode = AppMode.MilestoneReview;\r\n }\r\n\r\n return `${prefix}/${appTitle}/${appVersion}/mode/${appMode}/context/${iTwinId}/imodel/${iModelId}${!!routeChangesetId ? `/changeset/${routeChangesetId}` : \"\"}/${operationId}`;\r\n }\r\n\r\n /**\r\n * Inflates the IModelRpcProps from the URL path for each request on the backend.\r\n * @note This function updates the IModelRpcProps value supplied in the request body.\r\n */\r\n public override inflateToken(tokenFromBody: IModelRpcProps, request: SerializedRpcRequest): IModelRpcProps {\r\n const urlPathComponents = request.path.split(\"/\");\r\n\r\n const iModelKey = tokenFromBody.key;\r\n let iModelId = tokenFromBody.iModelId;\r\n let iTwinId = tokenFromBody.iTwinId;\r\n const changeset = { id: tokenFromBody.changeset?.id ?? \"0\", index: tokenFromBody.changeset?.index };\r\n\r\n for (let i = 0; i <= urlPathComponents.length; ++i) {\r\n const key = urlPathComponents[i];\r\n const value = urlPathComponents[i + 1];\r\n if (key === \"mode\") {\r\n ++i;\r\n } else if (key === \"context\") {\r\n iTwinId = value;\r\n ++i;\r\n } else if (key === \"imodel\") {\r\n iModelId = value;\r\n ++i;\r\n } else if (key === \"changeset\") {\r\n changeset.id = (value === \"0\") ? \"\" : value;\r\n ++i;\r\n }\r\n }\r\n\r\n return { key: iModelKey, iTwinId, iModelId, changeset };\r\n }\r\n\r\n /** Returns the OpenAPI-compatible URI path parameters for an RPC operation.\r\n * @internal\r\n */\r\n public supplyPathParametersForOperation(_operation: RpcOperation): OpenAPIParameter[] {\r\n return [\r\n { name: \"modeId\", in: \"path\", required: true, schema: { type: \"string\" } },\r\n { name: \"iTwinId\", in: \"path\", required: true, schema: { type: \"string\" } },\r\n { name: \"iModelId\", in: \"path\", required: true, schema: { type: \"string\" } },\r\n { name: \"changeSetId\", in: \"path\", required: false, schema: { type: \"string\" } },\r\n ];\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-common",
3
- "version": "4.1.0-dev.6",
3
+ "version": "4.1.0-dev.7",
4
4
  "description": "iTwin.js components common to frontend and backend",
5
5
  "main": "lib/cjs/core-common.js",
6
6
  "module": "lib/esm/core-common.js",
@@ -28,8 +28,8 @@
28
28
  "js-base64": "^3.6.1"
29
29
  },
30
30
  "peerDependencies": {
31
- "@itwin/core-bentley": "^4.1.0-dev.6",
32
- "@itwin/core-geometry": "^4.1.0-dev.6"
31
+ "@itwin/core-bentley": "^4.1.0-dev.7",
32
+ "@itwin/core-geometry": "^4.1.0-dev.7"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@itwin/eslint-plugin": "^4.0.0-dev.33",
@@ -43,9 +43,9 @@
43
43
  "nyc": "^15.1.0",
44
44
  "rimraf": "^3.0.2",
45
45
  "typescript": "~5.0.2",
46
- "@itwin/build-tools": "4.1.0-dev.6",
47
- "@itwin/core-bentley": "4.1.0-dev.6",
48
- "@itwin/core-geometry": "4.1.0-dev.6"
46
+ "@itwin/build-tools": "4.1.0-dev.7",
47
+ "@itwin/core-bentley": "4.1.0-dev.7",
48
+ "@itwin/core-geometry": "4.1.0-dev.7"
49
49
  },
50
50
  "nyc": {
51
51
  "extends": "./node_modules/@itwin/build-tools/.nycrc",