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

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/cli.mjs CHANGED
@@ -21441,20 +21441,21 @@ class Strapi {
21441
21441
  return data;
21442
21442
  }
21443
21443
  async can(uid, controller, action) {
21444
- if (!this.permissions) {
21445
- const response = await this.fetchData('users-permissions/permissions');
21446
- this.permissions = response.permissions;
21444
+ if (!this.permissionsList) {
21445
+ const { role } = await this.me();
21446
+ const response = await this.fetchData(`users-permissions/role/${role?.documentId}`);
21447
+ this.permissionsList = response.role.permissions;
21447
21448
  }
21448
- if (!this.permissions[uid]) {
21449
+ if (!this.permissionsList[uid]) {
21449
21450
  throw new Error(`Permissions for ${uid} not found!`);
21450
21451
  }
21451
- if (!this.permissions[uid].controllers[controller]) {
21452
+ if (!this.permissionsList[uid].controllers[controller]) {
21452
21453
  throw new Error(`Permissions for ${uid}.${controller} not found!`);
21453
21454
  }
21454
- if (!this.permissions[uid].controllers[controller][action]) {
21455
+ if (!this.permissionsList[uid].controllers[controller][action]) {
21455
21456
  throw new Error(`Permission for ${uid}.${controller}.${action} not found!`);
21456
21457
  }
21457
- return this.permissions[uid].controllers[controller][action].enabled;
21458
+ return this.permissionsList[uid].controllers[controller][action].enabled;
21458
21459
  }
21459
21460
  }
21460
21461
 
@@ -21952,7 +21953,7 @@ function generateMethodsCode(contentType) {
21952
21953
  if (contentType.uid.startsWith('api::')) {
21953
21954
  methods.push([
21954
21955
  ` public async can${getContentTypeName(contentType.schema.singularName)}(action: PermissionAction) {`,
21955
- ` return await this.can('${contentType.uid}', '${contentType.schema.singularName.replace(/^api::/, '')}', action);`,
21956
+ ` return await this.can('${contentType.uid.split('.')[0]}', '${contentType.schema.singularName}', action);`,
21956
21957
  ' }',
21957
21958
  ].join('\n'));
21958
21959
  }