@salesforce/sdk-core 1.43.0 → 1.44.0

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.
@@ -20,9 +20,27 @@
20
20
  export declare class JsonRpcClient {
21
21
  private nextRequestId;
22
22
  private pending;
23
+ private notificationHandlers;
23
24
  constructor();
25
+ /**
26
+ * Register a handler for a specific JSON-RPC notification method
27
+ *
28
+ * Subclasses can register handlers to process specific notification types.
29
+ * When a notification with the registered method is received, the handler
30
+ * will be invoked with the notification params.
31
+ *
32
+ * @param method - The notification method to handle (e.g., "ui/notifications/host-context-changed")
33
+ * @param handler - Callback function to process the notification params
34
+ *
35
+ * @example
36
+ * this.registerNotificationHandler("ui/notifications/host-context-changed", (params) => {
37
+ * this.handleHostContextChanged(params);
38
+ * });
39
+ */
40
+ protected registerNotificationHandler(method: string, handler: (params: unknown) => void): void;
24
41
  /**
25
42
  * Handle incoming JSON-RPC messages from parent window
43
+ * Processes both responses (for requests) and notifications
26
44
  */
27
45
  private onMessage;
28
46
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"jsonrpc-client.d.ts","sourceRoot":"","sources":["../src/jsonrpc-client.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,OAAO,CAAuC;;IAOtD;;OAEG;IACH,OAAO,CAAC,SAAS,CAqBf;IAEF;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EACrD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,GACb,OAAO,CAAC,OAAO,CAAC;CAiBnB"}
1
+ {"version":3,"file":"jsonrpc-client.d.ts","sourceRoot":"","sources":["../src/jsonrpc-client.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,OAAO,CAAuC;IACtD,OAAO,CAAC,oBAAoB,CAAgD;;IAO5E;;;;;;;;;;;;;;OAcG;IACH,SAAS,CAAC,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAI/F;;;OAGG;IACH,OAAO,CAAC,SAAS,CA4Bf;IAEF;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EACrD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,GACb,OAAO,CAAC,OAAO,CAAC;CAiBnB"}
@@ -1,4 +1,4 @@
1
- import { isJsonRpcResponse, isJsonRpcErrorResponse } from "./jsonrpc.js";
1
+ import { isJsonRpcResponse, isJsonRpcErrorResponse, isJsonRpcNotification } from "./jsonrpc.js";
2
2
  /**
3
3
  * Base class for JSON-RPC 2.0 clients using postMessage
4
4
  *
@@ -21,30 +21,57 @@ import { isJsonRpcResponse, isJsonRpcErrorResponse } from "./jsonrpc.js";
21
21
  export class JsonRpcClient {
22
22
  nextRequestId = 1;
23
23
  pending = new Map();
24
+ notificationHandlers = new Map();
24
25
  constructor() {
25
26
  // Listen for JSON-RPC messages from parent window
26
27
  window.addEventListener("message", this.onMessage);
27
28
  }
29
+ /**
30
+ * Register a handler for a specific JSON-RPC notification method
31
+ *
32
+ * Subclasses can register handlers to process specific notification types.
33
+ * When a notification with the registered method is received, the handler
34
+ * will be invoked with the notification params.
35
+ *
36
+ * @param method - The notification method to handle (e.g., "ui/notifications/host-context-changed")
37
+ * @param handler - Callback function to process the notification params
38
+ *
39
+ * @example
40
+ * this.registerNotificationHandler("ui/notifications/host-context-changed", (params) => {
41
+ * this.handleHostContextChanged(params);
42
+ * });
43
+ */
44
+ registerNotificationHandler(method, handler) {
45
+ this.notificationHandlers.set(method, handler);
46
+ }
28
47
  /**
29
48
  * Handle incoming JSON-RPC messages from parent window
49
+ * Processes both responses (for requests) and notifications
30
50
  */
31
51
  onMessage = (event) => {
32
52
  const data = event.data;
33
- // Use type guard for validation with type narrowing
34
- if (!isJsonRpcResponse(data)) {
53
+ // Handle JSON-RPC responses
54
+ if (isJsonRpcResponse(data)) {
55
+ const slot = this.pending.get(data.id);
56
+ if (!slot) {
57
+ return;
58
+ }
59
+ this.pending.delete(data.id);
60
+ // Type guard provides proper type narrowing
61
+ if (isJsonRpcErrorResponse(data)) {
62
+ slot.reject(new Error(data.error.message || "Request failed"));
63
+ }
64
+ else {
65
+ slot.resolve(data.result);
66
+ }
35
67
  return;
36
68
  }
37
- const slot = this.pending.get(data.id);
38
- if (!slot) {
39
- return;
40
- }
41
- this.pending.delete(data.id);
42
- // Type guard provides proper type narrowing
43
- if (isJsonRpcErrorResponse(data)) {
44
- slot.reject(new Error(data.error.message || "Request failed"));
45
- }
46
- else {
47
- slot.resolve(data.result);
69
+ // Handle JSON-RPC notifications
70
+ if (isJsonRpcNotification(data)) {
71
+ const handler = this.notificationHandlers.get(data.method);
72
+ if (handler) {
73
+ handler(data.params);
74
+ }
48
75
  }
49
76
  };
50
77
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sdk-core",
3
- "version": "1.43.0",
3
+ "version": "1.44.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "6987ff60e5d99e64b34cbe2383e54cda1727e151"
34
+ "gitHead": "00f5b3b58d400b13a1b1130d11f571c2e1366cb4"
35
35
  }