@itwin/core-common 3.4.0-dev.3 → 3.4.0-dev.33

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 (70) hide show
  1. package/CHANGELOG.md +38 -1
  2. package/lib/cjs/Code.d.ts +10 -4
  3. package/lib/cjs/Code.d.ts.map +1 -1
  4. package/lib/cjs/Code.js +2 -1
  5. package/lib/cjs/Code.js.map +1 -1
  6. package/lib/cjs/ECSchemaProps.d.ts +40 -0
  7. package/lib/cjs/ECSchemaProps.d.ts.map +1 -0
  8. package/lib/cjs/ECSchemaProps.js +10 -0
  9. package/lib/cjs/ECSchemaProps.js.map +1 -0
  10. package/lib/cjs/ElementProps.d.ts +6 -0
  11. package/lib/cjs/ElementProps.d.ts.map +1 -1
  12. package/lib/cjs/ElementProps.js.map +1 -1
  13. package/lib/cjs/Gradient.d.ts +18 -2
  14. package/lib/cjs/Gradient.d.ts.map +1 -1
  15. package/lib/cjs/Gradient.js +29 -18
  16. package/lib/cjs/Gradient.js.map +1 -1
  17. package/lib/cjs/ThematicDisplay.d.ts +6 -10
  18. package/lib/cjs/ThematicDisplay.d.ts.map +1 -1
  19. package/lib/cjs/ThematicDisplay.js.map +1 -1
  20. package/lib/cjs/core-common.d.ts +1 -0
  21. package/lib/cjs/core-common.d.ts.map +1 -1
  22. package/lib/cjs/core-common.js +1 -0
  23. package/lib/cjs/core-common.js.map +1 -1
  24. package/lib/cjs/ipc/IpcWebSocket.d.ts +3 -0
  25. package/lib/cjs/ipc/IpcWebSocket.d.ts.map +1 -1
  26. package/lib/cjs/ipc/IpcWebSocket.js +28 -14
  27. package/lib/cjs/ipc/IpcWebSocket.js.map +1 -1
  28. package/lib/cjs/rpc/web/BentleyCloudRpcProtocol.d.ts.map +1 -1
  29. package/lib/cjs/rpc/web/BentleyCloudRpcProtocol.js +3 -0
  30. package/lib/cjs/rpc/web/BentleyCloudRpcProtocol.js.map +1 -1
  31. package/lib/cjs/rpc/web/WebAppRpcProtocol.d.ts.map +1 -1
  32. package/lib/cjs/rpc/web/WebAppRpcProtocol.js +13 -1
  33. package/lib/cjs/rpc/web/WebAppRpcProtocol.js.map +1 -1
  34. package/lib/cjs/rpc/web/WebAppRpcRequest.js +1 -1
  35. package/lib/cjs/rpc/web/WebAppRpcRequest.js.map +1 -1
  36. package/lib/esm/Code.d.ts +10 -4
  37. package/lib/esm/Code.d.ts.map +1 -1
  38. package/lib/esm/Code.js +2 -1
  39. package/lib/esm/Code.js.map +1 -1
  40. package/lib/esm/ECSchemaProps.d.ts +40 -0
  41. package/lib/esm/ECSchemaProps.d.ts.map +1 -0
  42. package/lib/esm/ECSchemaProps.js +9 -0
  43. package/lib/esm/ECSchemaProps.js.map +1 -0
  44. package/lib/esm/ElementProps.d.ts +6 -0
  45. package/lib/esm/ElementProps.d.ts.map +1 -1
  46. package/lib/esm/ElementProps.js.map +1 -1
  47. package/lib/esm/Gradient.d.ts +18 -2
  48. package/lib/esm/Gradient.d.ts.map +1 -1
  49. package/lib/esm/Gradient.js +29 -18
  50. package/lib/esm/Gradient.js.map +1 -1
  51. package/lib/esm/ThematicDisplay.d.ts +6 -10
  52. package/lib/esm/ThematicDisplay.d.ts.map +1 -1
  53. package/lib/esm/ThematicDisplay.js.map +1 -1
  54. package/lib/esm/core-common.d.ts +1 -0
  55. package/lib/esm/core-common.d.ts.map +1 -1
  56. package/lib/esm/core-common.js +1 -0
  57. package/lib/esm/core-common.js.map +1 -1
  58. package/lib/esm/ipc/IpcWebSocket.d.ts +3 -0
  59. package/lib/esm/ipc/IpcWebSocket.d.ts.map +1 -1
  60. package/lib/esm/ipc/IpcWebSocket.js +28 -14
  61. package/lib/esm/ipc/IpcWebSocket.js.map +1 -1
  62. package/lib/esm/rpc/web/BentleyCloudRpcProtocol.d.ts.map +1 -1
  63. package/lib/esm/rpc/web/BentleyCloudRpcProtocol.js +3 -0
  64. package/lib/esm/rpc/web/BentleyCloudRpcProtocol.js.map +1 -1
  65. package/lib/esm/rpc/web/WebAppRpcProtocol.d.ts.map +1 -1
  66. package/lib/esm/rpc/web/WebAppRpcProtocol.js +13 -1
  67. package/lib/esm/rpc/web/WebAppRpcProtocol.js.map +1 -1
  68. package/lib/esm/rpc/web/WebAppRpcRequest.js +1 -1
  69. package/lib/esm/rpc/web/WebAppRpcRequest.js.map +1 -1
  70. package/package.json +8 -8
@@ -103,6 +103,7 @@ class IpcWebSocketBackend extends IpcWebSocket {
103
103
  constructor() {
104
104
  super();
105
105
  this._handlers = new Map();
106
+ this._processingQueue = [];
106
107
  IpcWebSocket.receivers.add(async (e, m) => this.dispatch(e, m));
107
108
  }
108
109
  send(channel, ...data) {
@@ -116,22 +117,35 @@ class IpcWebSocketBackend extends IpcWebSocket {
116
117
  };
117
118
  }
118
119
  async dispatch(_evt, message) {
119
- if (message.type !== IpcWebSocketMessageType.Invoke || !message.method)
120
+ if (message.type !== IpcWebSocketMessageType.Invoke)
120
121
  return;
121
- const handler = this._handlers.get(message.channel);
122
- if (!handler)
122
+ this._processingQueue.push(message);
123
+ await this.processMessages();
124
+ }
125
+ async processMessages() {
126
+ if (this._processing || !this._processingQueue.length) {
123
127
  return;
124
- let args = message.data;
125
- if (typeof (args) === "undefined")
126
- args = [];
127
- const response = await handler({}, message.method, ...args);
128
- IpcWebSocket.transport.send({
129
- type: IpcWebSocketMessageType.Response,
130
- channel: message.channel,
131
- response: message.request,
132
- data: response,
133
- sequence: -1,
134
- });
128
+ }
129
+ const message = this._processingQueue.shift();
130
+ if (message && message.method) {
131
+ const handler = this._handlers.get(message.channel);
132
+ if (handler) {
133
+ this._processing = message;
134
+ let args = message.data;
135
+ if (typeof (args) === "undefined")
136
+ args = [];
137
+ const response = await handler({}, message.method, ...args);
138
+ IpcWebSocket.transport.send({
139
+ type: IpcWebSocketMessageType.Response,
140
+ channel: message.channel,
141
+ response: message.request,
142
+ data: response,
143
+ sequence: -1,
144
+ });
145
+ this._processing = undefined;
146
+ }
147
+ }
148
+ await this.processMessages();
135
149
  }
136
150
  }
137
151
  exports.IpcWebSocketBackend = IpcWebSocketBackend;
