@elementor/editor-current-user 4.4.0-1084 → 4.4.0-1086

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.mts CHANGED
@@ -12,11 +12,13 @@ declare const useCurrentUserCapabilities: () => {
12
12
  type User = {
13
13
  suppressedMessages: string[];
14
14
  capabilities: string[];
15
+ restrictions: string[];
15
16
  };
16
17
 
17
18
  type UserModel = {
18
19
  suppressedMessages: string[];
19
20
  capabilities: string[];
21
+ restrictions: string[];
20
22
  };
21
23
 
22
24
  declare const getCurrentUser: () => UserModel | undefined;
@@ -24,6 +26,7 @@ declare const getCurrentUser: () => UserModel | undefined;
24
26
  declare function ensureUser(): Promise<{
25
27
  capabilities: string[];
26
28
  suppressedMessages: string[];
29
+ restrictions: string[];
27
30
  }>;
28
31
 
29
32
  declare function onSetUser(callback: (user: UserModel | null) => void): () => void;
@@ -31,8 +34,17 @@ declare function onSetUser(callback: (user: UserModel | null) => void): () => vo
31
34
  declare const useCurrentUser: () => _tanstack_react_query.UseQueryResult<{
32
35
  capabilities: string[];
33
36
  suppressedMessages: string[];
37
+ restrictions: string[];
34
38
  }, Error>;
35
39
 
36
40
  declare const useUpdateCurrentUser: () => _tanstack_react_query.UseMutationResult<axios.AxiosResponse<Partial<UserModel>, any, {}>, Error, Partial<User>, unknown>;
37
41
 
38
- export { ensureUser, getCurrentUser, onSetUser, useCurrentUser, useCurrentUserCapabilities, useSuppressedMessage, useUpdateCurrentUser };
42
+ declare const DESIGN_RESTRICTION = "design";
43
+ declare const useUserRestrictions: () => {
44
+ isRestricted: (restriction: string) => boolean;
45
+ restrictions: string[] | undefined;
46
+ };
47
+
48
+ declare const useHasContentOnlyAccess: () => boolean;
49
+
50
+ export { DESIGN_RESTRICTION, ensureUser, getCurrentUser, onSetUser, useCurrentUser, useCurrentUserCapabilities, useHasContentOnlyAccess, useSuppressedMessage, useUpdateCurrentUser, useUserRestrictions };
package/dist/index.d.ts CHANGED
@@ -12,11 +12,13 @@ declare const useCurrentUserCapabilities: () => {
12
12
  type User = {
13
13
  suppressedMessages: string[];
14
14
  capabilities: string[];
15
+ restrictions: string[];
15
16
  };
16
17
 
17
18
  type UserModel = {
18
19
  suppressedMessages: string[];
19
20
  capabilities: string[];
21
+ restrictions: string[];
20
22
  };
21
23
 
22
24
  declare const getCurrentUser: () => UserModel | undefined;
@@ -24,6 +26,7 @@ declare const getCurrentUser: () => UserModel | undefined;
24
26
  declare function ensureUser(): Promise<{
25
27
  capabilities: string[];
26
28
  suppressedMessages: string[];
29
+ restrictions: string[];
27
30
  }>;
28
31
 
29
32
  declare function onSetUser(callback: (user: UserModel | null) => void): () => void;
@@ -31,8 +34,17 @@ declare function onSetUser(callback: (user: UserModel | null) => void): () => vo
31
34
  declare const useCurrentUser: () => _tanstack_react_query.UseQueryResult<{
32
35
  capabilities: string[];
33
36
  suppressedMessages: string[];
37
+ restrictions: string[];
34
38
  }, Error>;
35
39
 
36
40
  declare const useUpdateCurrentUser: () => _tanstack_react_query.UseMutationResult<axios.AxiosResponse<Partial<UserModel>, any, {}>, Error, Partial<User>, unknown>;
37
41
 
38
- export { ensureUser, getCurrentUser, onSetUser, useCurrentUser, useCurrentUserCapabilities, useSuppressedMessage, useUpdateCurrentUser };
42
+ declare const DESIGN_RESTRICTION = "design";
43
+ declare const useUserRestrictions: () => {
44
+ isRestricted: (restriction: string) => boolean;
45
+ restrictions: string[] | undefined;
46
+ };
47
+
48
+ declare const useHasContentOnlyAccess: () => boolean;
49
+
50
+ export { DESIGN_RESTRICTION, ensureUser, getCurrentUser, onSetUser, useCurrentUser, useCurrentUserCapabilities, useHasContentOnlyAccess, useSuppressedMessage, useUpdateCurrentUser, useUserRestrictions };
package/dist/index.js CHANGED
@@ -20,13 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ DESIGN_RESTRICTION: () => DESIGN_RESTRICTION,
23
24
  ensureUser: () => ensureUser,
24
25
  getCurrentUser: () => getCurrentUser,
25
26
  onSetUser: () => onSetUser,
26
27
  useCurrentUser: () => useCurrentUser,
27
28
  useCurrentUserCapabilities: () => useCurrentUserCapabilities,
29
+ useHasContentOnlyAccess: () => useHasContentOnlyAccess,
28
30
  useSuppressedMessage: () => useSuppressedMessage,
29
- useUpdateCurrentUser: () => useUpdateCurrentUser
31
+ useUpdateCurrentUser: () => useUpdateCurrentUser,
32
+ useUserRestrictions: () => useUserRestrictions
30
33
  });
