@malevich-studio/strapi-sdk-typescript 1.2.15 → 1.2.17

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,7 @@ type RelationInput = {
13
13
  set?: RelationData[];
14
14
  } | RelationData[];
15
15
 
16
+ type PermissionAction = 'find' | 'findOne' | 'create' | 'update' | 'delete';
16
17
  type SuccessResponse<T> = {
17
18
  data: T;
18
19
  meta: {
@@ -41,6 +42,9 @@ type ErrorResponse = {
41
42
  };
42
43
  };
43
44
  type Response<T> = SuccessResponse<T> | ErrorResponse;
45
+ type UserResponse<T> = (T & {
46
+ error: undefined;
47
+ }) | ErrorResponse;
44
48
  type AuthResponse<T> = {
45
49
  jwt: string;
46
50
  user: T;
@@ -165,7 +169,7 @@ declare class Strapi {
165
169
  }>;
166
170
  protected baseResetPassword<T>(password: string, code: string): Promise<AuthResponse<T>>;
167
171
  protected baseChangePassword<T>(password: string, currentPassword: string): Promise<AuthResponse<T>>;
168
- protected baseMe<T, Q>(data: Q): Promise<T>;
172
+ protected baseMe<T, Q>(data: Q): Promise<UserResponse<T>>;
169
173
  getLocales(params: RequestInit): Promise<Locale[]>;
170
174
  getDocuments<T, Q extends object>(endpoint: string, data?: Q, params?: RequestInit): Promise<Response<T[]>>;
171
175
  getDocument<T, Q extends object>(endpoint: string, data?: Q, params?: RequestInit): Promise<Response<T>>;
@@ -174,6 +178,8 @@ declare class Strapi {
174
178
  delete<T>(endpoint: string, id: string, params?: RequestInit): Promise<Response<T>>;
175
179
  uploadForm(form: FormData): Promise<File[]>;
176
180
  private baseFetch;
181
+ private permissions?;
182
+ can(uid: string, controller: string, action: string): Promise<boolean>;
177
183
  }
178
184
 
179
- export { type AuthResponse, type DynamiczoneComponent, type DynamiczonePopulate, type ErrorResponse, type File, type FilterValue, type Filters, type Folder, type Locale, type Query, type RelationInput, type Response, Strapi, type SuccessResponse };
185
+ 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 };
package/dist/index.mjs CHANGED
@@ -21434,6 +21434,22 @@ class Strapi {
21434
21434
  log(data);
21435
21435
  return data;
21436
21436
  }
21437
+ async can(uid, controller, action) {
21438
+ if (!this.permissions) {
21439
+ const response = await this.fetchData('users-permissions/permissions');
21440
+ this.permissions = response.permissions;
21441
+ }
21442
+ if (!this.permissions[uid]) {
21443
+ throw new Error(`Permissions for ${uid} not found!`);
21444
+ }
21445
+ if (!this.permissions[uid].controllers[controller]) {
21446
+ throw new Error(`Permissions for ${uid}.${controller} not found!`);
21447
+ }
21448
+ if (!this.permissions[uid].controllers[controller][action]) {
21449
+ throw new Error(`Permission for ${uid}.${controller}.${action} not found!`);
21450
+ }
21451
+ return this.permissions[uid].controllers[controller][action].enabled;
21452
+ }
21437
21453
  }
21438
21454
 
21439
21455
  export { Strapi };