@salesforce/webapp-experimental 1.21.0 → 1.22.1

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.
@@ -5,23 +5,23 @@
5
5
  */
6
6
  import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
7
7
  import { getCurrentUser } from "./user.js";
8
- // Mock the baseDataClient
9
- vi.mock("../clients.js", () => {
10
- const mockGet = vi.fn();
8
+ import { executeGraphQL } from "../graphql.js";
9
+ vi.mock("../graphql", async () => {
11
10
  return {
12
- baseDataClient: {
13
- get: mockGet,
14
- },
11
+ gql: vi.fn((strings, ...values) => {
12
+ return strings.reduce((prev, curr, i) => {
13
+ return prev + curr + (values[i] ?? "");
14
+ }, "");
15
+ }),
16
+ executeGraphQL: vi.fn(),
15
17
  };
16
18
  });
17
19
  // Get reference to the mocked function for assertions
18
- const { baseDataClient } = await import("../clients.js");
19
- const mockGet = vi.mocked(baseDataClient.get);
20
+ const mockGraphql = vi.mocked(executeGraphQL);
20
21
  // Mock console.error to avoid noise in test output
21
- const mockConsoleError = vi
22
- .spyOn(console, "error")
23
- // eslint-disable-next-line @typescript-eslint/no-empty-function
24
- .mockImplementation(() => { });
22
+ const mockConsoleError = vi.spyOn(console, "error").mockImplementation(() => {
23
+ /* noop */
24
+ });
25
25
  describe("User API Utils", () => {
26
26
  beforeEach(() => {
27
27
  vi.clearAllMocks();
@@ -30,42 +30,31 @@ describe("User API Utils", () => {
30
30
  mockConsoleError.mockClear();
31
31
  });
32
32
  describe("getCurrentUser", () => {
33
- const mockChatterUserResponse = {
34
- json: vi.fn().mockResolvedValue({
35
- id: "005000000000001",
36
- name: "John Doe",
37
- email: "john.doe@company.com",
38
- username: "john.doe@company.com",
39
- }),
33
+ const mockResponse = {
34
+ uiapi: {
35
+ currentUser: {
36
+ Id: "005000000000001",
37
+ Name: { value: "John Doe" },
38
+ },
39
+ },
40
40
  };
41
- it("successfully fetches current user with complete data", async () => {
42
- mockGet.mockResolvedValue(mockChatterUserResponse);
41
+ it("successfully fetches current user", async () => {
42
+ mockGraphql.mockResolvedValue(mockResponse);
43
43
  const result = await getCurrentUser();
44
- expect(mockGet).toHaveBeenCalledWith("/chatter/users/me");
44
+ expect(mockGraphql).toHaveBeenCalledWith(expect.any(String));
45
45
  expect(result).toEqual({
46
46
  id: "005000000000001",
47
47
  name: "John Doe",
48
48
  });
49
49
  });
50
- it("handles user with minimal data", async () => {
51
- mockGet.mockResolvedValue({
52
- json: vi.fn().mockResolvedValue({
53
- id: "005000000000002",
54
- name: "Jane Smith",
55
- }),
56
- });
57
- const result = await getCurrentUser();
58
- expect(result).toEqual({
59
- id: "005000000000002",
60
- name: "Jane Smith",
61
- });
62
- });
63
50
  it('falls back to "User" when name is empty', async () => {
64
- mockGet.mockResolvedValue({
65
- json: vi.fn().mockResolvedValue({
66
- id: "005000000000003",
67
- name: "",
68
- }),
51
+ mockGraphql.mockResolvedValue({
52
+ uiapi: {
53
+ currentUser: {
54
+ Id: "005000000000003",
55
+ Name: { value: "" },
56
+ },
57
+ },
69
58
  });
70
59
  const result = await getCurrentUser();
71
60
  expect(result).toEqual({
@@ -74,11 +63,13 @@ describe("User API Utils", () => {
74
63
  });
75
64
  });
76
65
  it('falls back to "User" when name is null', async () => {
77
- mockGet.mockResolvedValue({
78
- json: vi.fn().mockResolvedValue({
79
- id: "005000000000004",
80
- name: null,
81
- }),
66
+ mockGraphql.mockResolvedValue({
67
+ uiapi: {
68
+ currentUser: {
69
+ Id: "005000000000004",
70
+ Name: { value: null },
71
+ },
72
+ },
82
73
  });
83
74
  const result = await getCurrentUser();
84
75
  expect(result).toEqual({
@@ -87,10 +78,13 @@ describe("User API Utils", () => {
87
78
  });
88
79
  });
89
80
  it('falls back to "User" when name is undefined', async () => {
90
- mockGet.mockResolvedValue({
91
- json: vi.fn().mockResolvedValue({
92
- id: "005000000000005",
93
- }),
81
+ mockGraphql.mockResolvedValue({
82
+ uiapi: {
83
+ currentUser: {
84
+ Id: "005000000000005",
85
+ Name: { value: undefined },
86
+ },
87
+ },
94
88
  });
95
89
  const result = await getCurrentUser();
96
90
  expect(result).toEqual({
@@ -98,64 +92,18 @@ describe("User API Utils", () => {
98
92
  name: "User",
99
93
  });
100
94
  });
101
- it("throws error when Chatter API request fails", async () => {
102
- const apiError = new Error("Chatter API error");
103
- mockGet.mockRejectedValue(apiError);
104
- await expect(getCurrentUser()).rejects.toThrow("Chatter API error");
95
+ it("throws error when request fails", async () => {
96
+ const apiError = new Error("Bad stuff");
97
+ mockGraphql.mockRejectedValue(apiError);
98
+ await expect(getCurrentUser()).rejects.toThrow("Bad stuff");
105
99
  expect(mockConsoleError).toHaveBeenCalledWith("Error fetching user data:", apiError);
106
100
  });
107
101
  it("throws error when no user data is found", async () => {
108
- mockGet.mockResolvedValue({
109
- json: vi.fn().mockResolvedValue(null),
110
- });
111
- await expect(getCurrentUser()).rejects.toThrow("No user data found in Chatter API response");
112
- expect(mockConsoleError).toHaveBeenCalled();
113
- });
114
- it("throws error when user data is undefined", async () => {
115
- mockGet.mockResolvedValue({
116
- json: vi.fn().mockResolvedValue(undefined),
102
+ mockGraphql.mockResolvedValue({
103
+ uiapi: {},
117
104
  });
118
- await expect(getCurrentUser()).rejects.toThrow("No user data found in Chatter API response");
105
+ await expect(getCurrentUser()).rejects.toThrow("No user data found");
119
106
  expect(mockConsoleError).toHaveBeenCalled();
120
107
  });
121
- it("throws error when no user ID is found", async () => {
122
- mockGet.mockResolvedValue({
123
- json: vi.fn().mockResolvedValue({
124
- name: "John Doe",
125
- }),
126
- });
127
- await expect(getCurrentUser()).rejects.toThrow("No user data found in Chatter API response");
128
- expect(mockConsoleError).toHaveBeenCalled();
129
- });
130
- it("throws error when user ID is empty string", async () => {
131
- mockGet.mockResolvedValue({
132
- json: vi.fn().mockResolvedValue({
133
- id: "",
134
- name: "John Doe",
135
- }),
136
- });
137
- await expect(getCurrentUser()).rejects.toThrow("No user data found in Chatter API response");
138
- expect(mockConsoleError).toHaveBeenCalled();
139
- });
140
- it("handles network errors gracefully", async () => {
141
- const networkError = new Error("Network timeout");
142
- networkError.name = "NetworkError";
143
- mockGet.mockRejectedValue(networkError);
144
- await expect(getCurrentUser()).rejects.toThrow("Network timeout");
145
- expect(mockConsoleError).toHaveBeenCalledWith("Error fetching user data:", networkError);
146
- });
147
- it("handles 401 unauthorized errors", async () => {
148
- const unauthorizedError = new Error("Unauthorized");
149
- unauthorizedError.name = "UnauthorizedError";
150
- mockGet.mockRejectedValue(unauthorizedError);
151
- await expect(getCurrentUser()).rejects.toThrow("Unauthorized");
152
- expect(mockConsoleError).toHaveBeenCalledWith("Error fetching user data:", unauthorizedError);
153
- });
154
- it("handles response with invalid data structure", async () => {
155
- mockGet.mockResolvedValue({
156
- json: vi.fn().mockResolvedValue("invalid data"),
157
- });
158
- await expect(getCurrentUser()).rejects.toThrow("No user data found in Chatter API response");
159
- });
160
108
  });
161
109
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-experimental",
3
3
  "description": "[experimental] Core package for Salesforce Web Applications",
4
- "version": "1.21.0",
4
+ "version": "1.22.1",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -38,8 +38,8 @@
38
38
  "test:coverage": "vitest run --coverage"
39
39
  },
40
40
  "dependencies": {
41
- "@conduit-client/salesforce-lightning-service-worker": "^3.7.0",
42
41
  "@salesforce/core": "^8.23.4",
42
+ "@salesforce/sdk-data": "^1.22.0",
43
43
  "axios": "^1.7.7",
44
44
  "micromatch": "^4.0.8",
45
45
  "path-to-regexp": "^8.3.0"
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "8a7b85936ce26a4200ee052fb09f981e738bdb89"
57
+ "gitHead": "b07f50207ad2ffe2f2edf124fc373731d4101f51"
58
58
  }
@@ -1,14 +0,0 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- /**
7
- * Client for querying or mutating data via an Apex class methods that have
8
- * been annotated as @AuraEnabled
9
- */
10
- export declare const apexClient: {
11
- get: (className: string, methodName: string, params?: Record<string, unknown>) => Promise<unknown>;
12
- post: (className: string, methodName: string, params?: Record<string, unknown>) => Promise<unknown>;
13
- };
14
- //# sourceMappingURL=apex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apex.d.ts","sourceRoot":"","sources":["../../src/api/apex.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;;GAGG;AACH,eAAO,MAAM,UAAU;qBACL,MAAM,cAAc,MAAM,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;sBAG3D,MAAM,cAAc,MAAM,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG9E,CAAC"}
package/dist/api/apex.js DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- import { API_VERSION, createClient } from "./clients.js";
7
- const client = createClient(`/lwr/apex/v${API_VERSION}`);
8
- /**
9
- * Client for querying or mutating data via an Apex class methods that have
10
- * been annotated as @AuraEnabled
11
- */
12
- export const apexClient = {
13
- get: (className, methodName, params) => {
14
- return executeApex("get", className, methodName, params);
15
- },
16
- post: (className, methodName, params) => {
17
- return executeApex("post", className, methodName, params);
18
- },
19
- };
20
- async function executeApex(method, className, methodName, params) {
21
- const res = await client[method](`/${className}/${methodName}`, params);
22
- return await res.json();
23
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- export {};
7
- //# sourceMappingURL=apex.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apex.test.d.ts","sourceRoot":"","sources":["../../src/api/apex.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -1,66 +0,0 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
7
- import { apexClient } from "./apex.js";
8
- import { createClient } from "./clients.js";
9
- vi.mock("./clients.js", () => ({
10
- API_VERSION: "65.0",
11
- createClient: vi.fn().mockReturnValue({
12
- get: vi.fn(),
13
- post: vi.fn(),
14
- }),
15
- }));
16
- describe("apexClient", () => {
17
- let mockClient;
18
- let mockResponse;
19
- beforeEach(async () => {
20
- mockResponse = {
21
- json: vi.fn(),
22
- };
23
- mockClient = vi.mocked(createClient).mock.results[0].value;
24
- mockClient.get.mockResolvedValue(mockResponse);
25
- mockClient.post.mockResolvedValue(mockResponse);
26
- vi.mocked(createClient).mockReturnValue(mockClient);
27
- });
28
- afterEach(() => {
29
- mockClient.get.mockClear();
30
- mockClient.post.mockClear();
31
- });
32
- describe("get", () => {
33
- it("should pass parameters to GET request", async () => {
34
- const params = { id: "123", name: "test" };
35
- const mockData = { result: "success" };
36
- mockResponse.json.mockResolvedValue(mockData);
37
- const result = await apexClient.get("TestClass", "testMethod", params);
38
- expect(mockClient.get).toHaveBeenCalledWith("/TestClass/testMethod", params);
39
- expect(result).toEqual(mockData);
40
- });
41
- it("should handle empty parameters", async () => {
42
- const mockData = { result: "success" };
43
- mockResponse.json.mockResolvedValue(mockData);
44
- const result = await apexClient.get("TestClass", "testMethod", {});
45
- expect(mockClient.get).toHaveBeenCalledWith("/TestClass/testMethod", {});
46
- expect(result).toEqual(mockData);
47
- });
48
- });
49
- describe("post", () => {
50
- it("should pass parameters to POST request", async () => {
51
- const params = { name: "new item", value: 42 };
52
- const mockData = { id: "abc123", result: "created" };
53
- mockResponse.json.mockResolvedValue(mockData);
54
- const result = await apexClient.post("TestClass", "createMethod", params);
55
- expect(mockClient.post).toHaveBeenCalledWith("/TestClass/createMethod", params);
56
- expect(result).toEqual(mockData);
57
- });
58
- it("should handle empty parameters", async () => {
59
- const mockData = { result: "success" };
60
- mockResponse.json.mockResolvedValue(mockData);
61
- const result = await apexClient.post("TestClass", "testMethod", {});
62
- expect(mockClient.post).toHaveBeenCalledWith("/TestClass/testMethod", {});
63
- expect(result).toEqual(mockData);
64
- });
65
- });
66
- });