31
34
  module.exports = __toCommonJS(index_exports);
32
35
 
@@ -39,8 +42,8 @@ var RESOURCE_URL = "elementor/v1/user-data/current-user";
39
42
  var getUserPayload = { params: { context: "edit" } };
40
43
  var apiClient = {
41
44
  get: () => (0, import_http_client.httpService)().get(RESOURCE_URL, getUserPayload).then((res) => {
42
- const { capabilities = [], suppressedMessages = [] } = res.data;
43
- return { capabilities, suppressedMessages };
45
+ const { capabilities = [], suppressedMessages = [], restrictions = [] } = res.data;
46
+ return { capabilities, suppressedMessages, restrictions };
44
47
  }),
45
48
  update: (data) => (0, import_http_client.httpService)().patch(RESOURCE_URL, {
46
49
  suppressedMessages: data.suppressedMessages
@@ -126,14 +129,31 @@ function onSetUser(callback) {
126
129
  unsubscribeListener();
127
130
  };
128
131
  }
132
+
133
+ // src/use-user-restrictions.ts
134
+ var DESIGN_RESTRICTION = "design";
135
+ var useUserRestrictions = () => {
136
+ const { data } = useCurrentUser();
137
+ const isRestricted = (restriction) => Boolean(data?.restrictions?.includes(restriction));
138
+ return {
139
+ isRestricted,
140
+ restrictions: data?.restrictions
141
+ };
142
+ };
143
+
144
+ // src/use-has-content-only-access.ts
145
+ var useHasContentOnlyAccess = () => useUserRestrictions().isRestricted(DESIGN_RESTRICTION);
129
146
  // Annotate the CommonJS export names for ESM import in node:
130
147
  0 && (module.exports = {
148
+ DESIGN_RESTRICTION,
131
149
  ensureUser,
132
150
  getCurrentUser,
133
151
  onSetUser,
134
152
  useCurrentUser,
135
153
  useCurrentUserCapabilities,
154
+ useHasContentOnlyAccess,
136
155
  useSuppressedMessage,
137
- useUpdateCurrentUser
156
+ useUpdateCurrentUser,
157
+ useUserRestrictions
138
158
  });
139
159
  //# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -7,8 +7,8 @@ var RESOURCE_URL = "elementor/v1/user-data/current-user";
7
7
  var getUserPayload = { params: { context: "edit" } };
8
8
  var apiClient = {
9
9
  get: () => httpService().get(RESOURCE_URL, getUserPayload).then((res) => {
10
- const { capabilities = [], suppressedMessages = [] } = res.data;
11
- return { capabilities, suppressedMessages };
10
+ const { capabilities = [], suppressedMessages = [], restrictions = [] } = res.data;
11
+ return { capabilities, suppressedMessages, restrictions };
12
12
  }),
13
13
  update: (data) => httpService().patch(RESOURCE_URL, {
14
14
  suppressedMessages: data.suppressedMessages
@@ -94,13 +94,30 @@ function onSetUser(callback) {
94
94
  unsubscribeListener();
95
95
  };
96
96
  }
97
+
98
+ // src/use-user-restrictions.ts
99
+ var DESIGN_RESTRICTION = "design";
100
+ var useUserRestrictions = () => {
101
+ const { data } = useCurrentUser();
102
+ const isRestricted = (restriction) => Boolean(data?.restrictions?.includes(restriction));
103
+ return {
104
+ isRestricted,
105
+ restrictions: data?.restrictions
106
+ };
107
+ };
108
+
109
+ // src/use-has-content-only-access.ts
110
+ var useHasContentOnlyAccess = () => useUserRestrictions().isRestricted(DESIGN_RESTRICTION);
97
111
  export {
112
+ DESIGN_RESTRICTION,
98
113
  ensureUser,
99
114
  getCurrentUser,
100
115
  onSetUser,
101
116
  useCurrentUser,
102
117
  useCurrentUserCapabilities,
118
+ useHasContentOnlyAccess,
103
119
  useSuppressedMessage,
104
- useUpdateCurrentUser
120
+ useUpdateCurrentUser,
121
+ useUserRestrictions
105
122
  };
106
123
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-current-user",
3
3
  "description": "Elementor Editor Current User",
4
- "version": "4.4.0-1084",
4
+ "version": "4.4.0-1086",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -36,9 +36,9 @@
36
36
  "react": "^18.3.1"
37
37
  },
38
38
  "dependencies": {
39
- "@elementor/editor-v1-adapters": "4.4.0-1084",
40
- "@elementor/http-client": "4.4.0-1084",
41
- "@elementor/query": "4.4.0-1084"
39
+ "@elementor/editor-v1-adapters": "4.4.0-1086",
40
+ "@elementor/http-client": "4.4.0-1086",
41
+ "@elementor/query": "4.4.0-1086"
42
42
  },
43
43
  "devDependencies": {
44
44
  "tsup": "^8.3.5"
@@ -0,0 +1,77 @@
1
+ import { type UseQueryResult } from '@elementor/query';
2
+ import { renderHook } from '@testing-library/react';
3
+
4
+ import { type User } from '../types';
5
+ import { useCurrentUser } from '../use-current-user';
6
+ import { useHasContentOnlyAccess } from '../use-has-content-only-access';
7
+ import { DESIGN_RESTRICTION, useUserRestrictions } from '../use-user-restrictions';
8
+
9
+ jest.mock( '../use-current-user' );
10
+
11
+ const mockRestrictions = ( restrictions: string[] ) => {
12
+ jest.mocked( useCurrentUser ).mockReturnValue( {
13
+ data: { restrictions },
14
+ } as UseQueryResult< User, Error > );
15
+ };
16
+
17
+ describe( 'useUserRestrictions', () => {
18
+ it( 'should report the restrictions it was given', () => {
19
+ // Arrange
20
+ mockRestrictions( [ 'json-upload' ] );
21
+
22
+ // Act
23
+ const { result } = renderHook( () => useUserRestrictions() );
24
+
25
+ // Assert
26
+ expect( result.current.restrictions ).toEqual( [ 'json-upload' ] );
27
+ expect( result.current.isRestricted( 'json-upload' ) ).toBe( true );
28
+ expect( result.current.isRestricted( DESIGN_RESTRICTION ) ).toBe( false );
29
+ } );
30
+
31
+ it( 'should report nothing as restricted while the user data is unavailable', () => {
32
+ // Arrange
33
+ jest.mocked( useCurrentUser ).mockReturnValue( {} as UseQueryResult< User, Error > );
34
+
35
+ // Act
36
+ const { result } = renderHook( () => useUserRestrictions() );
37
+
38
+ // Assert
39
+ expect( result.current.restrictions ).toBeUndefined();
40
+ expect( result.current.isRestricted( DESIGN_RESTRICTION ) ).toBe( false );
41
+ } );
42
+ } );
43
+
44
+ describe( 'useHasContentOnlyAccess', () => {
45
+ it( 'should report content-only access when the design restriction is present', () => {
46
+ // Arrange
47
+ mockRestrictions( [ DESIGN_RESTRICTION ] );
48
+
49
+ // Act
50
+ const { result } = renderHook( () => useHasContentOnlyAccess() );
51
+
52
+ // Assert
53
+ expect( result.current ).toBe( true );
54
+ } );
55
+
56
+ it( 'should not report content-only access for unrelated restrictions', () => {
57
+ // Arrange
58
+ mockRestrictions( [ 'json-upload' ] );
59
+
60
+ // Act
61
+ const { result } = renderHook( () => useHasContentOnlyAccess() );
62
+
63
+ // Assert
64
+ expect( result.current ).toBe( false );
65
+ } );
66
+
67
+ it( 'should not report content-only access while the user data is unavailable', () => {
68
+ // Arrange
69
+ jest.mocked( useCurrentUser ).mockReturnValue( {} as UseQueryResult< User, Error > );
70
+
71
+ // Act
72
+ const { result } = renderHook( () => useHasContentOnlyAccess() );
73
+
74
+ // Assert
75
+ expect( result.current ).toBe( false );
76
+ } );
77
+ } );
package/src/api.ts CHANGED
@@ -11,6 +11,7 @@ type GetUserPayload = {
11
11
  export type UserModel = {
12
12
  suppressedMessages: string[];
13
13
  capabilities: string[];
14
+ restrictions: string[];
14
15
  };
15
16
 
16
17
  const getUserPayload: GetUserPayload = { params: { context: 'edit' } };
@@ -20,9 +21,9 @@ export const apiClient = {
20
21
  httpService()
21
22
  .get< UserModel >( RESOURCE_URL, getUserPayload )
22
23
  .then( ( res ) => {
23
- const { capabilities = [], suppressedMessages = [] } = res.data;
24
+ const { capabilities = [], suppressedMessages = [], restrictions = [] } = res.data;
24
25
 
25
- return { capabilities, suppressedMessages };
26
+ return { capabilities, suppressedMessages, restrictions };
26
27
  } ),
27
28
  update: ( data: Partial< User > ) =>
28
29
  httpService().patch< Partial< UserModel > >( RESOURCE_URL, {
package/src/index.ts CHANGED
@@ -5,3 +5,5 @@ export { ensureUser } from './ensure-current-user';
5
5
  export { onSetUser } from './on-set-user';
6
6
  export { useCurrentUser } from './use-current-user';
7
7
  export { useUpdateCurrentUser } from './use-update-current-user';
8
+ export { DESIGN_RESTRICTION, useUserRestrictions } from './use-user-restrictions';
9
+ export { useHasContentOnlyAccess } from './use-has-content-only-access';
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type User = {
2
2
  suppressedMessages: string[];
3
3
  capabilities: string[];
4
+ restrictions: string[];
4
5
  };
@@ -0,0 +1,3 @@
1
+ import { DESIGN_RESTRICTION, useUserRestrictions } from './use-user-restrictions';
2
+
3
+ export const useHasContentOnlyAccess = () => useUserRestrictions().isRestricted( DESIGN_RESTRICTION );
@@ -0,0 +1,14 @@
1
+ import { useCurrentUser } from './use-current-user';
2
+
3
+ export const DESIGN_RESTRICTION = 'design';
4
+
5
+ export const useUserRestrictions = () => {
6
+ const { data } = useCurrentUser();
7
+
8
+ const isRestricted = ( restriction: string ) => Boolean( data?.restrictions?.includes( restriction ) );
9
+
10
+ return {
11
+ isRestricted,
12
+ restrictions: data?.restrictions,
13
+ };
14
+ };