@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.cjs CHANGED
@@ -21461,20 +21461,21 @@ class Strapi {
21461
21461
  return data;
21462
21462
  }
21463
21463
  async can(uid, controller, action) {
21464
- if (!this.permissions) {
21465
- const response = await this.fetchData('users-permissions/permissions');
21466
- this.permissions = response.permissions;
21464
+ if (!this.permissionsList) {
21465
+ const { role } = await this.me();
21466
+ const response = await this.fetchData(`users-permissions/role/${role?.documentId}`);
21467
+ this.permissionsList = response.role.permissions;
21467
21468
  }
21468
- if (!this.permissions[uid]) {
21469
+ if (!this.permissionsList[uid]) {
21469
21470
  throw new Error(`Permissions for ${uid} not found!`);
21470
21471
  }
21471
- if (!this.permissions[uid].controllers[controller]) {
21472
+ if (!this.permissionsList[uid].controllers[controller]) {
21472
21473
  throw new Error(`Permissions for ${uid}.${controller} not found!`);
21473
21474
  }
21474
- if (!this.permissions[uid].controllers[controller][action]) {
21475
+ if (!this.permissionsList[uid].controllers[controller][action]) {
21475
21476
  throw new Error(`Permission for ${uid}.${controller}.${action} not found!`);
21476
21477
  }
21477
- return this.permissions[uid].controllers[controller][action].enabled;
21478
+ return this.permissionsList[uid].controllers[controller][action].enabled;
21478
21479
  }
21479
21480
  }
21480
21481
 
@@ -21972,7 +21973,7 @@ function generateMethodsCode(contentType) {
21972
21973
  if (contentType.uid.startsWith('api::')) {
21973
21974
  methods.push([
21974
21975
  ` public async can${getContentTypeName(contentType.schema.singularName)}(action: PermissionAction) {`,
21975
- ` return await this.can('${contentType.uid}', '${contentType.schema.singularName.replace(/^api::/, '')}', action);`,
21976
+ ` return await this.can('${contentType.uid.split('.')[0]}', '${contentType.schema.singularName}', action);`,
21976
21977
  ' }',
21977
21978
  ].join('\n'));
21978
21979
  }