@salesforce/sdk-core 1.30.1 → 1.32.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.
package/dist/index.d.ts CHANGED
@@ -9,4 +9,7 @@ export type { AlertOptions, MessageLevel, ModalOptions, ToastOptions, Theme, The
9
9
  export type { DataSDK, GraphQLResponse, LabelRequest, ResourceUrlRequest, SchemaDescriptor, SchemaRequest, UserInfo, } from "./data.js";
10
10
  export type { LightningSDK, LMSMessage, LMSSubscription, MessageChannel } from "./lightning.js";
11
11
  export type { OpenAISDK, SalesforceACCSDK } from "./platforms.js";
12
+ export type { JsonRpcBase, JsonRpcRequest, JsonRpcError, JsonRpcSuccessResponse, JsonRpcErrorResponse, JsonRpcResponse, JsonRpcNotification, JsonRpcMessage, JsonRpcPendingRequest, JsonRpcPendingRequestMap, } from "./jsonrpc.js";
13
+ export { isJsonRpcBase, isJsonRpcSuccessResponse, isJsonRpcErrorResponse, isJsonRpcResponse, isJsonRpcNotification, isJsonRpcRequest, } from "./jsonrpc.js";
14
+ export { JsonRpcClient } from "./jsonrpc-client.js";
12
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGnD,YAAY,EACX,WAAW,EACX,OAAO,EACP,WAAW,EACX,eAAe,EACf,QAAQ,EACR,SAAS,GACT,MAAM,WAAW,CAAC;AAGnB,YAAY,EACX,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,SAAS,EACT,OAAO,GACP,MAAM,WAAW,CAAC;AAGnB,YAAY,EACX,OAAO,EACP,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,QAAQ,GACR,MAAM,WAAW,CAAC;AAGnB,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhG,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGnD,YAAY,EACX,WAAW,EACX,OAAO,EACP,WAAW,EACX,eAAe,EACf,QAAQ,EACR,SAAS,GACT,MAAM,WAAW,CAAC;AAGnB,YAAY,EACX,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,SAAS,EACT,OAAO,GACP,MAAM,WAAW,CAAC;AAGnB,YAAY,EACX,OAAO,EACP,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,QAAQ,GACR,MAAM,WAAW,CAAC;AAGnB,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhG,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlE,YAAY,EACX,WAAW,EACX,cAAc,EACd,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,wBAAwB,GACxB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,aAAa,EACb,wBAAwB,EACxB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,GAChB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -5,3 +5,5 @@
5
5
  */
6
6
  // Surface detection
7
7
  export { Surface, getSurface } from "./surface.js";
8
+ export { isJsonRpcBase, isJsonRpcSuccessResponse, isJsonRpcErrorResponse, isJsonRpcResponse, isJsonRpcNotification, isJsonRpcRequest, } from "./jsonrpc.js";
9
+ export { JsonRpcClient } from "./jsonrpc-client.js";
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Base class for JSON-RPC 2.0 clients using postMessage
3
+ *
4
+ * This class provides core JSON-RPC client functionality for MCP Apps implementations.
5
+ * It handles request/response correlation, message validation, and error handling.
6
+ *
7
+ * Subclasses should extend this class and use the protected `request()` method
8
+ * to send JSON-RPC requests to the parent window.
9
+ *
10
+ * @example
11
+ * export class MCPAppsViewSDK extends JsonRpcClient implements ViewSDK {
12
+ * async displayAlert(options: AlertOptions): Promise<void> {
13
+ * await this.request("ui/message", {
14
+ * role: "user",
15
+ * content: { type: "text", text: options.message }
16
+ * });
17
+ * }
18
+ * }
19
+ */
20
+ export declare class JsonRpcClient {
21
+ private nextRequestId;
22
+ private pending;
23
+ constructor();
24
+ /**
25
+ * Handle incoming JSON-RPC messages from parent window
26
+ */
27
+ private onMessage;
28
+ /**
29
+ * Send a JSON-RPC request to the parent window
30
+ *
31
+ * @param method - The JSON-RPC method name
32
+ * @param params - The method parameters
33
+ * @returns Promise that resolves with the result or rejects with error
34
+ *
35
+ * @example
36
+ * const result = await this.request("ui/message", {
37
+ * role: "user",
38
+ * content: { type: "text", text: "Hello" }
39
+ * });
40
+ */
41
+ protected request<TParams = unknown, TResult = unknown>(method: string, params: TParams): Promise<TResult>;
42
+ }
43
+ //# sourceMappingURL=jsonrpc-client.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,79 @@
1
+ import { isJsonRpcResponse, isJsonRpcErrorResponse } from "./jsonrpc.js";
2
+ /**
3
+ * Base class for JSON-RPC 2.0 clients using postMessage
4
+ *
5
+ * This class provides core JSON-RPC client functionality for MCP Apps implementations.
6
+ * It handles request/response correlation, message validation, and error handling.
7
+ *
8
+ * Subclasses should extend this class and use the protected `request()` method
9
+ * to send JSON-RPC requests to the parent window.
10
+ *
11
+ * @example
12
+ * export class MCPAppsViewSDK extends JsonRpcClient implements ViewSDK {
13
+ * async displayAlert(options: AlertOptions): Promise<void> {
14
+ * await this.request("ui/message", {
15
+ * role: "user",
16
+ * content: { type: "text", text: options.message }
17
+ * });
18
+ * }
19
+ * }
20
+ */
21
+ export class JsonRpcClient {
22
+ nextRequestId = 1;
23
+ pending = new Map();
24
+ constructor() {
25
+ // Listen for JSON-RPC messages from parent window
26
+ window.addEventListener("message", this.onMessage);
27
+ }
28
+ /**
29
+ * Handle incoming JSON-RPC messages from parent window
30
+ */
31
+ onMessage = (event) => {
32
+ const data = event.data;
33
+ // Use type guard for validation with type narrowing
34
+ if (!isJsonRpcResponse(data)) {
35
+ return;
36
+ }
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);
48
+ }
49
+ };
50
+ /**
51
+ * Send a JSON-RPC request to the parent window
52
+ *
53
+ * @param method - The JSON-RPC method name
54
+ * @param params - The method parameters
55
+ * @returns Promise that resolves with the result or rejects with error
56
+ *
57
+ * @example
58
+ * const result = await this.request("ui/message", {
59
+ * role: "user",
60
+ * content: { type: "text", text: "Hello" }
61
+ * });
62
+ */
63
+ request(method, params) {
64
+ const id = this.nextRequestId++;
65
+ const message = {
66
+ jsonrpc: "2.0",
67
+ id,
68
+ method,
69
+ params,
70
+ };
71
+ return new Promise((resolve, reject) => {
72
+ this.pending.set(id, {
73
+ resolve: resolve,
74
+ reject,
75
+ });
76
+ window.parent?.postMessage(message, "*");
77
+ });
78
+ }
79
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ /**
7
+ * JSON-RPC 2.0 Protocol Types
8
+ *
9
+ * This module provides TypeScript types and utilities for implementing
10
+ * JSON-RPC 2.0 protocol as specified in https://www.jsonrpc.org/specification
11
+ *
12
+ * JSON-RPC 2.0 is a stateless, light-weight remote procedure call (RPC) protocol.
13
+ * Used for iframe communication via postMessage in MCP Apps surface.
14
+ *
15
+ * @example
16
+ * // Creating a request
17
+ * const request: JsonRpcRequest = {
18
+ * jsonrpc: "2.0",
19
+ * id: 1,
20
+ * method: "ui/message",
21
+ * params: { role: "user", content: { type: "text", text: "Hello" } }
22
+ * };
23
+ * window.parent.postMessage(request, "*");
24
+ *
25
+ * @example
26
+ * // Validating a response
27
+ * window.addEventListener("message", (event) => {
28
+ * if (isJsonRpcResponse(event.data)) {
29
+ * if (isJsonRpcErrorResponse(event.data)) {
30
+ * console.error("Error:", event.data.error.message);
31
+ * } else {
32
+ * console.log("Result:", event.data.result);
33
+ * }
34
+ * }
35
+ * });
36
+ */
37
+ /**
38
+ * JSON-RPC 2.0 base message with required version field
39
+ */
40
+ export interface JsonRpcBase {
41
+ jsonrpc: "2.0";
42
+ }
43
+ /**
44
+ * JSON-RPC 2.0 Request with numeric ID (per spec)
45
+ */
46
+ export interface JsonRpcRequest<TParams = unknown> extends JsonRpcBase {
47
+ id: number;
48
+ method: string;
49
+ params?: TParams;
50
+ }
51
+ /**
52
+ * JSON-RPC 2.0 Error object structure
53
+ */
54
+ export interface JsonRpcError {
55
+ code: number;
56
+ message?: string;
57
+ data?: unknown;
58
+ }
59
+ /**
60
+ * JSON-RPC 2.0 Success Response
61
+ */
62
+ export interface JsonRpcSuccessResponse<TResult = unknown> extends JsonRpcBase {
63
+ id: number;
64
+ result: TResult;
65
+ }
66
+ /**
67
+ * JSON-RPC 2.0 Error Response
68
+ */
69
+ export interface JsonRpcErrorResponse extends JsonRpcBase {
70
+ id: number;
71
+ error: JsonRpcError;
72
+ }
73
+ /**
74
+ * JSON-RPC 2.0 Notification (no id, no response expected)
75
+ */
76
+ export interface JsonRpcNotification<TParams = unknown> extends JsonRpcBase {
77
+ method: string;
78
+ params?: TParams;
79
+ }
80
+ /**
81
+ * Union of all JSON-RPC response types
82
+ */
83
+ export type JsonRpcResponse<TResult = unknown> = JsonRpcSuccessResponse<TResult> | JsonRpcErrorResponse;
84
+ /**
85
+ * Union of all JSON-RPC message types
86
+ */
87
+ export type JsonRpcMessage<TRequest = unknown, TResponse = unknown> = JsonRpcRequest<TRequest> | JsonRpcResponse<TResponse> | JsonRpcNotification;
88
+ /**
89
+ * Pending request resolver functions
90
+ */
91
+ export interface JsonRpcPendingRequest {
92
+ resolve: (value: unknown) => void;
93
+ reject: (error: unknown) => void;
94
+ }
95
+ /**
96
+ * Map of pending JSON-RPC requests by numeric ID
97
+ */
98
+ export type JsonRpcPendingRequestMap = Map<number, JsonRpcPendingRequest>;
99
+ /**
100
+ * Type guard to check if message is valid JSON-RPC 2.0 base
101
+ */
102
+ export declare function isJsonRpcBase(data: unknown): data is JsonRpcBase;
103
+ /**
104
+ * Type guard for JSON-RPC success response
105
+ */
106
+ export declare function isJsonRpcSuccessResponse(data: unknown): data is JsonRpcSuccessResponse;
107
+ /**
108
+ * Type guard for JSON-RPC error response
109
+ */
110
+ export declare function isJsonRpcErrorResponse(data: unknown): data is JsonRpcErrorResponse;
111
+ /**
112
+ * Type guard for any JSON-RPC response (success or error)
113
+ */
114
+ export declare function isJsonRpcResponse(data: unknown): data is JsonRpcResponse;
115
+ /**
116
+ * Type guard for JSON-RPC notification
117
+ */
118
+ export declare function isJsonRpcNotification(data: unknown): data is JsonRpcNotification;
119
+ /**
120
+ * Type guard for JSON-RPC request
121
+ */
122
+ export declare function isJsonRpcRequest(data: unknown): data is JsonRpcRequest;
123
+ //# sourceMappingURL=jsonrpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonrpc.d.ts","sourceRoot":"","sources":["../src/jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,KAAK,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,OAAO,GAAG,OAAO,CAAE,SAAQ,WAAW;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,OAAO,GAAG,OAAO,CAAE,SAAQ,WAAW;IAC7E,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,YAAY,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,OAAO,GAAG,OAAO,CAAE,SAAQ,WAAW;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,GAAG,OAAO,IAC1C,sBAAsB,CAAC,OAAO,CAAC,GAC/B,oBAAoB,CAAC;AAExB;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,QAAQ,GAAG,OAAO,EAAE,SAAS,GAAG,OAAO,IAC/D,cAAc,CAAC,QAAQ,CAAC,GACxB,eAAe,CAAC,SAAS,CAAC,GAC1B,mBAAmB,CAAC;AAEvB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;AAE1E;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,WAAW,CAOhE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,sBAAsB,CAOtF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,oBAAoB,CAOlF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,eAAe,CAExE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,mBAAmB,CAOhF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,cAAc,CAQtE"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ /**
7
+ * Type guard to check if message is valid JSON-RPC 2.0 base
8
+ */
9
+ export function isJsonRpcBase(data) {
10
+ return (typeof data === "object" &&
11
+ data !== null &&
12
+ "jsonrpc" in data &&
13
+ data.jsonrpc === "2.0");
14
+ }
15
+ /**
16
+ * Type guard for JSON-RPC success response
17
+ */
18
+ export function isJsonRpcSuccessResponse(data) {
19
+ return (isJsonRpcBase(data) &&
20
+ "id" in data &&
21
+ typeof data.id === "number" &&
22
+ "result" in data);
23
+ }
24
+ /**
25
+ * Type guard for JSON-RPC error response
26
+ */
27
+ export function isJsonRpcErrorResponse(data) {
28
+ return (isJsonRpcBase(data) &&
29
+ "id" in data &&
30
+ typeof data.id === "number" &&
31
+ "error" in data);
32
+ }
33
+ /**
34
+ * Type guard for any JSON-RPC response (success or error)
35
+ */
36
+ export function isJsonRpcResponse(data) {
37
+ return isJsonRpcSuccessResponse(data) || isJsonRpcErrorResponse(data);
38
+ }
39
+ /**
40
+ * Type guard for JSON-RPC notification
41
+ */
42
+ export function isJsonRpcNotification(data) {
43
+ return (isJsonRpcBase(data) &&
44
+ "method" in data &&
45
+ typeof data.method === "string" &&
46
+ !("id" in data));
47
+ }
48
+ /**
49
+ * Type guard for JSON-RPC request
50
+ */
51
+ export function isJsonRpcRequest(data) {
52
+ return (isJsonRpcBase(data) &&
53
+ "id" in data &&
54
+ typeof data.id === "number" &&
55
+ "method" in data &&
56
+ typeof data.method === "string");
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sdk-core",
3
- "version": "1.30.1",
3
+ "version": "1.32.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": "a5cc859ca5bec49a2501879befaa90787bf5c578"
34
+ "gitHead": "a2b51130c4f7fef330a3c0c981c4c90b5b8711c0"
35
35
  }