@@ -1 +1 @@
1
- {"version":3,"file":"IpcWebSocket.js","sourceRoot":"","sources":["../../../src/ipc/IpcWebSocket.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAKH,gBAAgB;AAChB,IAAY,uBAOX;AAPD,WAAY,uBAAuB;IACjC,qEAAI,CAAA;IACJ,qEAAI,CAAA;IACJ,yEAAM,CAAA;IACN,6EAAQ,CAAA;IACR,6EAAQ,CAAA;IACR,+EAAS,CAAA;AACX,CAAC,EAPW,uBAAuB,GAAvB,+BAAuB,KAAvB,+BAAuB,QAOlC;AAaD,gBAAgB;AAChB,IAAiB,mBAAmB,CAYnC;AAZD,WAAiB,mBAAmB;IAClC,SAAgB,QAAQ;QACtB,OAAO,EAAE,IAAI,EAAE,uBAAuB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC;IACpG,CAAC;IAFe,4BAAQ,WAEvB,CAAA;IAED,SAAgB,SAAS;QACvB,OAAO,EAAE,IAAI,EAAE,uBAAuB,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC;IACrG,CAAC;IAFe,6BAAS,YAExB,CAAA;IAED,SAAgB,IAAI,CAAC,OAA4B;QAC/C,OAAO,OAAO,CAAC,IAAI,KAAK,uBAAuB,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,KAAK,uBAAuB,CAAC,SAAS,CAAC;IACjH,CAAC;IAFe,wBAAI,OAEnB,CAAA;AACH,CAAC,EAZgB,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAYnC;AAED,gBAAgB;AAChB,MAAsB,YAAY;IAMhC;QAFU,cAAS,GAAG,IAAI,GAAG,EAA4B,CAAC;QAGxD,YAAY,CAAC,SAAS,CAAC,GAAG,CAAC,K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AAC,OAAO,CAAC,MAAM;YACpE,OAAO;QAET,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO;YACV,OAAO;QAET,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACxB,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,WAAW;YAC/B,IAAI,GAAG,EAAE,CAAC;QAEZ,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,EAAS,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;QAEnE,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC;YAC1B,IAAI,EAAE,uBAAuB,CAAC,QAAQ;YACtC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,QAAQ,EAAE,OAAO,CAAC,OAAO;YACzB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,CAAC;SACb,CAAC,CAAC;IACL,CAAC;CACF;AA3CD,kDA2CC","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 IpcSocket\r\n */\r\n\r\nimport { IpcListener, IpcSocket, IpcSocketBackend, IpcSocketFrontend, RemoveFunction } from \"./IpcSocket\";\r\nimport { IpcWebSocketTransport } from \"./IpcWebSocketTransport\";\r\n\r\n/** @internal */\r\nexport enum IpcWebSocketMessageType {\r\n Send,\r\n Push,\r\n Invoke,\r\n Response,\r\n Internal,\r\n Duplicate\r\n}\r\n\r\n/** @internal */\r\nexport interface IpcWebSocketMessage {\r\n type: IpcWebSocketMessageType;\r\n request?: number;\r\n response?: number;\r\n channel: string;\r\n method?: string;\r\n data?: any[];\r\n sequence: number;\r\n}\r\n\r\n/** @internal */\r\nexport namespace IpcWebSocketMessage {\r\n export function internal(): IpcWebSocketMessage {\r\n return { type: IpcWebSocketMessageType.Internal, channel: \"\", sequence: Number.MIN_SAFE_INTEGER };\r\n }\r\n\r\n export function duplicate(): IpcWebSocketMessage {\r\n return { type: IpcWebSocketMessageType.Duplicate, channel: \"\", sequence: Number.MIN_SAFE_INTEGER };\r\n }\r\n\r\n export function skip(message: IpcWebSocketMessage): boolean {\r\n return message.type === IpcWebSocketMessageType.Internal || message.type === IpcWebSocketMessageType.Duplicate;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport abstract class IpcWebSocket implements IpcSocket {\r\n public static transport: IpcWebSocketTransport;\r\n public static receivers: Set<(evt: Event, message: IpcWebSocketMessage) => void> = new Set();\r\n\r\n protected _channels = new Map<string, Set<IpcListener>>();\r\n\r\n public constructor() {\r\n IpcWebSocket.receivers.add(async (e, m) => this.broadcast(e, m));\r\n }\r\n\r\n public abstract send(channel: string, ...data: any[]): void;\r\n\r\n public addListener(channel: string, listener: IpcListener): RemoveFunction {\r\n let listeners = this._channels.get(channel);\r\n if (!listeners) {\r\n listeners = new Set();\r\n this._channels.set(channel, listeners);\r\n }\r\n\r\n if (!listeners.has(listener))\r\n listeners.add(listener);\r\n\r\n return () => listeners!.delete(listener);\r\n }\r\n\r\n public removeListener(channel: string, listener: IpcListener) {\r\n this._channels.get(channel)?.delete(listener);\r\n }\r\n\r\n private async broadcast(evt: Event, message: IpcWebSocketMessage) {\r\n if (message.type !== IpcWebSocketMessageType.Send && message.type !== IpcWebSocketMessageType.Push)\r\n return;\r\n\r\n const handlers = this._channels.get(message.channel);\r\n if (!handlers)\r\n return;\r\n\r\n let arg = message.data;\r\n if (typeof (arg) === \"undefined\")\r\n arg = [];\r\n\r\n for (const handler of handlers)\r\n handler(evt, ...arg);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class IpcWebSocketFrontend extends IpcWebSocket implements IpcSocketFrontend {\r\n private _nextRequest = 0;\r\n private _pendingRequests = new Map<number, (response: any) => void>();\r\n\r\n public constructor() {\r\n super();\r\n IpcWebSocket.receivers.add(async (e, m) => this.dispatch(e, m));\r\n }\r\n\r\n public send(channel: string, ...data: any[]): void {\r\n IpcWebSocket.transport.send({ type: IpcWebSocketMessageType.Send, channel, data, sequence: -1 });\r\n }\r\n\r\n public async invoke(channel: string, methodName: string, ...args: any[]): Promise<any> {\r\n const requestId = ++this._nextRequest;\r\n IpcWebSocket.transport.send({ type: IpcWebSocketMessageType.Invoke, channel, method: methodName, data: args, request: requestId, sequence: -1 });\r\n\r\n return new Promise((resolve) => {\r\n this._pendingRequests.set(requestId, resolve);\r\n });\r\n }\r\n\r\n private async dispatch(_evt: Event, message: IpcWebSocketMessage) {\r\n if (message.type !== IpcWebSocketMessageType.Response || !message.response)\r\n return;\r\n\r\n const pendingHandler = this._pendingRequests.get(message.response);\r\n if (!pendingHandler)\r\n return;\r\n\r\n this._pendingRequests.delete(message.response);\r\n pendingHandler(message.data);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class IpcWebSocketBackend extends IpcWebSocket implements IpcSocketBackend {\r\n private _handlers = new Map<string, (event: Event, methodName: string, ...args: any[]) => Promise<any>>();\r\n\r\n public constructor() {\r\n super();\r\n IpcWebSocket.receivers.add(async (e, m) => this.dispatch(e, m));\r\n }\r\n\r\n public send(channel: string, ...data: any[]): void {\r\n IpcWebSocket.transport.send({ type: IpcWebSocketMessageType.Push, channel, data, sequence: -1 });\r\n }\r\n\r\n public handle(channel: string, handler: (event: Event, methodName: string, ...args: any[]) => Promise<any>): RemoveFunction {\r\n this._handlers.set(channel, handler);\r\n\r\n return () => {\r\n if (this._handlers.get(channel) === handler)\r\n this._handlers.delete(channel);\r\n };\r\n }\r\n\r\n private async dispatch(_evt: Event, message: IpcWebSocketMessage) {\r\n if (message.type !== IpcWebSocketMessageType.Invoke || !message.method)\r\n return;\r\n\r\n const handler = this._handlers.get(message.channel);\r\n if (!handler)\r\n return;\r\n\r\n let args = message.data;\r\n if (typeof (args) === \"undefined\")\r\n args = [];\r\n\r\n const response = await handler({} as any, message.method, ...args);\r\n\r\n IpcWebSocket.transport.send({\r\n type: IpcWebSocketMessageType.Response,\r\n channel: message.channel,\r\n response: message.request,\r\n data: response,\r\n sequence: -1,\r\n });\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"IpcWebSocket.js","sourceRoot":"","sources":["../../../src/ipc/IpcWebSocket.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAKH,gBAAgB;AAChB,IAAY,uBAOX;AAPD,WAAY,uBAAuB;IACjC,qEAAI,CAAA;IACJ,qEAAI,CAAA;IACJ,yEAAM,CAAA;IACN,6EAAQ,CAAA;IACR,6EAAQ,CAAA;IACR,+EAAS,CAAA;AACX,CAAC,EAPW,uBAAuB,GAAvB,+BAAuB,KAAvB,+BAAuB,QAOlC;AAaD,gBAAgB;AAChB,IAAiB,mBAAmB,CAYnC;AAZD,WAAiB,mBAAmB;IAClC,SAAgB,QAAQ;QACtB,OAAO,EAAE,IAAI,EAAE,uBAAuB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC;IACpG,CAAC;IAFe,4BAAQ,WAEvB,CAAA;IAED,SAAgB,SAAS;QACvB,OAAO,EAAE,IAAI,EAAE,uBAAuB,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC;IACrG,CAAC;IAFe,6BAAS,YAExB,CAAA;IAED,SAAgB,IAAI,CAAC,OAA4B;QAC/C,OAAO,OAAO,CAAC,IAAI,KAAK,uBAAuB,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,KAAK,uBAAuB,CAAC,SAAS,CAAC;IACjH,CAAC;IAFe,wBAAI,OAEnB,CAAA;AACH,CAAC,EAZgB,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAYnC;AAED,gBAAgB;AAChB,MAAsB,YAAY;IAM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;AA9DD,kDA8DC","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 IpcSocket\r\n */\r\n\r\nimport { IpcListener, IpcSocket, IpcSocketBackend, IpcSocketFrontend, RemoveFunction } from \"./IpcSocket\";\r\nimport { IpcWebSocketTransport } from \"./IpcWebSocketTransport\";\r\n\r\n/** @internal */\r\nexport enum IpcWebSocketMessageType {\r\n Send,\r\n Push,\r\n Invoke,\r\n Response,\r\n Internal,\r\n Duplicate\r\n}\r\n\r\n/** @internal */\r\nexport interface IpcWebSocketMessage {\r\n type: IpcWebSocketMessageType;\r\n request?: number;\r\n response?: number;\r\n channel: string;\r\n method?: string;\r\n data?: any[];\r\n sequence: number;\r\n}\r\n\r\n/** @internal */\r\nexport namespace IpcWebSocketMessage {\r\n export function internal(): IpcWebSocketMessage {\r\n return { type: IpcWebSocketMessageType.Internal, channel: \"\", sequence: Number.MIN_SAFE_INTEGER };\r\n }\r\n\r\n export function duplicate(): IpcWebSocketMessage {\r\n return { type: IpcWebSocketMessageType.Duplicate, channel: \"\", sequence: Number.MIN_SAFE_INTEGER };\r\n }\r\n\r\n export function skip(message: IpcWebSocketMessage): boolean {\r\n return message.type === IpcWebSocketMessageType.Internal || message.type === IpcWebSocketMessageType.Duplicate;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport abstract class IpcWebSocket implements IpcSocket {\r\n public static transport: IpcWebSocketTransport;\r\n public static receivers: Set<(evt: Event, message: IpcWebSocketMessage) => void> = new Set();\r\n\r\n protected _channels = new Map<string, Set<IpcListener>>();\r\n\r\n public constructor() {\r\n IpcWebSocket.receivers.add(async (e, m) => this.broadcast(e, m));\r\n }\r\n\r\n public abstract send(channel: string, ...data: any[]): void;\r\n\r\n public addListener(channel: string, listener: IpcListener): RemoveFunction {\r\n let listeners = this._channels.get(channel);\r\n if (!listeners) {\r\n listeners = new Set();\r\n this._channels.set(channel, listeners);\r\n }\r\n\r\n if (!listeners.has(listener))\r\n listeners.add(listener);\r\n\r\n return () => listeners!.delete(listener);\r\n }\r\n\r\n public removeListener(channel: string, listener: IpcListener) {\r\n this._channels.get(channel)?.delete(listener);\r\n }\r\n\r\n private async broadcast(evt: Event, message: IpcWebSocketMessage) {\r\n if (message.type !== IpcWebSocketMessageType.Send && message.type !== IpcWebSocketMessageType.Push)\r\n return;\r\n\r\n const handlers = this._channels.get(message.channel);\r\n if (!handlers)\r\n return;\r\n\r\n let arg = message.data;\r\n if (typeof (arg) === \"undefined\")\r\n arg = [];\r\n\r\n for (const handler of handlers)\r\n handler(evt, ...arg);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class IpcWebSocketFrontend extends IpcWebSocket implements IpcSocketFrontend {\r\n private _nextRequest = 0;\r\n private _pendingRequests = new Map<number, (response: any) => void>();\r\n\r\n public constructor() {\r\n super();\r\n IpcWebSocket.receivers.add(async (e, m) => this.dispatch(e, m));\r\n }\r\n\r\n public send(channel: string, ...data: any[]): void {\r\n IpcWebSocket.transport.send({ type: IpcWebSocketMessageType.Send, channel, data, sequence: -1 });\r\n }\r\n\r\n public async invoke(channel: string, methodName: string, ...args: any[]): Promise<any> {\r\n const requestId = ++this._nextRequest;\r\n IpcWebSocket.transport.send({ type: IpcWebSocketMessageType.Invoke, channel, method: methodName, data: args, request: requestId, sequence: -1 });\r\n\r\n return new Promise((resolve) => {\r\n this._pendingRequests.set(requestId, resolve);\r\n });\r\n }\r\n\r\n private async dispatch(_evt: Event, message: IpcWebSocketMessage) {\r\n if (message.type !== IpcWebSocketMessageType.Response || !message.response)\r\n return;\r\n\r\n const pendingHandler = this._pendingRequests.get(message.response);\r\n if (!pendingHandler)\r\n return;\r\n\r\n this._pendingRequests.delete(message.response);\r\n pendingHandler(message.data);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class IpcWebSocketBackend extends IpcWebSocket implements IpcSocketBackend {\r\n private _handlers = new Map<string, (event: Event, methodName: string, ...args: any[]) => Promise<any>>();\r\n private _processingQueue: IpcWebSocketMessage[] = [];\r\n private _processing: IpcWebSocketMessage | undefined;\r\n\r\n public constructor() {\r\n super();\r\n IpcWebSocket.receivers.add(async (e, m) => this.dispatch(e, m));\r\n }\r\n\r\n public send(channel: string, ...data: any[]): void {\r\n IpcWebSocket.transport.send({ type: IpcWebSocketMessageType.Push, channel, data, sequence: -1 });\r\n }\r\n\r\n public handle(channel: string, handler: (event: Event, methodName: string, ...args: any[]) => Promise<any>): RemoveFunction {\r\n this._handlers.set(channel, handler);\r\n\r\n return () => {\r\n if (this._handlers.get(channel) === handler)\r\n this._handlers.delete(channel);\r\n };\r\n }\r\n\r\n private async dispatch(_evt: Event, message: IpcWebSocketMessage) {\r\n if (message.type !== IpcWebSocketMessageType.Invoke)\r\n return;\r\n\r\n this._processingQueue.push(message);\r\n await this.processMessages();\r\n }\r\n\r\n private async processMessages() {\r\n if (this._processing || !this._processingQueue.length) {\r\n return;\r\n }\r\n\r\n const message = this._processingQueue.shift();\r\n if (message && message.method) {\r\n const handler = this._handlers.get(message.channel);\r\n if (handler) {\r\n this._processing = message;\r\n\r\n let args = message.data;\r\n if (typeof (args) === \"undefined\")\r\n args = [];\r\n\r\n const response = await handler({} as any, message.method, ...args);\r\n\r\n IpcWebSocket.transport.send({\r\n type: IpcWebSocketMessageType.Response,\r\n channel: message.channel,\r\n response: message.request,\r\n data: response,\r\n sequence: -1,\r\n });\r\n\r\n this._processing = undefined;\r\n }\r\n }\r\n\r\n await this.processMessages();\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"BentleyCloudRpcProtocol.d.ts","sourceRoot":"","sources":["../../../../src/rpc/web/BentleyCloudRpcProtocol.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,EAAE,YAAY,EAAE,MAA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OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAM9D;;GAEG;AACH,8BAAsB,uBAAwB,SAAQ,iBAAiB;IACrD,UAAU,UAAQ;IAElC,iFAAiF;IACjE,yCAAyC,EAAE,qBAAqB,CAe9E;IAEF,mDAAmD;IACnC,yBAAyB,SAAwB;IAEjE,yEAAyE;IACzD,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,sBAAsB;IAoB1E,qEAAqE;IACrD,sBAAsB,CAAC,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS;IA0C/F;;;OAGG;IACa,YAAY,CAAC,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,oBAAoB,GAAG,cAAc;IA4B1G;;OAEG;IACI,gCAAgC,CAAC,UAAU,EAAE,YAAY,GAAG,gBAAgB,EAAE;CAQtF"}
@@ -46,6 +46,9 @@ class BentleyCloudRpcProtocol extends WebAppRpcProtocol_1.WebAppRpcProtocol {
46
46
  const components = url.pathname.split("/").filter((x) => x); // filter out empty segments
47
47
  const operationComponent = components.slice(-1)[0];
48
48
  const encodedRequest = url.searchParams.get("parameters") || "";
49
+ // The encodedRequest should be base64 - fail now if any other characters detected.
50
+ if (/[^A-z0-9=+\/]/.test(encodedRequest))
51
+ throw new IModelError_1.IModelError(core_bentley_1.BentleyStatus.ERROR, `Invalid request: Malformed URL parameters detected.`);
49
52
  const firstHyphen = operationComponent.indexOf("-");
50
53
  const lastHyphen = operationComponent.lastIndexOf("-");
51
54
  const interfaceDefinition = operationComponent.slice(0, firstHyphen);
@@ -1 +1 @@
1
- {"version":3,"file":"BentleyCloudRpcProtocol.js","sourceRoot":"","sources":["../../../../src/rpc/web/BentleyCloudRpcProtocol.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AAEpD,mDAAgD;AAChD,+DAA4D;AAC5D,uDAAoD;AAIpD,2DAAwD;AAGxD,IAAK,OAEJ;AAFD,WAA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,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;AA/HD,0DA+HC","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\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 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":[],"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5E,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;AAnID,0DAmIC","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\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 +1 @@
1
- {"version":3,"file":"WebAppRpcProtocol.d.ts","sourceRoot":"","sources":["../../../../src/rpc/web/WebAppRpcProtocol.ts"],"names":[],"mappings":"AAIA;;GAEG;;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,QAAQ;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,GAAG,CAAC;IAChB,OAAO,EAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;KAAE,CAAC;IAC7D,UAAU,EA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AAe,UAAQ;IAEvC,+EAA+E;IAClE,yBAAyB,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,kBAAkB;IAItF,gFAAgF;IACnE,0BAA0B,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,kBAAkB;IAevF,iFAAiF;IAC1E,+BAA+B,CAAC,IAAI,EAAE,iBAAiB,EAAE,GAAG,EAAE,kBAAkB;IAKvF,wEAAwE;WAC1D,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc;IAerF,4DAA4D;IAC5D,SAAgB,IAAI,EAAE,WAAW,CAAC;IAElC,sDAAsD;IAC/C,UAAU,EAAE,MAAM,CAAM;IAE/B,+CAA+C;IAC/C,SAAgB,WAAW,0BAAoB;IAE/C,2EAA2E;IAC3D,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB;IAczD,2EAA2E;IAC3D,OAAO,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM;IAczC,sBAAsB,UAAQ;IAE9C,+DAA+D;IACxD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIvC;;OAEG;IACH,IAAW,kBAAkB,0BAA8C;IAE3E;;OAEG;aACa,gCAAgC,CAAC,UAAU,EAAE,YAAY,GAAG,gBAAgB,EAAE;IAE9F,mCAAmC;gBAChB,aAAa,EAAE,gBAAgB;CAInD"}
@@ -8,6 +8,8 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.WebAppRpcProtocol = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const CommonLoggerCategory_1 = require("../../CommonLoggerCategory");
11
13
  const RpcConstants_1 = require("../core/RpcConstants");
12
14
  const RpcProtocol_1 = require("../core/RpcProtocol");
13
15
  const OpenAPI_1 = require("./OpenAPI");
@@ -34,7 +36,17 @@ class WebAppRpcProtocol extends RpcProtocol_1.RpcProtocol {
34
36
  }
35
37
  /** Convenience handler for an RPC operation post request for an HTTP server. */
36
38
  async handleOperationPostRequest(req, res) {
37
- const request = await WebAppRpcRequest_1.WebAppRpcRequest.parseRequest(this, req);
39
+ let request;
40
+ try {
41
+ request = await WebAppRpcRequest_1.WebAppRpcRequest.parseRequest(this, req);
42
+ }
43
+ catch (error) {
44
+ const message = core_bentley_1.BentleyError.getErrorMessage(error);
45
+ core_bentley_1.Logger.logError(CommonLoggerCategory_1.CommonLoggerCategory.RpcInterfaceBackend, `Failed to parse request: ${message}`, core_bentley_1.BentleyError.getErrorMetadata(error));
46
+ res.status(400);
47
+ res.send(JSON.stringify({ message, isError: true }));
48
+ return;
49
+ }
38
50
  const fulfillment = await this.fulfill(request);
39
51
  await WebAppRpcRequest_1.WebAppRpcRequest.sendResponse(this, request, fulfillment, req, res);
40
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WebAppRpcProtocol.js","sourceRoot":"","sources":["../../../../src/rpc/web/WebAppRpcProtocol.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH,uDAA2F;AAE3F,qDAAkD;AAClD,uCAAiF;AACjF,yDAAsD;AACtD,yDAAsD;AAsCtD;;GAEG;AACH,MAAsB,iBAAkB,SAAQ,yBAAW;IA6FzD,mCAAmC;IACnC,YAAmB,aAA+B;QAChD,KAAK,CAAC,aAAa,CAAC,CAAC;QA9FP,oBAAe,GAAG,IAAI,CAAC;QAuCvC,sDAAsD;QAC/C,eAAU,GAAW,EAAE,CAAC;QAE/B,+CAA+C;QAC/B,gBAAW,GAAG,mCAAgB,CAAC;QAgC/B,2BAAsB,GAAG,IAAI,CAAC;QAoB5C,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,mCAAgB,CAAC,gBAAgB,CAAC,CAAC;IAC7D,CAAC;IA9FD,+EAA+E;IACxE,KAAK,CAAC,yBAAyB,CAAC,GAAsB,EAAE,GAAuB;QACpF,OAAO,IAAI,CAAC,0BAA0B,CAAC,GAAG,EAAE,GAAG,C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AAI,KAAK,GAAG,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAW,kBAAkB,KAAK,OAAO,IAAI,+BAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CAY5E;AAlGD,8CAkGC","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 { Readable, Writable } from \"stream\";\r\nimport { RpcConfiguration } from \"../core/RpcConfiguration\";\r\nimport { RpcContentType, RpcRequestStatus, WEB_RPC_CONSTANTS } from \"../core/RpcConstants\";\r\nimport { RpcOperation } from \"../core/RpcOperation\";\r\nimport { RpcProtocol } from \"../core/RpcProtocol\";\r\nimport { OpenAPIInfo, OpenAPIParameter, RpcOpenAPIDescription } from \"./OpenAPI\";\r\nimport { WebAppRpcLogging } from \"./WebAppRpcLogging\";\r\nimport { WebAppRpcRequest } from \"./WebAppRpcRequest\";\r\n\r\n/** An HTTP server request object.\r\n * @public\r\n */\r\nexport interface HttpServerRequest extends Readable {\r\n aborted: boolean;\r\n httpVersion: string;\r\n httpVersionMajor: number;\r\n httpVersionMinor: number;\r\n complete: boolean;\r\n connection: any;\r\n headers: { [header: string]: string | string[] | undefined };\r\n rawHeaders: string[];\r\n trailers: { [key: string]: string | undefined };\r\n rawTrailers: string[];\r\n setTimeout(msecs: number, callback: () => void): this;\r\n url?: string;\r\n statusCode?: number;\r\n statusMessage?: string;\r\n socket: any;\r\n destroy(error?: Error): void;\r\n body: string | Buffer;\r\n path: string;\r\n method: string;\r\n ip?: string;\r\n header: (field: string) => string | undefined;\r\n}\r\n\r\n/** An HTTP server response object.\r\n * @public\r\n */\r\nexport interface HttpServerResponse extends Writable {\r\n send(body?: any): HttpServerResponse;\r\n status(code: number): HttpServerResponse;\r\n set(field: string, value: string): void;\r\n}\r\n\r\n/** The HTTP application protocol.\r\n * @internal\r\n */\r\nexport abstract class WebAppRpcProtocol extends RpcProtocol {\r\n public override preserveStreams = true;\r\n\r\n /** Convenience handler for an RPC operation get request for an HTTP server. */\r\n public async handleOperationGetRequest(req: HttpServerRequest, res: HttpServerResponse) {\r\n return this.handleOperationPostRequest(req, res);\r\n }\r\n\r\n /** Convenience handler for an RPC operation post request for an HTTP server. */\r\n public async handleOperationPostRequest(req: HttpServerRequest, res: HttpServerResponse) {\r\n const request = await WebAppRpcRequest.parseRequest(this, req);\r\n const fulfillment = await this.fulfill(request);\r\n await WebAppRpcRequest.sendResponse(this, request, fulfillment, req, res);\r\n }\r\n\r\n /** Convenience handler for an OpenAPI description request for an HTTP server. */\r\n public handleOpenApiDescriptionRequest(_req: HttpServerRequest, res: HttpServerResponse) {\r\n const description = JSON.stringify(this.openAPIDescription);\r\n res.send(description);\r\n }\r\n\r\n /** Converts an HTTP content type value to an RPC content type value. */\r\n public static computeContentType(httpType: string | null | undefined): RpcContentType {\r\n if (!httpType)\r\n return RpcContentType.Unknown;\r\n\r\n if (httpType.indexOf(WEB_RPC_CONSTANTS.ANY_TEXT) === 0) {\r\n return RpcContentType.Text;\r\n } else if (httpType.indexOf(WEB_RPC_CONSTANTS.BINARY) === 0) {\r\n return RpcContentType.Binary;\r\n } else if (httpType.indexOf(WEB_RPC_CONSTANTS.MULTIPART) === 0) {\r\n return RpcContentType.Multipart;\r\n } else {\r\n return RpcContentType.Unknown;\r\n }\r\n }\r\n\r\n /** The OpenAPI-compatible info object for this protocol. */\r\n public abstract info: OpenAPIInfo;\r\n\r\n /** An optional prefix for RPC operation URI paths. */\r\n public pathPrefix: string = \"\";\r\n\r\n /** The RPC request class for this protocol. */\r\n public readonly requestType = WebAppRpcRequest;\r\n\r\n /** Supplies the status corresponding to a protocol-specific code value. */\r\n public override getStatus(code: number): RpcRequestStatus {\r\n switch (code) {\r\n case 404: return RpcRequestStatus.NotFound;\r\n case 202: return RpcRequestStatus.Pending;\r\n case 200: return RpcRequestStatus.Resolved;\r\n case 500: return RpcRequestStatus.Rejected;\r\n case 204: return RpcRequestStatus.NoContent;\r\n case 502: return RpcRequestStatus.BadGateway;\r\n case 503: return RpcRequestStatus.ServiceUnavailable;\r\n case 504: return RpcRequestStatus.GatewayTimeout;\r\n default: return RpcRequestStatus.Unknown;\r\n }\r\n }\r\n\r\n /** Supplies the protocol-specific code corresponding to a status value. */\r\n public override getCode(status: RpcRequestStatus): number {\r\n switch (status) {\r\n case RpcRequestStatus.NotFound: return 404;\r\n case RpcRequestStatus.Pending: return 202;\r\n case RpcRequestStatus.Resolved: return 200;\r\n case RpcRequestStatus.Rejected: return 500;\r\n case RpcRequestStatus.NoContent: return 204;\r\n case RpcRequestStatus.BadGateway: return 502;\r\n case RpcRequestStatus.ServiceUnavailable: return 503;\r\n case RpcRequestStatus.GatewayTimeout: return 504;\r\n default: return 501;\r\n }\r\n }\r\n\r\n public override supportsStatusCategory = true;\r\n\r\n /** Whether an HTTP status code indicates a request timeout. */\r\n public isTimeout(code: number): boolean {\r\n return code === 504;\r\n }\r\n\r\n /** An OpenAPI-compatible description of this protocol.\r\n * @internal\r\n */\r\n public get openAPIDescription() { return new RpcOpenAPIDescription(this); }\r\n\r\n /** Returns the OpenAPI-compatible URI path parameters for an RPC operation.\r\n * @internal\r\n */\r\n public abstract supplyPathParametersForOperation(_operation: RpcOperation): OpenAPIParameter[];\r\n\r\n /** Constructs an HTTP protocol. */\r\n public constructor(configuration: RpcConfiguration) {\r\n super(configuration);\r\n this.events.addListener(WebAppRpcLogging.logProtocolEvent);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"WebAppRpcProtocol.js","sourceRoot":"","sources":["../../../../src/rpc/web/WebAppRpcProtocol.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA2D;AAE3D,qEAAkE;AAElE,uDAA2F;AAE3F,qDAAwE;AACxE,uCAAiF;AACjF,yDAAsD;AACtD,yDA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;YAC5C,KAAK,GAAG,CAAC,CAAC,OAAO,+BAAgB,CAAC,UAAU,CAAC;YAC7C,KAAK,GAAG,CAAC,CAAC,OAAO,+BAAgB,CAAC,kBAAkB,CAAC;YACrD,KAAK,GAAG,CAAC,CAAC,OAAO,+BAAgB,CAAC,cAAc,CAAC;YACjD,OAAO,CAAC,CAAC,OAAO,+BAAgB,CAAC,OAAO,CAAC;SAC1C;IACH,CAAC;IAED,2EAA2E;IAC3D,OAAO,CAAC,MAAwB;QAC9C,QAAQ,MAAM,EAAE;YACd,KAAK,+BAAgB,CAAC,QAAQ,CAAC,CAAC,OAAO,GAAG,CAAC;YAC3C,KAAK,+BAAgB,CAAC,OAAO,CAAC,CAAC,OAAO,GAAG,CAAC;YAC1C,KAAK,+BAAgB,CAAC,QAAQ,CAAC,CAAC,OAAO,GAAG,CAAC;YAC3C,KAAK,+BAAgB,CAAC,QAAQ,CAAC,CAAC,OAAO,GAAG,CAAC;YAC3C,KAAK,+BAAgB,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC;YAC5C,KAAK,+BAAgB,CAAC,UAAU,CAAC,CAAC,OAAO,GAAG,CAAC;YAC7C,KAAK,+BAAgB,CAAC,kBAAkB,CAAC,CAAC,OAAO,GAAG,CAAC;YACrD,KAAK,+BAAgB,CAAC,cAAc,CAAC,CAAC,OAAO,GAAG,CAAC;YACjD,OAAO,CAAC,CAAC,OAAO,GAAG,CAAC;SACrB;IACH,CAAC;IAID,+DAA+D;IACxD,SAAS,CAAC,IAAY;QAC3B,OAAO,IAAI,KAAK,GAAG,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAW,kBAAkB,KAAK,OAAO,IAAI,+BAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CAY5E;AA3GD,8CA2GC","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 { BentleyError, Logger } from \"@itwin/core-bentley\";\r\nimport { Readable, Writable } from \"stream\";\r\nimport { CommonLoggerCategory } from \"../../CommonLoggerCategory\";\r\nimport { RpcConfiguration } from \"../core/RpcConfiguration\";\r\nimport { RpcContentType, RpcRequestStatus, WEB_RPC_CONSTANTS } from \"../core/RpcConstants\";\r\nimport { RpcOperation } from \"../core/RpcOperation\";\r\nimport { RpcProtocol, SerializedRpcRequest } from \"../core/RpcProtocol\";\r\nimport { OpenAPIInfo, OpenAPIParameter, RpcOpenAPIDescription } from \"./OpenAPI\";\r\nimport { WebAppRpcLogging } from \"./WebAppRpcLogging\";\r\nimport { WebAppRpcRequest } from \"./WebAppRpcRequest\";\r\n\r\n/** An HTTP server request object.\r\n * @public\r\n */\r\nexport interface HttpServerRequest extends Readable {\r\n aborted: boolean;\r\n httpVersion: string;\r\n httpVersionMajor: number;\r\n httpVersionMinor: number;\r\n complete: boolean;\r\n connection: any;\r\n headers: { [header: string]: string | string[] | undefined };\r\n rawHeaders: string[];\r\n trailers: { [key: string]: string | undefined };\r\n rawTrailers: string[];\r\n setTimeout(msecs: number, callback: () => void): this;\r\n url?: string;\r\n statusCode?: number;\r\n statusMessage?: string;\r\n socket: any;\r\n destroy(error?: Error): void;\r\n body: string | Buffer;\r\n path: string;\r\n method: string;\r\n ip?: string;\r\n header: (field: string) => string | undefined;\r\n}\r\n\r\n/** An HTTP server response object.\r\n * @public\r\n */\r\nexport interface HttpServerResponse extends Writable {\r\n send(body?: any): HttpServerResponse;\r\n status(code: number): HttpServerResponse;\r\n set(field: string, value: string): void;\r\n}\r\n\r\n/** The HTTP application protocol.\r\n * @internal\r\n */\r\nexport abstract class WebAppRpcProtocol extends RpcProtocol {\r\n public override preserveStreams = true;\r\n\r\n /** Convenience handler for an RPC operation get request for an HTTP server. */\r\n public async handleOperationGetRequest(req: HttpServerRequest, res: HttpServerResponse) {\r\n return this.handleOperationPostRequest(req, res);\r\n }\r\n\r\n /** Convenience handler for an RPC operation post request for an HTTP server. */\r\n public async handleOperationPostRequest(req: HttpServerRequest, res: HttpServerResponse) {\r\n let request: SerializedRpcRequest;\r\n try {\r\n request = await WebAppRpcRequest.parseRequest(this, req);\r\n } catch (error) {\r\n const message = BentleyError.getErrorMessage(error);\r\n Logger.logError(CommonLoggerCategory.RpcInterfaceBackend, `Failed to parse request: ${message}`, BentleyError.getErrorMetadata(error));\r\n res.status(400);\r\n res.send(JSON.stringify({ message, isError: true }));\r\n return;\r\n }\r\n const fulfillment = await this.fulfill(request);\r\n await WebAppRpcRequest.sendResponse(this, request, fulfillment, req, res);\r\n }\r\n\r\n /** Convenience handler for an OpenAPI description request for an HTTP server. */\r\n public handleOpenApiDescriptionRequest(_req: HttpServerRequest, res: HttpServerResponse) {\r\n const description = JSON.stringify(this.openAPIDescription);\r\n res.send(description);\r\n }\r\n\r\n /** Converts an HTTP content type value to an RPC content type value. */\r\n public static computeContentType(httpType: string | null | undefined): RpcContentType {\r\n if (!httpType)\r\n return RpcContentType.Unknown;\r\n\r\n if (httpType.indexOf(WEB_RPC_CONSTANTS.ANY_TEXT) === 0) {\r\n return RpcContentType.Text;\r\n } else if (httpType.indexOf(WEB_RPC_CONSTANTS.BINARY) === 0) {\r\n return RpcContentType.Binary;\r\n } else if (httpType.indexOf(WEB_RPC_CONSTANTS.MULTIPART) === 0) {\r\n return RpcContentType.Multipart;\r\n } else {\r\n return RpcContentType.Unknown;\r\n }\r\n }\r\n\r\n /** The OpenAPI-compatible info object for this protocol. */\r\n public abstract info: OpenAPIInfo;\r\n\r\n /** An optional prefix for RPC operation URI paths. */\r\n public pathPrefix: string = \"\";\r\n\r\n /** The RPC request class for this protocol. */\r\n public readonly requestType = WebAppRpcRequest;\r\n\r\n /** Supplies the status corresponding to a protocol-specific code value. */\r\n public override getStatus(code: number): RpcRequestStatus {\r\n switch (code) {\r\n case 404: return RpcRequestStatus.NotFound;\r\n case 202: return RpcRequestStatus.Pending;\r\n case 200: return RpcRequestStatus.Resolved;\r\n case 500: return RpcRequestStatus.Rejected;\r\n case 204: return RpcRequestStatus.NoContent;\r\n case 502: return RpcRequestStatus.BadGateway;\r\n case 503: return RpcRequestStatus.ServiceUnavailable;\r\n case 504: return RpcRequestStatus.GatewayTimeout;\r\n default: return RpcRequestStatus.Unknown;\r\n }\r\n }\r\n\r\n /** Supplies the protocol-specific code corresponding to a status value. */\r\n public override getCode(status: RpcRequestStatus): number {\r\n switch (status) {\r\n case RpcRequestStatus.NotFound: return 404;\r\n case RpcRequestStatus.Pending: return 202;\r\n case RpcRequestStatus.Resolved: return 200;\r\n case RpcRequestStatus.Rejected: return 500;\r\n case RpcRequestStatus.NoContent: return 204;\r\n case RpcRequestStatus.BadGateway: return 502;\r\n case RpcRequestStatus.ServiceUnavailable: return 503;\r\n case RpcRequestStatus.GatewayTimeout: return 504;\r\n default: return 501;\r\n }\r\n }\r\n\r\n public override supportsStatusCategory = true;\r\n\r\n /** Whether an HTTP status code indicates a request timeout. */\r\n public isTimeout(code: number): boolean {\r\n return code === 504;\r\n }\r\n\r\n /** An OpenAPI-compatible description of this protocol.\r\n * @internal\r\n */\r\n public get openAPIDescription() { return new RpcOpenAPIDescription(this); }\r\n\r\n /** Returns the OpenAPI-compatible URI path parameters for an RPC operation.\r\n * @internal\r\n */\r\n public abstract supplyPathParametersForOperation(_operation: RpcOperation): OpenAPIParameter[];\r\n\r\n /** Constructs an HTTP protocol. */\r\n public constructor(configuration: RpcConfiguration) {\r\n super(configuration);\r\n this.events.addListener(WebAppRpcLogging.logProtocolEvent);\r\n }\r\n}\r\n"]}
@@ -75,7 +75,7 @@ class WebAppRpcRequest extends RpcRequest_1.RpcRequest {
75
75
  }
76
76
  }
77
77
  if (!request.id) {
78
- throw new IModelError_1.IModelError(core_bentley_1.BentleyStatus.ERROR, `Invalid request.`);
78
+ throw new IModelError_1.IModelError(core_bentley_1.BentleyStatus.ERROR, `Invalid request: Missing required activity ID.`);
79
79
  }
80
80
  return request;
81
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WebAppRpcRequest.js","sourceRoot":"","sources":["../../../../src/rpc/web/WebAppRpcRequest.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,mCAAgC;AAChC,mDAAiF;AAEjF,uDAAsI;AAEtI,yDAAmF;AACnF,qDAAuH;AACvH,mDAAgD;AAChD,uEAAoE;AACpE,iDAAgE;AAChE,2DAA+F;AAK/F;;GAEG;AACH,MAAa,gBAAiB,SAAQ,uBAAU;IAmI9C,4CAA4C;IAC5C,YAAmB,MAAoB,EAAE,SAAiB,EAAE,UAAiB;QAC3E,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QApI/B,aAAQ,GAAY,KAAK,CAAC;QAC1B,aAAQ,GAAgB,EAAE,CAAC;QAC3B,gBAAW,GAAW,EAAE,CAAC;QAajC,0DAA0D;QACjC,aAAQ,GAAsB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAe,CAAC;QAEjG,+FAA+F;QACxF,aAAQ,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAkH3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG,EAAE,CAAC;IAC7B,CAAC;IArID,IAAY,QAAQ,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAoC,CAAC,CAAC,CAAC;IAkBrF,oBAAoB;IACZ,MAAM,CAAC,YAAY,CAAC,QAA2B,EAAE,GAAsB;;QAC7E,MAAM,WAAW,GAA0B,QAAQ,CAAC,yCAAyC,CAAC;QAC9F,MAAM,aAAa,GAA0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Q,CAAC,MAAM,GAAG,MAAM,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,2BAAY,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC3D,CAAC;IAEO,kBAAkB,CAAC,UAA8B;QACvD,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE;YACpD,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,8CAA8C;YAC5F,IAAI,WAAW,CAAC,MAAM,IAAI,gBAAgB,CAAC,mBAAmB,EAAE;gBAC9D,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC;gBAC7B,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,SAAS,CAAC;gBAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,gCAAiB,CAAC,OAAO,CAAC,CAAC;gBAChD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;gBAC/B,OAAO;aACR;SACF;QAED,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,gCAAiB,CAAC,OAAO,CAAC,GAAG,gCAAiB,CAAC,IAAI,CAAC;QAClE,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC;IAC1C,CAAC;;AAxYH,4CAyYC;AAnYC;;;;GAIG;AACW,oCAAmB,GAAG,IAAI,GAAG,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { Buffer } from \"buffer\";\r\nimport { IModelError, ServerError, ServerTimeoutError } from \"../../IModelError\";\r\nimport { RpcInterface } from \"../../RpcInterface\";\r\nimport { RpcContentType, RpcProtocolEvent, RpcRequestStatus, RpcResponseCacheControl, WEB_RPC_CONSTANTS } from \"../core/RpcConstants\";\r\nimport { SerializedRpcActivity } from \"../core/RpcInvocation\";\r\nimport { MarshalingBinaryMarker, RpcSerializedValue } from \"../core/RpcMarshaling\";\r\nimport { RpcProtocol, RpcRequestFulfillment, SerializedRpcOperation, SerializedRpcRequest } from \"../core/RpcProtocol\";\r\nimport { RpcRequest } from \"../core/RpcRequest\";\r\nimport { RpcMultipartParser } from \"./multipart/RpcMultipartParser\";\r\nimport { ReadableFormData, RpcMultipart } from \"./RpcMultipart\";\r\nimport { HttpServerRequest, HttpServerResponse, WebAppRpcProtocol } from \"./WebAppRpcProtocol\";\r\n\r\n/** @internal */\r\nexport type HttpMethod_T = \"get\" | \"put\" | \"post\" | \"delete\" | \"options\" | \"head\" | \"patch\" | \"trace\"; // eslint-disable-line @typescript-eslint/naming-convention\r\n\r\n/** A web application RPC request.\r\n * @internal\r\n */\r\nexport class WebAppRpcRequest extends RpcRequest {\r\n private _loading: boolean = false;\r\n private _request: RequestInit = {};\r\n private _pathSuffix: string = \"\";\r\n private get _headers() { return this._request.headers as { [key: string]: string }; }\r\n\r\n /** The maximum size permitted for an encoded component in a URL.\r\n * Note that some backends limit the total cumulative request size. Our current node backends accept requests with a max size of 16 kb.\r\n * In addition to the url size, an authorization header may also add considerably to the request size.\r\n * @note This is used for features like encoding the payload of a cacheable request in the URL.\r\n */\r\n public static maxUrlComponentSize = 1024 * 8;\r\n\r\n /** The HTTP method for this request. */\r\n public override method: HttpMethod_T;\r\n\r\n /** Convenience access to the protocol of this request. */\r\n public override readonly protocol: WebAppRpcProtocol = this.client.configuration.protocol as any;\r\n\r\n /** Standardized access to metadata about the request (useful for purposes such as logging). */\r\n public metadata = { status: 0, message: \"\" };\r\n\r\n /** Parse headers */\r\n private static parseHeaders(protocol: WebAppRpcProtocol, req: HttpServerRequest): SerializedRpcActivity {\r\n const headerNames: SerializedRpcActivity = protocol.serializedClientRequestContextHeaderNames;\r\n const parsedHeaders: SerializedRpcActivity = {\r\n id: req.header(headerNames.id) || \"\",\r\n applicationId: req.header(headerNames.applicationId) || \"\",\r\n applicationVersion: req.header(headerNames.applicationVersion) || \"\",\r\n sessionId: req.header(headerNames.sessionId) || \"\",\r\n authorization: (headerNames.authorization ? req.header(headerNames.authorization) : \"\") ?? \"\",\r\n };\r\n return parsedHeaders;\r\n }\r\n\r\n /** Parses a request. */\r\n public static async parseRequest(protocol: WebAppRpcProtocol, req: HttpServerRequest): Promise<SerializedRpcRequest> {\r\n const operation = protocol.getOperationFromPath(req.url!);\r\n\r\n const parsedHeaders = this.parseHeaders(protocol, req);\r\n\r\n const request: SerializedRpcRequest = {\r\n ...parsedHeaders,\r\n operation: {\r\n interfaceDefinition: operation.interfaceDefinition,\r\n operationName: operation.operationName,\r\n interfaceVersion: operation.interfaceVersion,\r\n },\r\n method: req.method,\r\n path: req.url!,\r\n parameters: operation.encodedRequest ? WebAppRpcRequest.parseFromPath(operation) : await WebAppRpcRequest.parseFromBody(req),\r\n caching: operation.encodedRequest ? RpcResponseCacheControl.Immutable : RpcResponseCacheControl.None,\r\n };\r\n\r\n request.ip = req.ip;\r\n\r\n request.protocolVersion = 0;\r\n\r\n if (protocol.protocolVersionHeaderName) {\r\n const version = req.header(protocol.protocolVersionHeaderName);\r\n if (version) {\r\n request.protocolVersion = parseInt(version, 10);\r\n }\r\n }\r\n\r\n if (!request.id) {\r\n throw new IModelError(BentleyStatus.ERROR, `Invalid request.`);\r\n }\r\n\r\n return request;\r\n }\r\n\r\n /** Sends the response for a web request. */\r\n public static async sendResponse(\r\n protocol: WebAppRpcProtocol,\r\n request: SerializedRpcRequest,\r\n fulfillment: RpcRequestFulfillment,\r\n req: HttpServerRequest,\r\n res: HttpServerResponse,\r\n ): Promise<void> {\r\n const versionHeader = protocol.protocolVersionHeaderName;\r\n if (versionHeader && RpcProtocol.protocolVersion) {\r\n res.set(versionHeader, RpcProtocol.protocolVersion.toString());\r\n }\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n const { Readable, Stream } = await import(/* webpackIgnore: true */ \"stream\");\r\n const { createGzip } = await import(/* webpackIgnore: true */ \"zlib\");\r\n\r\n const transportType = WebAppRpcRequest.computeTransportType(fulfillment.result, fulfillment.rawResult);\r\n let responseBody;\r\n if (transportType === RpcContentType.Binary) {\r\n responseBody = WebAppRpcRequest.configureBinary(fulfillment, res);\r\n } else if (transportType === RpcContentType.Multipart) {\r\n responseBody = WebAppRpcRequest.configureMultipart(fulfillment, res);\r\n } else if (transportType === RpcContentType.Stream) {\r\n responseBody = WebAppRpcRequest.configureStream(fulfillment);\r\n } else {\r\n responseBody = WebAppRpcRequest.configureText(fulfillment, res);\r\n }\r\n\r\n WebAppRpcRequest.configureResponse(protocol, request, fulfillment, res);\r\n res.status(fulfillment.status);\r\n\r\n if (fulfillment.allowCompression && req.header(\"Accept-Encoding\")?.includes(\"gzip\")) {\r\n res.set(\"Content-Encoding\", \"gzip\");\r\n const readableResponseBody = (responseBody instanceof Stream) ? responseBody : Readable.from(responseBody);\r\n responseBody = readableResponseBody.pipe(createGzip());\r\n }\r\n\r\n // This check should in theory look for instances of Readable, but that would break backend implementation at\r\n // core/backend/src/RpcBackend.ts\r\n if (responseBody instanceof Stream) {\r\n responseBody.pipe(res);\r\n } else {\r\n res.send(responseBody);\r\n }\r\n }\r\n\r\n /** Determines the most efficient transport type for an RPC value. */\r\n protected static computeTransportType(value: RpcSerializedValue, source: any): RpcContentType {\r\n if (source instanceof Uint8Array || (Array.isArray(source) && source[0] instanceof Uint8Array)) {\r\n return RpcContentType.Binary;\r\n } else if (value.data.length > 0) {\r\n return RpcContentType.Multipart;\r\n } else if (value.stream) {\r\n return RpcContentType.Stream;\r\n } else {\r\n return RpcContentType.Text;\r\n }\r\n }\r\n\r\n /** Constructs a web application request. */\r\n public constructor(client: RpcInterface, operation: string, parameters: any[]) {\r\n super(client, operation, parameters);\r\n this.path = this.protocol.supplyPathForOperation(this.operation, this);\r\n this.method = \"head\";\r\n this._request.headers = {};\r\n }\r\n\r\n /** Sets request header values. */\r\n protected setHeader(name: string, value: string): void {\r\n this._headers[name] = value;\r\n }\r\n\r\n /** Sends the request. */\r\n protected async send(): Promise<number> {\r\n this._loading = true;\r\n await this.setupTransport();\r\n\r\n return new Promise<number>(async (resolve, reject) => {\r\n try {\r\n resolve(await this.performFetch());\r\n } catch (reason) {\r\n reject(new ServerError(-1, typeof (reason) === \"string\" ? reason : \"Server connection error.\"));\r\n }\r\n });\r\n }\r\n\r\n protected override computeRetryAfter(attempts: number): number {\r\n const retryAfter = this._response && this._response.headers.get(\"Retry-After\");\r\n if (retryAfter) {\r\n this.resetTransientFaultCount();\r\n\r\n const r = Number(retryAfter);\r\n if (Number.isFinite(r)) {\r\n return r * 1000;\r\n }\r\n\r\n const d = Date.parse(retryAfter);\r\n if (!Number.isNaN(d)) {\r\n return d - Date.now();\r\n }\r\n } else {\r\n this.recordTransientFault();\r\n }\r\n\r\n return super.computeRetryAfter(attempts);\r\n }\r\n\r\n protected override handleUnknownResponse(code: number) {\r\n if (this.protocol.isTimeout(code)) {\r\n this.reject(new ServerTimeoutError(\"Request timeout.\"));\r\n } else {\r\n this.reject(new ServerError(code, \"Unknown server response code.\"));\r\n }\r\n }\r\n\r\n protected async load(): Promise<RpcSerializedValue> {\r\n return new Promise<RpcSerializedValue>(async (resolve, reject) => {\r\n try {\r\n if (!this._loading)\r\n return;\r\n\r\n const response = this._response;\r\n if (!response) {\r\n reject(new IModelError(BentleyStatus.ERROR, \"Invalid state.\"));\r\n return;\r\n }\r\n\r\n if (this.protocol.protocolVersionHeaderName) {\r\n const version = response.headers.get(this.protocol.protocolVersionHeaderName);\r\n if (version) {\r\n this.responseProtocolVersion = parseInt(version, 10);\r\n }\r\n }\r\n\r\n const contentType = response.headers.get(WEB_RPC_CONSTANTS.CONTENT);\r\n const responseType = WebAppRpcProtocol.computeContentType(contentType);\r\n\r\n if (responseType === RpcContentType.Binary) {\r\n resolve(await this.loadBinary(response));\r\n } else if (responseType === RpcContentType.Multipart) {\r\n resolve(await this.loadMultipart(response, contentType!));\r\n } else {\r\n resolve(await this.loadText(response));\r\n }\r\n\r\n this._loading = false;\r\n this.setLastUpdatedTime();\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.ResponseLoaded, this);\r\n } catch (reason) {\r\n if (!this._loading)\r\n return;\r\n\r\n this._loading = false;\r\n reject(new ServerError(this.metadata.status, typeof (reason) === \"string\" ? reason : \"Unknown server response error.\"));\r\n }\r\n });\r\n }\r\n\r\n /** Override to supply an alternate fetch function. */\r\n protected supplyFetch(): typeof fetch {\r\n return fetch;\r\n }\r\n\r\n /** Override to supply an alternate Request function. */\r\n protected supplyRequest(): typeof Request {\r\n return Request;\r\n }\r\n\r\n private static configureResponse(protocol: WebAppRpcProtocol, request: SerializedRpcRequest, fulfillment: RpcRequestFulfillment, res: HttpServerResponse) {\r\n const success = protocol.getStatus(fulfillment.status) === RpcRequestStatus.Resolved;\r\n // TODO: Use stale-while-revalidate in cache headers. This needs to be tested, and does not currently have support in the router/caching-service.\r\n // This will allow browsers to use stale cached responses while also revalidating with the router, allowing us to start up a backend if necessary.\r\n\r\n // RPC Caching Service uses the s-maxage header to determine the TTL for the redis cache.\r\n const oneHourInSeconds = 3600;\r\n if (success && request.caching === RpcResponseCacheControl.Immutable) {\r\n // If response size is > 50 MB, do not cache it.\r\n if (fulfillment.result.objects.length > (50 * 10**7)) {\r\n res.set(\"Cache-Control\", \"no-store\");\r\n } else if (request.operation.operationName === \"generateTileContent\") {\r\n res.set(\"Cache-Control\", \"no-store\");\r\n } else if (request.operation.operationName === \"getConnectionProps\") {\r\n // GetConnectionprops can't be cached on the browser longer than the lifespan of the backend. The lifespan of backend may shrink too. Keep it at 1 second to be safe.\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 24}, max-age=1, immutable`);\r\n } else if (request.operation.operationName === \"getTileCacheContainerUrl\") {\r\n // getTileCacheContainerUrl returns a SAS with an expiry of 23:59:59. We can't exceed that time when setting the max-age.\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 23}, max-age=${oneHourInSeconds * 23}, immutable`);\r\n } else {\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 24}, max-age=${oneHourInSeconds * 48}, immutable`);\r\n }\r\n }\r\n\r\n if (fulfillment.retry) {\r\n res.set(\"Retry-After\", fulfillment.retry);\r\n }\r\n }\r\n\r\n private static configureText(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): string {\r\n res.set(WEB_RPC_CONSTANTS.CONTENT, WEB_RPC_CONSTANTS.TEXT);\r\n return (fulfillment.status === 204) ? \"\" : fulfillment.result.objects;\r\n }\r\n\r\n private static configureBinary(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): Buffer {\r\n res.set(WEB_RPC_CONSTANTS.CONTENT, WEB_RPC_CONSTANTS.BINARY);\r\n const data = fulfillment.result.data[0];\r\n return Buffer.isBuffer(data) ? data : Buffer.from(data);\r\n }\r\n\r\n private static configureMultipart(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): ReadableFormData {\r\n const response = RpcMultipart.createStream(fulfillment.result);\r\n const headers = response.getHeaders();\r\n for (const header in headers) {\r\n if (headers.hasOwnProperty(header)) {\r\n res.set(header, headers[header]);\r\n }\r\n }\r\n\r\n return response;\r\n }\r\n\r\n private static configureStream(fulfillment: RpcRequestFulfillment) {\r\n return fulfillment.result.stream!;\r\n }\r\n\r\n private static parseFromPath(operation: SerializedRpcOperation): RpcSerializedValue {\r\n const decoded = operation.encodedRequest ? Buffer.from(operation.encodedRequest, \"base64\").toString(\"binary\") : \"\";\r\n return RpcSerializedValue.create(decoded);\r\n }\r\n\r\n private static async parseFromBody(req: HttpServerRequest): Promise<RpcSerializedValue> {\r\n const contentType = WebAppRpcProtocol.computeContentType(req.header(WEB_RPC_CONSTANTS.CONTENT));\r\n if (contentType === RpcContentType.Binary) {\r\n const objects = JSON.stringify([MarshalingBinaryMarker.createDefault()]);\r\n const data = [req.body as Buffer];\r\n return RpcSerializedValue.create(objects, data);\r\n } else if (contentType === RpcContentType.Multipart) {\r\n return RpcMultipart.parseRequest(req);\r\n } else {\r\n return RpcSerializedValue.create(req.body as string);\r\n }\r\n }\r\n\r\n private async performFetch(): Promise<number> {\r\n const requestClass = this.supplyRequest();\r\n const fetchFunction = this.supplyFetch();\r\n\r\n const path = new URL(this.path, typeof (location) !== \"undefined\" ? location.origin : undefined);\r\n if (this._pathSuffix) {\r\n const params = new URLSearchParams();\r\n params.set(\"parameters\", this._pathSuffix);\r\n path.search = `?${params.toString()}`;\r\n }\r\n\r\n const request = new requestClass(path.toString(), this._request);\r\n const response = await fetchFunction(request);\r\n this._response = response;\r\n this.metadata.status = response.status;\r\n return response.status;\r\n }\r\n\r\n private async loadText(response: Response) {\r\n const value = await response.text();\r\n this.metadata.message = value;\r\n return RpcSerializedValue.create(value);\r\n }\r\n\r\n private async loadBinary(response: Response) {\r\n const value = new Uint8Array(await response.arrayBuffer());\r\n const objects = JSON.stringify(MarshalingBinaryMarker.createDefault());\r\n return RpcSerializedValue.create(objects, [value]);\r\n }\r\n\r\n private async loadMultipart(response: Response, contentType: string) {\r\n const data = await response.arrayBuffer();\r\n const value = new RpcMultipartParser(contentType, Buffer.from(data)).parse();\r\n return value;\r\n }\r\n\r\n private async setupTransport(): Promise<void> {\r\n const parameters = (await this.protocol.serialize(this)).parameters;\r\n const transportType = WebAppRpcRequest.computeTransportType(parameters, this.parameters);\r\n\r\n if (transportType === RpcContentType.Binary) {\r\n this.setupBinaryTransport(parameters);\r\n } else if (transportType === RpcContentType.Multipart) {\r\n this.setupMultipartTransport(parameters);\r\n } else {\r\n this.setupTextTransport(parameters);\r\n }\r\n }\r\n\r\n private setupBinaryTransport(parameters: RpcSerializedValue) {\r\n this._headers[WEB_RPC_CONSTANTS.CONTENT] = WEB_RPC_CONSTANTS.BINARY;\r\n this._request.method = \"post\";\r\n this._request.body = parameters.data[0];\r\n }\r\n\r\n private setupMultipartTransport(parameters: RpcSerializedValue) {\r\n // IMPORTANT: do not set a multipart Content-Type header value. The browser does this automatically!\r\n delete this._headers[WEB_RPC_CONSTANTS.CONTENT];\r\n this._request.method = \"post\";\r\n this._request.body = RpcMultipart.createForm(parameters);\r\n }\r\n\r\n private setupTextTransport(parameters: RpcSerializedValue) {\r\n if (this.operation.policy.allowResponseCaching(this)) {\r\n const encodedBody = btoa(parameters.objects); // eslint-disable-line deprecation/deprecation\r\n if (encodedBody.length <= WebAppRpcRequest.maxUrlComponentSize) {\r\n this._request.method = \"get\";\r\n this._request.body = undefined;\r\n delete this._headers[WEB_RPC_CONSTANTS.CONTENT];\r\n this._pathSuffix = encodedBody;\r\n return;\r\n }\r\n }\r\n\r\n this._pathSuffix = \"\";\r\n this._headers[WEB_RPC_CONSTANTS.CONTENT] = WEB_RPC_CONSTANTS.TEXT;\r\n this._request.method = \"post\";\r\n this._request.body = parameters.objects;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"WebAppRpcRequest.js","sourceRoot":"","sources":["../../../../src/rpc/web/WebAppRpcRequest.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,mCAAgC;AAChC,mDAAiF;AAEjF,uDAAsI;AAEtI,yDAAmF;AACnF,qDAAuH;AACvH,mDAAgD;AAChD,uEAAoE;AACpE,iDAAgE;AAChE,2DAA+F;AAK/F;;GAEG;AACH,MAAa,gBAAiB,SAAQ,uBAAU;IAmI9C,4CAA4C;IAC5C,YAAmB,MAAoB,EAAE,SAAiB,EAAE,UAAiB;QAC3E,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QApI/B,aAAQ,GAAY,KAAK,CAAC;QAC1B,aAAQ,GAAgB,EAAE,CAAC;QAC3B,gBAAW,GAAW,E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,CAAC,WAAW,GAAG,WAAW,CAAC;gBAC/B,OAAO;aACR;SACF;QAED,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,gCAAiB,CAAC,OAAO,CAAC,GAAG,gCAAiB,CAAC,IAAI,CAAC;QAClE,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC;IAC1C,CAAC;;AAxYH,4CAyYC;AAnYC;;;;GAIG;AACW,oCAAmB,GAAG,IAAI,GAAG,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { Buffer } from \"buffer\";\r\nimport { IModelError, ServerError, ServerTimeoutError } from \"../../IModelError\";\r\nimport { RpcInterface } from \"../../RpcInterface\";\r\nimport { RpcContentType, RpcProtocolEvent, RpcRequestStatus, RpcResponseCacheControl, WEB_RPC_CONSTANTS } from \"../core/RpcConstants\";\r\nimport { SerializedRpcActivity } from \"../core/RpcInvocation\";\r\nimport { MarshalingBinaryMarker, RpcSerializedValue } from \"../core/RpcMarshaling\";\r\nimport { RpcProtocol, RpcRequestFulfillment, SerializedRpcOperation, SerializedRpcRequest } from \"../core/RpcProtocol\";\r\nimport { RpcRequest } from \"../core/RpcRequest\";\r\nimport { RpcMultipartParser } from \"./multipart/RpcMultipartParser\";\r\nimport { ReadableFormData, RpcMultipart } from \"./RpcMultipart\";\r\nimport { HttpServerRequest, HttpServerResponse, WebAppRpcProtocol } from \"./WebAppRpcProtocol\";\r\n\r\n/** @internal */\r\nexport type HttpMethod_T = \"get\" | \"put\" | \"post\" | \"delete\" | \"options\" | \"head\" | \"patch\" | \"trace\"; // eslint-disable-line @typescript-eslint/naming-convention\r\n\r\n/** A web application RPC request.\r\n * @internal\r\n */\r\nexport class WebAppRpcRequest extends RpcRequest {\r\n private _loading: boolean = false;\r\n private _request: RequestInit = {};\r\n private _pathSuffix: string = \"\";\r\n private get _headers() { return this._request.headers as { [key: string]: string }; }\r\n\r\n /** The maximum size permitted for an encoded component in a URL.\r\n * Note that some backends limit the total cumulative request size. Our current node backends accept requests with a max size of 16 kb.\r\n * In addition to the url size, an authorization header may also add considerably to the request size.\r\n * @note This is used for features like encoding the payload of a cacheable request in the URL.\r\n */\r\n public static maxUrlComponentSize = 1024 * 8;\r\n\r\n /** The HTTP method for this request. */\r\n public override method: HttpMethod_T;\r\n\r\n /** Convenience access to the protocol of this request. */\r\n public override readonly protocol: WebAppRpcProtocol = this.client.configuration.protocol as any;\r\n\r\n /** Standardized access to metadata about the request (useful for purposes such as logging). */\r\n public metadata = { status: 0, message: \"\" };\r\n\r\n /** Parse headers */\r\n private static parseHeaders(protocol: WebAppRpcProtocol, req: HttpServerRequest): SerializedRpcActivity {\r\n const headerNames: SerializedRpcActivity = protocol.serializedClientRequestContextHeaderNames;\r\n const parsedHeaders: SerializedRpcActivity = {\r\n id: req.header(headerNames.id) || \"\",\r\n applicationId: req.header(headerNames.applicationId) || \"\",\r\n applicationVersion: req.header(headerNames.applicationVersion) || \"\",\r\n sessionId: req.header(headerNames.sessionId) || \"\",\r\n authorization: (headerNames.authorization ? req.header(headerNames.authorization) : \"\") ?? \"\",\r\n };\r\n return parsedHeaders;\r\n }\r\n\r\n /** Parses a request. */\r\n public static async parseRequest(protocol: WebAppRpcProtocol, req: HttpServerRequest): Promise<SerializedRpcRequest> {\r\n const operation = protocol.getOperationFromPath(req.url!);\r\n\r\n const parsedHeaders = this.parseHeaders(protocol, req);\r\n\r\n const request: SerializedRpcRequest = {\r\n ...parsedHeaders,\r\n operation: {\r\n interfaceDefinition: operation.interfaceDefinition,\r\n operationName: operation.operationName,\r\n interfaceVersion: operation.interfaceVersion,\r\n },\r\n method: req.method,\r\n path: req.url!,\r\n parameters: operation.encodedRequest ? WebAppRpcRequest.parseFromPath(operation) : await WebAppRpcRequest.parseFromBody(req),\r\n caching: operation.encodedRequest ? RpcResponseCacheControl.Immutable : RpcResponseCacheControl.None,\r\n };\r\n\r\n request.ip = req.ip;\r\n\r\n request.protocolVersion = 0;\r\n\r\n if (protocol.protocolVersionHeaderName) {\r\n const version = req.header(protocol.protocolVersionHeaderName);\r\n if (version) {\r\n request.protocolVersion = parseInt(version, 10);\r\n }\r\n }\r\n\r\n if (!request.id) {\r\n throw new IModelError(BentleyStatus.ERROR, `Invalid request: Missing required activity ID.`);\r\n }\r\n\r\n return request;\r\n }\r\n\r\n /** Sends the response for a web request. */\r\n public static async sendResponse(\r\n protocol: WebAppRpcProtocol,\r\n request: SerializedRpcRequest,\r\n fulfillment: RpcRequestFulfillment,\r\n req: HttpServerRequest,\r\n res: HttpServerResponse,\r\n ): Promise<void> {\r\n const versionHeader = protocol.protocolVersionHeaderName;\r\n if (versionHeader && RpcProtocol.protocolVersion) {\r\n res.set(versionHeader, RpcProtocol.protocolVersion.toString());\r\n }\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n const { Readable, Stream } = await import(/* webpackIgnore: true */ \"stream\");\r\n const { createGzip } = await import(/* webpackIgnore: true */ \"zlib\");\r\n\r\n const transportType = WebAppRpcRequest.computeTransportType(fulfillment.result, fulfillment.rawResult);\r\n let responseBody;\r\n if (transportType === RpcContentType.Binary) {\r\n responseBody = WebAppRpcRequest.configureBinary(fulfillment, res);\r\n } else if (transportType === RpcContentType.Multipart) {\r\n responseBody = WebAppRpcRequest.configureMultipart(fulfillment, res);\r\n } else if (transportType === RpcContentType.Stream) {\r\n responseBody = WebAppRpcRequest.configureStream(fulfillment);\r\n } else {\r\n responseBody = WebAppRpcRequest.configureText(fulfillment, res);\r\n }\r\n\r\n WebAppRpcRequest.configureResponse(protocol, request, fulfillment, res);\r\n res.status(fulfillment.status);\r\n\r\n if (fulfillment.allowCompression && req.header(\"Accept-Encoding\")?.includes(\"gzip\")) {\r\n res.set(\"Content-Encoding\", \"gzip\");\r\n const readableResponseBody = (responseBody instanceof Stream) ? responseBody : Readable.from(responseBody);\r\n responseBody = readableResponseBody.pipe(createGzip());\r\n }\r\n\r\n // This check should in theory look for instances of Readable, but that would break backend implementation at\r\n // core/backend/src/RpcBackend.ts\r\n if (responseBody instanceof Stream) {\r\n responseBody.pipe(res);\r\n } else {\r\n res.send(responseBody);\r\n }\r\n }\r\n\r\n /** Determines the most efficient transport type for an RPC value. */\r\n protected static computeTransportType(value: RpcSerializedValue, source: any): RpcContentType {\r\n if (source instanceof Uint8Array || (Array.isArray(source) && source[0] instanceof Uint8Array)) {\r\n return RpcContentType.Binary;\r\n } else if (value.data.length > 0) {\r\n return RpcContentType.Multipart;\r\n } else if (value.stream) {\r\n return RpcContentType.Stream;\r\n } else {\r\n return RpcContentType.Text;\r\n }\r\n }\r\n\r\n /** Constructs a web application request. */\r\n public constructor(client: RpcInterface, operation: string, parameters: any[]) {\r\n super(client, operation, parameters);\r\n this.path = this.protocol.supplyPathForOperation(this.operation, this);\r\n this.method = \"head\";\r\n this._request.headers = {};\r\n }\r\n\r\n /** Sets request header values. */\r\n protected setHeader(name: string, value: string): void {\r\n this._headers[name] = value;\r\n }\r\n\r\n /** Sends the request. */\r\n protected async send(): Promise<number> {\r\n this._loading = true;\r\n await this.setupTransport();\r\n\r\n return new Promise<number>(async (resolve, reject) => {\r\n try {\r\n resolve(await this.performFetch());\r\n } catch (reason) {\r\n reject(new ServerError(-1, typeof (reason) === \"string\" ? reason : \"Server connection error.\"));\r\n }\r\n });\r\n }\r\n\r\n protected override computeRetryAfter(attempts: number): number {\r\n const retryAfter = this._response && this._response.headers.get(\"Retry-After\");\r\n if (retryAfter) {\r\n this.resetTransientFaultCount();\r\n\r\n const r = Number(retryAfter);\r\n if (Number.isFinite(r)) {\r\n return r * 1000;\r\n }\r\n\r\n const d = Date.parse(retryAfter);\r\n if (!Number.isNaN(d)) {\r\n return d - Date.now();\r\n }\r\n } else {\r\n this.recordTransientFault();\r\n }\r\n\r\n return super.computeRetryAfter(attempts);\r\n }\r\n\r\n protected override handleUnknownResponse(code: number) {\r\n if (this.protocol.isTimeout(code)) {\r\n this.reject(new ServerTimeoutError(\"Request timeout.\"));\r\n } else {\r\n this.reject(new ServerError(code, \"Unknown server response code.\"));\r\n }\r\n }\r\n\r\n protected async load(): Promise<RpcSerializedValue> {\r\n return new Promise<RpcSerializedValue>(async (resolve, reject) => {\r\n try {\r\n if (!this._loading)\r\n return;\r\n\r\n const response = this._response;\r\n if (!response) {\r\n reject(new IModelError(BentleyStatus.ERROR, \"Invalid state.\"));\r\n return;\r\n }\r\n\r\n if (this.protocol.protocolVersionHeaderName) {\r\n const version = response.headers.get(this.protocol.protocolVersionHeaderName);\r\n if (version) {\r\n this.responseProtocolVersion = parseInt(version, 10);\r\n }\r\n }\r\n\r\n const contentType = response.headers.get(WEB_RPC_CONSTANTS.CONTENT);\r\n const responseType = WebAppRpcProtocol.computeContentType(contentType);\r\n\r\n if (responseType === RpcContentType.Binary) {\r\n resolve(await this.loadBinary(response));\r\n } else if (responseType === RpcContentType.Multipart) {\r\n resolve(await this.loadMultipart(response, contentType!));\r\n } else {\r\n resolve(await this.loadText(response));\r\n }\r\n\r\n this._loading = false;\r\n this.setLastUpdatedTime();\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.ResponseLoaded, this);\r\n } catch (reason) {\r\n if (!this._loading)\r\n return;\r\n\r\n this._loading = false;\r\n reject(new ServerError(this.metadata.status, typeof (reason) === \"string\" ? reason : \"Unknown server response error.\"));\r\n }\r\n });\r\n }\r\n\r\n /** Override to supply an alternate fetch function. */\r\n protected supplyFetch(): typeof fetch {\r\n return fetch;\r\n }\r\n\r\n /** Override to supply an alternate Request function. */\r\n protected supplyRequest(): typeof Request {\r\n return Request;\r\n }\r\n\r\n private static configureResponse(protocol: WebAppRpcProtocol, request: SerializedRpcRequest, fulfillment: RpcRequestFulfillment, res: HttpServerResponse) {\r\n const success = protocol.getStatus(fulfillment.status) === RpcRequestStatus.Resolved;\r\n // TODO: Use stale-while-revalidate in cache headers. This needs to be tested, and does not currently have support in the router/caching-service.\r\n // This will allow browsers to use stale cached responses while also revalidating with the router, allowing us to start up a backend if necessary.\r\n\r\n // RPC Caching Service uses the s-maxage header to determine the TTL for the redis cache.\r\n const oneHourInSeconds = 3600;\r\n if (success && request.caching === RpcResponseCacheControl.Immutable) {\r\n // If response size is > 50 MB, do not cache it.\r\n if (fulfillment.result.objects.length > (50 * 10**7)) {\r\n res.set(\"Cache-Control\", \"no-store\");\r\n } else if (request.operation.operationName === \"generateTileContent\") {\r\n res.set(\"Cache-Control\", \"no-store\");\r\n } else if (request.operation.operationName === \"getConnectionProps\") {\r\n // GetConnectionprops can't be cached on the browser longer than the lifespan of the backend. The lifespan of backend may shrink too. Keep it at 1 second to be safe.\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 24}, max-age=1, immutable`);\r\n } else if (request.operation.operationName === \"getTileCacheContainerUrl\") {\r\n // getTileCacheContainerUrl returns a SAS with an expiry of 23:59:59. We can't exceed that time when setting the max-age.\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 23}, max-age=${oneHourInSeconds * 23}, immutable`);\r\n } else {\r\n res.set(\"Cache-Control\", `s-maxage=${oneHourInSeconds * 24}, max-age=${oneHourInSeconds * 48}, immutable`);\r\n }\r\n }\r\n\r\n if (fulfillment.retry) {\r\n res.set(\"Retry-After\", fulfillment.retry);\r\n }\r\n }\r\n\r\n private static configureText(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): string {\r\n res.set(WEB_RPC_CONSTANTS.CONTENT, WEB_RPC_CONSTANTS.TEXT);\r\n return (fulfillment.status === 204) ? \"\" : fulfillment.result.objects;\r\n }\r\n\r\n private static configureBinary(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): Buffer {\r\n res.set(WEB_RPC_CONSTANTS.CONTENT, WEB_RPC_CONSTANTS.BINARY);\r\n const data = fulfillment.result.data[0];\r\n return Buffer.isBuffer(data) ? data : Buffer.from(data);\r\n }\r\n\r\n private static configureMultipart(fulfillment: RpcRequestFulfillment, res: HttpServerResponse): ReadableFormData {\r\n const response = RpcMultipart.createStream(fulfillment.result);\r\n const headers = response.getHeaders();\r\n for (const header in headers) {\r\n if (headers.hasOwnProperty(header)) {\r\n res.set(header, headers[header]);\r\n }\r\n }\r\n\r\n return response;\r\n }\r\n\r\n private static configureStream(fulfillment: RpcRequestFulfillment) {\r\n return fulfillment.result.stream!;\r\n }\r\n\r\n private static parseFromPath(operation: SerializedRpcOperation): RpcSerializedValue {\r\n const decoded = operation.encodedRequest ? Buffer.from(operation.encodedRequest, \"base64\").toString(\"binary\") : \"\";\r\n return RpcSerializedValue.create(decoded);\r\n }\r\n\r\n private static async parseFromBody(req: HttpServerRequest): Promise<RpcSerializedValue> {\r\n const contentType = WebAppRpcProtocol.computeContentType(req.header(WEB_RPC_CONSTANTS.CONTENT));\r\n if (contentType === RpcContentType.Binary) {\r\n const objects = JSON.stringify([MarshalingBinaryMarker.createDefault()]);\r\n const data = [req.body as Buffer];\r\n return RpcSerializedValue.create(objects, data);\r\n } else if (contentType === RpcContentType.Multipart) {\r\n return RpcMultipart.parseRequest(req);\r\n } else {\r\n return RpcSerializedValue.create(req.body as string);\r\n }\r\n }\r\n\r\n private async performFetch(): Promise<number> {\r\n const requestClass = this.supplyRequest();\r\n const fetchFunction = this.supplyFetch();\r\n\r\n const path = new URL(this.path, typeof (location) !== \"undefined\" ? location.origin : undefined);\r\n if (this._pathSuffix) {\r\n const params = new URLSearchParams();\r\n params.set(\"parameters\", this._pathSuffix);\r\n path.search = `?${params.toString()}`;\r\n }\r\n\r\n const request = new requestClass(path.toString(), this._request);\r\n const response = await fetchFunction(request);\r\n this._response = response;\r\n this.metadata.status = response.status;\r\n return response.status;\r\n }\r\n\r\n private async loadText(response: Response) {\r\n const value = await response.text();\r\n this.metadata.message = value;\r\n return RpcSerializedValue.create(value);\r\n }\r\n\r\n private async loadBinary(response: Response) {\r\n const value = new Uint8Array(await response.arrayBuffer());\r\n const objects = JSON.stringify(MarshalingBinaryMarker.createDefault());\r\n return RpcSerializedValue.create(objects, [value]);\r\n }\r\n\r\n private async loadMultipart(response: Response, contentType: string) {\r\n const data = await response.arrayBuffer();\r\n const value = new RpcMultipartParser(contentType, Buffer.from(data)).parse();\r\n return value;\r\n }\r\n\r\n private async setupTransport(): Promise<void> {\r\n const parameters = (await this.protocol.serialize(this)).parameters;\r\n const transportType = WebAppRpcRequest.computeTransportType(parameters, this.parameters);\r\n\r\n if (transportType === RpcContentType.Binary) {\r\n this.setupBinaryTransport(parameters);\r\n } else if (transportType === RpcContentType.Multipart) {\r\n this.setupMultipartTransport(parameters);\r\n } else {\r\n this.setupTextTransport(parameters);\r\n }\r\n }\r\n\r\n private setupBinaryTransport(parameters: RpcSerializedValue) {\r\n this._headers[WEB_RPC_CONSTANTS.CONTENT] = WEB_RPC_CONSTANTS.BINARY;\r\n this._request.method = \"post\";\r\n this._request.body = parameters.data[0];\r\n }\r\n\r\n private setupMultipartTransport(parameters: RpcSerializedValue) {\r\n // IMPORTANT: do not set a multipart Content-Type header value. The browser does this automatically!\r\n delete this._headers[WEB_RPC_CONSTANTS.CONTENT];\r\n this._request.method = \"post\";\r\n this._request.body = RpcMultipart.createForm(parameters);\r\n }\r\n\r\n private setupTextTransport(parameters: RpcSerializedValue) {\r\n if (this.operation.policy.allowResponseCaching(this)) {\r\n const encodedBody = btoa(parameters.objects); // eslint-disable-line deprecation/deprecation\r\n if (encodedBody.length <= WebAppRpcRequest.maxUrlComponentSize) {\r\n this._request.method = \"get\";\r\n this._request.body = undefined;\r\n delete this._headers[WEB_RPC_CONSTANTS.CONTENT];\r\n this._pathSuffix = encodedBody;\r\n return;\r\n }\r\n }\r\n\r\n this._pathSuffix = \"\";\r\n this._headers[WEB_RPC_CONSTANTS.CONTENT] = WEB_RPC_CONSTANTS.TEXT;\r\n this._request.method = \"post\";\r\n this._request.body = parameters.objects;\r\n }\r\n}\r\n"]}
package/lib/esm/Code.d.ts CHANGED
@@ -3,7 +3,9 @@
3
3
  */
4
4
  import { GuidString, Id64String } from "@itwin/core-bentley";
5
5
  import { IModel } from "./IModel";
6
- /** The props that hold the identity of the object defining the uniqueness scope for a set of Code values.
6
+ /**
7
+ * The identity of the element defining the scope for a Code value.
8
+ * For query input, may either be an ElementId or a FederationGuid. When returned from a query, it will be an ElementId.
7
9
  * @public
8
10
  * @extensions
9
11
  */
@@ -13,18 +15,22 @@ export declare type CodeScopeProps = Id64String | GuidString;
13
15
  * @extensions
14
16
  */
15
17
  export interface CodeProps {
16
- spec: Id64String;
18
+ /** Either the stringified 64-bit Id of the CodeSpec for this code, or the name of the CodeSpec. */
19
+ spec: Id64String | string;
20
+ /** Either the ElementId or the FederationGuid of the element that provides the scope for this code. */
17
21
  scope: CodeScopeProps;
22
+ /** the value of this code. May be undefined. */
18
23
  value?: string;
19
24
  }
20
- /** A three-part structure containing information about the [Code]($docs/bis/guide/fundamentals/codes) of an Element
25
+ /**
26
+ * A three-part structure containing information about the [Code]($docs/bis/guide/fundamentals/codes) of an Element
21
27
  * @public
22
28
  */
23
29
  export declare class Code implements CodeProps {
24
30
  /** The id of the [CodeSpec]($docs/bis/guide/fundamentals/codes.md#codespec) of the Element */
25
31
  spec: Id64String;
26
32
  /** The [CodeScope]($docs/bis/guide/fundamentals/codes.md#codescope-property) of the Element */
27
- scope: string;
33
+ scope: Id64String;
28
34
  /** The [CodeValue]($docs/bis/guide/fundamentals/codes.md#codevalue-property) of the Element
29
35
  * @note Leading and trailing whitespace is invalid so is automatically trimmed.
30
36
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Code.d.ts","sourceRoot":"","sources":["../../src/Code.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAQ,UA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,IAAI,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACI,UAAU,EAAE,GAAG,CAAC;IAEvB;OACG;IACH,OAAO;IAkBP;;;OAGG;WACW,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,gBAAgB,GAAG,QAAQ;IAItI;;OAEG;WACW,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,QAAQ;IAIrG,wDAAwD;IACxD,IAAW,OAAO,IAAI,OAAO,CAAkC;IAE/D,uCAAuC;IACvC,IAAW,SAAS,IAAI,aAAa,CAAC,IAAI,CAA2C;IACrF,IAAW,SAAS,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,EAAiD;IAEnG,0MAA0M;IAC1M,IAAW,QAAQ,IAAI,aAAa,CAAC,gBAAgB,CAEpD;IACD,IAAW,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC,gBAAgB,EAKtD;IAED;;OAEG;IACH,IAAW,mBAAmB,IAAI,OAAO,CAKxC;IACD,IAAW,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAG5C;CACF"}
package/lib/esm/Code.js CHANGED
@@ -6,7 +6,8 @@
6
6
  * @module Codes
7
7
  */
8
8
  import { Id64, JsonUtils } from "@itwin/core-bentley";
9
- /** A three-part structure containing information about the [Code]($docs/bis/guide/fundamentals/codes) of an Element
9
+ /**
10
+ * A three-part structure containing information about the [Code]($docs/bis/guide/fundamentals/codes) of an Element
10
11
  * @public
11
12
  */
12
13
  export class Code {