@salesforce/ui-bundle 12.4.1 → 12.4.3
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/api/utils/user.d.ts
CHANGED
|
@@ -8,9 +8,14 @@ interface User {
|
|
|
8
8
|
name: string;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Fetch current user information from Salesforce
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* Fetch current user information from Salesforce via UI API GraphQL.
|
|
12
|
+
* Guest (unauthenticated) sessions also resolve to a running user record on
|
|
13
|
+
* the platform, so guests are filtered out here rather than relying on a
|
|
14
|
+
* fetch failure to signal "not logged in". UserType is intentionally NOT
|
|
15
|
+
* @optional in the query, but a missing/null/empty value in the response is
|
|
16
|
+
* still treated as an error rather than assumed non-guest, since that's an
|
|
17
|
+
* unexpected shape we can't safely authenticate against.
|
|
18
|
+
* @returns User info or null if no session (or a guest session)
|
|
14
19
|
*/
|
|
15
20
|
export declare function getCurrentUser(): Promise<User | null>;
|
|
16
21
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/api/utils/user.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/api/utils/user.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,UAAU,IAAI;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACb;AA4BD;;;;;;;;;GASG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAuC3D"}
|
package/dist/api/utils/user.js
CHANGED
|
@@ -1,19 +1,45 @@
|
|
|
1
|
-
import { createDataSDK } from "@salesforce/platform-sdk";
|
|
2
|
-
|
|
1
|
+
import { gql, createDataSDK } from "@salesforce/platform-sdk";
|
|
2
|
+
const CURRENT_USER_QUERY = gql`
|
|
3
|
+
query GetCurrentUser {
|
|
4
|
+
uiapi {
|
|
5
|
+
currentUser {
|
|
6
|
+
Id
|
|
7
|
+
Name @optional {
|
|
8
|
+
value
|
|
9
|
+
}
|
|
10
|
+
UserType {
|
|
11
|
+
value
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
3
17
|
async function getCurrentUser() {
|
|
4
18
|
try {
|
|
5
19
|
const sdk = await createDataSDK();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
throw new Error(`HTTP ${response.status}`);
|
|
20
|
+
if (!sdk.graphql) {
|
|
21
|
+
throw new Error("GraphQL client is not available");
|
|
9
22
|
}
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
const result = await sdk.graphql.query({
|
|
24
|
+
query: CURRENT_USER_QUERY
|
|
25
|
+
});
|
|
26
|
+
if (result.errors?.length) {
|
|
27
|
+
throw new Error(`GraphQL errors: ${result.errors.map((e) => e.message).join(", ")}`);
|
|
28
|
+
}
|
|
29
|
+
const currentUser = result.data?.uiapi?.currentUser;
|
|
30
|
+
if (!currentUser?.Id) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const userType = currentUser.UserType?.value;
|
|
34
|
+
if (!userType) {
|
|
35
|
+
throw new Error("Current user response missing UserType");
|
|
36
|
+
}
|
|
37
|
+
if (userType === "Guest") {
|
|
38
|
+
return null;
|
|
13
39
|
}
|
|
14
40
|
return {
|
|
15
|
-
id:
|
|
16
|
-
name:
|
|
41
|
+
id: currentUser.Id,
|
|
42
|
+
name: currentUser.Name?.value || "User"
|
|
17
43
|
};
|
|
18
44
|
} catch (error) {
|
|
19
45
|
console.error("Error fetching user data:", error);
|
package/dist/package.json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/ui-bundle",
|
|
3
3
|
"description": "Core package for Salesforce UI Bundles",
|
|
4
|
-
"version": "12.4.
|
|
4
|
+
"version": "12.4.3",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@salesforce/core": "^8.23.4",
|
|
42
|
-
"@salesforce/platform-sdk": "^12.4.
|
|
42
|
+
"@salesforce/platform-sdk": "^12.4.3",
|
|
43
43
|
"micromatch": "^4.0.8",
|
|
44
44
|
"path-to-regexp": "^8.4.2"
|
|
45
45
|
},
|