@malevich-studio/strapi-sdk-typescript 1.2.20 → 1.2.21

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
@@ -13,6 +13,18 @@ type RelationInput = {
13
13
  set?: RelationData[];
14
14
  } | RelationData[];
15
15
 
16
+ type Permissions = {
17
+ [key: string]: {
18
+ controllers: {
19
+ [key: string]: {
20
+ [key: string]: {
21
+ enabled: boolean;
22
+ policy: string;
23
+ };
24
+ };
25
+ };
26
+ };
27
+ };
16
28
  type PermissionAction = 'find' | 'findOne' | 'create' | 'update' | 'delete';
17
29
  type SuccessResponse<T> = {
18
30
  data: T;
@@ -148,12 +160,12 @@ type DynamiczonePopulate<T> = {
148
160
  [K in keyof T]: T[K];
149
161
  };
150
162
  };
151
- declare abstract class Strapi {
163
+ declare class Strapi {
152
164
  private readonly url;
153
165
  private token?;
154
166
  constructor(url: string, token?: string | undefined);
155
167
  fetch<T>(endpoint: string, data?: object | FormData, params?: RequestInit): Promise<Response<T>>;
156
- private fetchData;
168
+ fetchData<T>(endpoint: string, data?: object | FormData, params?: RequestInit): Promise<T>;
157
169
  setToken(token: string): void;
158
170
  getToken(): string | undefined;
159
171
  protected baseLogin<T>(identifier: string, password: string): Promise<AuthResponse<T>>;
@@ -179,14 +191,7 @@ declare abstract class Strapi {
179
191
  uploadForm(form: FormData): Promise<File[]>;
180
192
  private baseFetch;
181
193
  private permissionsList?;
182
- abstract me(data: Query<'id' | 'documentId', 'id' | 'documentId', {}, {
183
- role: Query<'id' | 'documentId', 'id' | 'documentId', {}, {}>;
184
- }>): Promise<{
185
- role?: {
186
- id?: number;
187
- };
188
- }>;
189
- can(uid: string, controller: string, action: PermissionAction): Promise<boolean>;
194
+ can(uid: string, controller: string, action: string): Promise<boolean>;
190
195
  }
191
196
 
192
- export { type AuthResponse, type DynamiczoneComponent, type DynamiczonePopulate, type ErrorResponse, type File, type FilterValue, type Filters, type Folder, type Locale, type PermissionAction, type Query, type RelationInput, type Response, Strapi, type SuccessResponse, type UserResponse };
197
+ export { type AuthResponse, type DynamiczoneComponent, type DynamiczonePopulate, type ErrorResponse, type File, type FilterValue, type Filters, type Folder, type Locale, type PermissionAction, type Permissions, type Query, type RelationInput, type Response, Strapi, type SuccessResponse, type UserResponse };
package/dist/index.mjs CHANGED
@@ -21436,8 +21436,11 @@ class Strapi {
21436
21436
  }
21437
21437
  async can(uid, controller, action) {
21438
21438
  if (!this.permissionsList) {
21439
- const { role } = await this.me({ populate: { role: { fields: ["id"] } } });
21440
- const response = await this.fetchData(`users-permissions/roles/${role?.id}`);
21439
+ const user = await this.baseMe({ populate: { role: { fields: ["id"] } } });
21440
+ if (user.error) {
21441
+ return false;
21442
+ }
21443
+ const response = await this.fetchData(`users-permissions/roles/${user.role.id}`);
21441
21444
  this.permissionsList = response.role.permissions;
21442
21445
  }
21443
21446
  if (!this.permissionsList[uid]) {